From 08231e5ce0d31ca446de932e3144675a1a99b6e5 Mon Sep 17 00:00:00 2001 From: Andrii Kosachenko Date: Thu, 23 Mar 2023 19:34:39 +0200 Subject: [PATCH] Issue #109: add new input `instance_launch_options` 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 --- CHANGELOG.adoc | 1 + CONTRIBUTORS.adoc | 1 + docs/terraformoptions.adoc | 14 +++++++++++ main.tf | 17 ++++++++++++- variables.tf | 50 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 1 deletion(-) 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 = <