From b1a2a3889ec5b94152d85a4bb00ca5f5a90d9be3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87etin=20ARDAL?= Date: Sun, 24 Oct 2021 17:48:05 +0200 Subject: [PATCH] feat: add support for instance_state (RUNNING or STOPPED) --- docs/terraformoptions.adoc | 6 ++++++ examples/instances_fixed_shape/main.tf | 4 +++- .../instances_fixed_shape/terraform.tfvars.example | 1 + examples/instances_fixed_shape/variables.tf | 11 +++++++++++ examples/instances_flex_shape/main.tf | 2 ++ .../instances_flex_shape/terraform.tfvars.example | 1 + examples/instances_flex_shape/variables.tf | 11 +++++++++++ examples/instances_reserved_public_ip/main.tf | 1 + .../terraform.tfvars.example | 1 + examples/instances_reserved_public_ip/variables.tf | 11 +++++++++++ main.tf | 1 + variables.tf | 11 +++++++++++ 12 files changed, 60 insertions(+), 1 deletion(-) diff --git a/docs/terraformoptions.adoc b/docs/terraformoptions.adoc index badca2a..2abb6f6 100644 --- a/docs/terraformoptions.adoc +++ b/docs/terraformoptions.adoc @@ -128,6 +128,12 @@ |`null` |no +|[[input_instance_state]] <> +|(Updatable) The target state for the instance. Could be set to RUNNING or STOPPED. +|`string` +|`"RUNNING"` +|no + |[[input_instance_timeout]] <> |Timeout setting for creating instance. |`string` diff --git a/examples/instances_fixed_shape/main.tf b/examples/instances_fixed_shape/main.tf index 52d4eb5..26fef93 100644 --- a/examples/instances_fixed_shape/main.tf +++ b/examples/instances_fixed_shape/main.tf @@ -28,6 +28,7 @@ module "instance_nonflex" { ad_number = var.instance_ad_number instance_count = var.instance_count instance_display_name = var.instance_display_name + instance_state = var.instance_state shape = var.shape source_ocid = var.source_ocid source_type = var.source_type @@ -57,7 +58,8 @@ module "instance_nonflex_custom" { # compute instance parameters ad_number = var.instance_ad_number instance_count = var.instance_count - instance_display_name = "instance_nonflex_custom" + instance_display_name = "module_instance_nonflex_custom" + instance_state = var.instance_state shape = var.shape source_ocid = var.source_ocid source_type = var.source_type diff --git a/examples/instances_fixed_shape/terraform.tfvars.example b/examples/instances_fixed_shape/terraform.tfvars.example index 584f070..cbf7c56 100644 --- a/examples/instances_fixed_shape/terraform.tfvars.example +++ b/examples/instances_fixed_shape/terraform.tfvars.example @@ -24,6 +24,7 @@ compartment_ocid = "" # compute instance parameters source_ocid = "" +instance_state = "RUNNING" # operating system parameters diff --git a/examples/instances_fixed_shape/variables.tf b/examples/instances_fixed_shape/variables.tf index 9ace2dd..4422200 100644 --- a/examples/instances_fixed_shape/variables.tf +++ b/examples/instances_fixed_shape/variables.tf @@ -85,6 +85,17 @@ variable "instance_flex_ocpus" { default = null } +variable "instance_state" { + type = string + description = "(Updatable) The target state for the instance. Could be set to RUNNING or STOPPED." + default = "RUNNING" + + validation { + condition = contains(["RUNNING", "STOPPED"], var.instance_state) + error_message = "Accepted values are RUNNING or STOPPED." + } +} + variable "shape" { description = "The shape of an instance." type = string diff --git a/examples/instances_flex_shape/main.tf b/examples/instances_flex_shape/main.tf index f7b2f31..0e80a37 100644 --- a/examples/instances_flex_shape/main.tf +++ b/examples/instances_flex_shape/main.tf @@ -29,6 +29,7 @@ module "instance_flex" { ad_number = var.instance_ad_number instance_count = var.instance_count instance_display_name = var.instance_display_name + instance_state = var.instance_state shape = var.shape source_ocid = var.source_ocid source_type = var.source_type @@ -60,6 +61,7 @@ output "instance_flex" { # ad_number = null # instance_count = 4 # instance_display_name = "instance_flex_custom" +# instance_state = var.instance_state # shape = var.shape # source_ocid = var.source_ocid # source_type = var.source_type diff --git a/examples/instances_flex_shape/terraform.tfvars.example b/examples/instances_flex_shape/terraform.tfvars.example index 584f070..cbf7c56 100644 --- a/examples/instances_flex_shape/terraform.tfvars.example +++ b/examples/instances_flex_shape/terraform.tfvars.example @@ -24,6 +24,7 @@ compartment_ocid = "" # compute instance parameters source_ocid = "" +instance_state = "RUNNING" # operating system parameters diff --git a/examples/instances_flex_shape/variables.tf b/examples/instances_flex_shape/variables.tf index 079b999..f8604bb 100644 --- a/examples/instances_flex_shape/variables.tf +++ b/examples/instances_flex_shape/variables.tf @@ -85,6 +85,17 @@ variable "instance_flex_ocpus" { default = null } +variable "instance_state" { + type = string + description = "(Updatable) The target state for the instance. Could be set to RUNNING or STOPPED." + default = "RUNNING" + + validation { + condition = contains(["RUNNING", "STOPPED"], var.instance_state) + error_message = "Accepted values are RUNNING or STOPPED." + } +} + variable "shape" { description = "The shape of an instance." type = string diff --git a/examples/instances_reserved_public_ip/main.tf b/examples/instances_reserved_public_ip/main.tf index ef4c0f2..9d59529 100644 --- a/examples/instances_reserved_public_ip/main.tf +++ b/examples/instances_reserved_public_ip/main.tf @@ -28,6 +28,7 @@ module "instance_reserved_ip" { ad_number = null instance_count = 1 instance_display_name = "instance_reserved_ip" + instance_state = var.instance_state shape = var.shape source_ocid = var.source_ocid source_type = var.source_type diff --git a/examples/instances_reserved_public_ip/terraform.tfvars.example b/examples/instances_reserved_public_ip/terraform.tfvars.example index e66c988..c941e95 100644 --- a/examples/instances_reserved_public_ip/terraform.tfvars.example +++ b/examples/instances_reserved_public_ip/terraform.tfvars.example @@ -24,6 +24,7 @@ compartment_ocid = "" # compute instance parameters source_ocid = "" +instance_state = "RUNNING" # operating system parameters diff --git a/examples/instances_reserved_public_ip/variables.tf b/examples/instances_reserved_public_ip/variables.tf index a38ab25..5abfaa8 100644 --- a/examples/instances_reserved_public_ip/variables.tf +++ b/examples/instances_reserved_public_ip/variables.tf @@ -85,6 +85,17 @@ variable "instance_flex_ocpus" { default = null } +variable "instance_state" { + type = string + description = "(Updatable) The target state for the instance. Could be set to RUNNING or STOPPED." + default = "RUNNING" + + validation { + condition = contains(["RUNNING", "STOPPED"], var.instance_state) + error_message = "Accepted values are RUNNING or STOPPED." + } +} + variable "shape" { description = "The shape of an instance." type = string diff --git a/main.tf b/main.tf index f43d5c3..4f5eea5 100644 --- a/main.tf +++ b/main.tf @@ -73,6 +73,7 @@ resource "oci_core_instance" "instance" { extended_metadata = var.extended_metadata ipxe_script = var.ipxe_script preserve_boot_volume = var.preserve_boot_volume + state = var.instance_state shape = var.shape shape_config { // If shape name contains ".Flex" and instance_flex inputs are not null, use instance_flex inputs values for shape_config block diff --git a/variables.tf b/variables.tf index f19785b..1379fd2 100644 --- a/variables.tf +++ b/variables.tf @@ -74,6 +74,17 @@ variable "instance_flex_ocpus" { default = null } +variable "instance_state" { + type = string + description = "(Updatable) The target state for the instance. Could be set to RUNNING or STOPPED." + default = "RUNNING" + + validation { + condition = contains(["RUNNING", "STOPPED"], var.instance_state) + error_message = "Accepted values are RUNNING or STOPPED." + } +} + variable "shape" { description = "The shape of an instance." type = string