diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 433f922..7cc7df2 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -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 diff --git a/CONTRIBUTORS.adoc b/CONTRIBUTORS.adoc index 9b33e74..d77d993 100644 --- a/CONTRIBUTORS.adoc +++ b/CONTRIBUTORS.adoc @@ -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] diff --git a/docs/terraformoptions.adoc b/docs/terraformoptions.adoc index 1ec2ae7..2fc035c 100644 --- a/docs/terraformoptions.adoc +++ b/docs/terraformoptions.adoc @@ -156,6 +156,20 @@ |`null` |no +|[[input_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]] <> |(Updatable) The target state for the instance. Could be set to RUNNING or STOPPED. |`string` diff --git a/main.tf b/main.tf index cd5d27a..314b62d 100644 --- a/main.tf +++ b/main.tf @@ -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 } @@ -204,4 +219,4 @@ resource "oci_core_public_ip" "public_ip" { freeform_tags = local.merged_freeform_tags defined_tags = var.defined_tags -} \ No newline at end of file +} diff --git a/variables.tf b/variables.tf index 0bab5cf..e25edb1 100644 --- a/variables.tf +++ b/variables.tf @@ -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 = <