Skip to content

Commit

Permalink
Issue oracle-terraform-modules#109: add new input `instance_launch_op…
Browse files Browse the repository at this point in the history
…tions`

oci_core_instance resource supports optional inputs from "launch_options"
block. In some use cases where instances are launched from a customized images
it is required to tune some of the launch options so that instances could boot
properly. The current implementation of the compute instance module has
lacked it. Hence the `instance_launch_options` input was added to fill
the gap in the implementation.

Signed-off-by: Andrii Kosachenko <[email protected]>
  • Loading branch information
silent-at-gh committed Mar 23, 2023
1 parent b19dbe0 commit 08231e5
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Given a version number MAJOR.MINOR.PATCH:

* Add support for burstable instances (fix #66)
* Add support for Oracle Cloud Agent pulgins configuration (fix #17)
* Add support for instance options from `launch_options` block (Issue #109)

=== Fixes

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ _Code Contributors have a least one merged PR in the code base of the project_
- https://github.com/yimw[@yimw]
- https://github.com/alexng-canuck[@alexng-canuck]
- https://github.com/aorcl[@aorcl]
- https://github.com/silent-at-gh[@silent-at-gh]
14 changes: 14 additions & 0 deletions docs/terraformoptions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@
|`null`
|no

|[[input_instance_launch_options]] <<input_instance_launch_options,instance_launch_options>>
|Options for tuning the compatibility and performance of VM shapes.
Valid option names and their values are:

* __boot_volume_type__ - `ISCSI`, `SCSI`, `IDE`, `VFIO` or `PARAVIRTUALIZED`
* __network_type__ - `E1000`, `VFIO` or `PARAVIRTUALIZED`
* __firmware__ - `BIOS` or `UEFI_64`
* __remote_data_volume_type__ - `ISCSI`, `SCSI`, `IDE`, `VFIO` or `PARAVIRTUALIZED`
* __is_consistent_volume_naming_enabled__ - `true` or `false`
* __is_pv_encryption_in_transit_enabled__ - `true` of `false`
|`map(any)`
|`{}`
|no

|[[input_instance_state]] <<input_instance_state,instance_state>>
|(Updatable) The target state for the instance. Could be set to RUNNING or STOPPED.
|`string`
Expand Down
17 changes: 16 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,24 @@ resource "oci_core_instance" "instance" {
source_type = var.source_type
}


dynamic "launch_options" {
// This one is optional or user may specify zero (or more) options
for_each = length(keys(var.instance_launch_options)) > 0 ? [var.instance_launch_options] : []
content {
boot_volume_type = try(launch_options.value.boot_volume_type, null)
firmware = try(launch_options.value.firmware, null)
is_consistent_volume_naming_enabled = try(launch_options.value.is_consistent_volume_naming_enabled, null)
is_pv_encryption_in_transit_enabled = try(launch_options.value.is_pv_encryption_in_transit_enabled, null)
network_type = try(launch_options.value.network_type, null)
remote_data_volume_type = try(launch_options.value.remote_data_volume_type, null)
}
}

freeform_tags = local.merged_freeform_tags
defined_tags = var.defined_tags


timeouts {
create = var.instance_timeout
}
Expand Down Expand Up @@ -204,4 +219,4 @@ resource "oci_core_public_ip" "public_ip" {

freeform_tags = local.merged_freeform_tags
defined_tags = var.defined_tags
}
}
50 changes: 50 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,56 @@ variable "instance_state" {
}
}

variable "instance_launch_options" {
type = map(any)
description = "Options for tuning the compatibility and performance of VM shapes"
default = {}

validation {
condition = ( length(keys(var.instance_launch_options)) == 0
? true
: alltrue(flatten([
# check that provided options names are known
length(setintersection([
"boot_volume_type",
"network_type",
"firmware",
"remote_data_volume_type",
"is_consistent_volume_naming_enabled",
"is_pv_encryption_in_transit_enabled" ], keys(var.instance_launch_options))
) == length(keys(var.instance_launch_options)),
[
# match every option agains allowed values range (avr)
for k, avr in {
"boot_volume_type" : ["ISCSI", "SCSI", "IDE", "VFIO", "PARAVIRTUALIZED"],
"network_type" : ["E1000", "VFIO", "PARAVIRTUALIZED"],
"firmware" : ["BIOS", "UEFI_64"],
"remote_data_volume_type" : ["ISCSI", "SCSI", "IDE", "VFIO", "PARAVIRTUALIZED"]
}: contains(avr, lookup(var.instance_launch_options, k, false)) if contains(keys(var.instance_launch_options), k)
],
[
# verify that given option values are boolean
for k in [
"is_consistent_volume_naming_enabled",
"is_pv_encryption_in_transit_enabled"
]: contains([true, false], try(tobool(lookup(var.instance_launch_options, k, null)), "") ) if contains(keys(var.instance_launch_options), k)
]
] ) ) )
error_message = <<EOEM
Accepted option names and their values are:
* boot_volume_type - ISCSI, SCSI, IDE, VFIO or PARAVIRTUALIZED
* firmware - BIOS or UEFI_64
* is_consistent_volume_naming_enabled - true or false
* is_pv_encryption_in_transit_enabled - true of false
* network_type - E1000, VFIO or PARAVIRTUALIZED
* remote_data_volume_type - ISCSI, SCSI, IDE, VFIO or PARAVIRTUALIZED
More details:
https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_instance#launch_options
EOEM
}
}

variable "shape" {
description = "The shape of an instance."
type = string
Expand Down

0 comments on commit 08231e5

Please sign in to comment.