From 2bab564838c69a8edc9ae0c38901bea4d2393937 Mon Sep 17 00:00:00 2001 From: Ryan Boehning <1250684+ryboe@users.noreply.github.com> Date: Tue, 13 Jun 2023 18:20:36 -0700 Subject: [PATCH 1/2] feat: add var.resource_policies to instance_template Resolve #315 --- modules/instance_template/README.md | 1 + modules/instance_template/main.tf | 1 + modules/instance_template/variables.tf | 6 ++++++ modules/instance_template/versions.tf | 2 +- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/instance_template/README.md b/modules/instance_template/README.md index fbb6e0c9..85b97187 100644 --- a/modules/instance_template/README.md +++ b/modules/instance_template/README.md @@ -40,6 +40,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example. | preemptible | Allow the instance to be preempted | `bool` | `false` | no | | project\_id | The GCP project ID | `string` | `null` | no | | region | Region where the instance template should be created. | `string` | `null` | no | +| resource\_policies | A list of self_links of resource policies to attach to the instance. Modifying this list will cause the instance to recreate. Currently a max of 1 resource policy is supported. | `list(string)` | `[]` | no | | service\_account | Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template#service_account. |
object({| n/a | yes | | shielded\_instance\_config | Not used unless enable\_shielded\_vm is true. Shielded VM configuration for the instance. |
email = string
scopes = set(string)
})
object({|
enable_secure_boot = bool
enable_vtpm = bool
enable_integrity_monitoring = bool
})
{| no | | source\_image | Source disk image. If neither source\_image nor source\_image\_family is specified, defaults to the latest public CentOS image. | `string` | `""` | no | diff --git a/modules/instance_template/main.tf b/modules/instance_template/main.tf index bd4a846e..e277d610 100644 --- a/modules/instance_template/main.tf +++ b/modules/instance_template/main.tf @@ -69,6 +69,7 @@ resource "google_compute_instance_template" "tpl" { metadata_startup_script = var.startup_script region = var.region min_cpu_platform = var.min_cpu_platform + resource_policies = var.resource_policies dynamic "disk" { for_each = local.all_disks content { diff --git a/modules/instance_template/variables.tf b/modules/instance_template/variables.tf index c1072376..7bbf5e70 100644 --- a/modules/instance_template/variables.tf +++ b/modules/instance_template/variables.tf @@ -92,6 +92,12 @@ variable "threads_per_core" { default = null } +variable "resource_policies" { + type = list(string) + description = "A list of self_links of resource policies to attach to the instance. Modifying this list will cause the instance to recreate. Currently a max of 1 resource policy is supported." + default = [] +} + ####### # disk ####### diff --git a/modules/instance_template/versions.tf b/modules/instance_template/versions.tf index 16fa675e..4e2a06ab 100644 --- a/modules/instance_template/versions.tf +++ b/modules/instance_template/versions.tf @@ -17,7 +17,7 @@ terraform { required_version = ">=0.13.0" required_providers { - google = ">= 3.88, < 5.0" + google = ">= 4.53, < 5.0" } provider_meta "google" { module_name = "blueprints/terraform/terraform-google-vm:instance_template/v8.0.1" From 38c4375348744b9f8403451f580ca8b1993bb32a Mon Sep 17 00:00:00 2001 From: Awais Malik
"enable_integrity_monitoring": true,
"enable_secure_boot": true,
"enable_vtpm": true
}
object({| n/a | yes | | shielded\_instance\_config | Not used unless enable\_shielded\_vm is true. Shielded VM configuration for the instance. |
email = string
scopes = set(string)
})
object({|
enable_secure_boot = bool
enable_vtpm = bool
enable_integrity_monitoring = bool
})
{| no | | source\_image | Source disk image. If neither source\_image nor source\_image\_family is specified, defaults to the latest public CentOS image. | `string` | `""` | no | diff --git a/modules/instance_template/metadata.yaml b/modules/instance_template/metadata.yaml index 559e672f..cb995afc 100644 --- a/modules/instance_template/metadata.yaml +++ b/modules/instance_template/metadata.yaml @@ -25,7 +25,7 @@ spec: repo: https://github.com/terraform-google-modules/terraform-google-vm sourceType: git dir: /modules/instance_template - version: 9.0.0 + version: 10.0.0 actuationTool: flavor: Terraform version: ">=0.13.0" @@ -86,13 +86,14 @@ spec: description: List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template#disk_name varType: |- list(object({ - disk_name = string - device_name = string - auto_delete = bool - boot = bool - disk_size_gb = number - disk_type = string - disk_labels = map(string) + disk_name = string + device_name = string + auto_delete = bool + boot = bool + disk_size_gb = number + disk_type = string + disk_labels = map(string) + source_snapshot = optional(string) })) defaultValue: [] - name: additional_networks @@ -233,6 +234,10 @@ spec: description: Region where the instance template should be created. varType: string defaultValue: null + - name: resource_policies + description: A list of self_links of resource policies to attach to the instance. Modifying this list will cause the instance to recreate. Currently a max of 1 resource policy is supported. + varType: list(string) + defaultValue: [] - name: service_account description: Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template#service_account. varType: |- @@ -270,6 +275,10 @@ spec: description: Provision a SPOT instance varType: bool defaultValue: false + - name: spot_instance_termination_action + description: Action to take when Compute Engine preempts a Spot VM. + varType: string + defaultValue: STOP - name: stack_type description: The stack type for this network interface to identify whether the IPv6 feature is enabled or not. Values are `IPV4_IPV6` or `IPV4_ONLY`. Default behavior is equivalent to IPV4_ONLY. varType: string @@ -303,6 +312,8 @@ spec: description: Name of instance template - name: self_link description: Self-link of instance template + - name: self_link_unique + description: Unique self-link of instance template (recommended output to use instead of self_link) - name: tags description: Tags that will be associated with instance(s) requirements: diff --git a/modules/mig/metadata.yaml b/modules/mig/metadata.yaml index beac0725..bb14bfca 100644 --- a/modules/mig/metadata.yaml +++ b/modules/mig/metadata.yaml @@ -25,7 +25,7 @@ spec: repo: https://github.com/terraform-google-modules/terraform-google-vm sourceType: git dir: /modules/mig - version: 9.0.0 + version: 10.0.0 actuationTool: flavor: Terraform version: ">=0.13.0" diff --git a/modules/mig_with_percent/metadata.yaml b/modules/mig_with_percent/metadata.yaml index baa8a88e..b5a0b267 100644 --- a/modules/mig_with_percent/metadata.yaml +++ b/modules/mig_with_percent/metadata.yaml @@ -25,7 +25,7 @@ spec: repo: https://github.com/terraform-google-modules/terraform-google-vm sourceType: git dir: /modules/mig_with_percent - version: 9.0.0 + version: 10.0.0 actuationTool: flavor: Terraform version: ">=0.13.0" diff --git a/modules/preemptible_and_regular_instance_templates/metadata.yaml b/modules/preemptible_and_regular_instance_templates/metadata.yaml index 8e3a3033..395820a2 100644 --- a/modules/preemptible_and_regular_instance_templates/metadata.yaml +++ b/modules/preemptible_and_regular_instance_templates/metadata.yaml @@ -25,7 +25,7 @@ spec: repo: https://github.com/terraform-google-modules/terraform-google-vm sourceType: git dir: /modules/preemptible_and_regular_instance_templates - version: 9.0.0 + version: 10.0.0 actuationTool: flavor: Terraform version: ">=0.13.0" diff --git a/modules/umig/metadata.yaml b/modules/umig/metadata.yaml index 29942feb..9d227cc1 100644 --- a/modules/umig/metadata.yaml +++ b/modules/umig/metadata.yaml @@ -25,7 +25,7 @@ spec: repo: https://github.com/terraform-google-modules/terraform-google-vm sourceType: git dir: /modules/umig - version: 9.0.0 + version: 10.0.0 actuationTool: flavor: Terraform version: ">=0.13.0"
"enable_integrity_monitoring": true,
"enable_secure_boot": true,
"enable_vtpm": true
}