From d959936f446b2e8dee9f0c2f05a349755bc37373 Mon Sep 17 00:00:00 2001 From: Ryan Boehning <1250684+ryboe@users.noreply.github.com> Date: Fri, 29 Sep 2023 11:57:37 -0700 Subject: [PATCH] feat: add var.resource_policies to instance_template (#317) Co-authored-by: Awais Malik --- modules/compute_disk_snapshot/metadata.yaml | 2 +- modules/compute_instance/metadata.yaml | 6 ++++- modules/instance_template/README.md | 1 + modules/instance_template/main.tf | 1 + modules/instance_template/metadata.yaml | 27 +++++++++++++------ modules/instance_template/variables.tf | 6 +++++ modules/mig/metadata.yaml | 2 +- modules/mig_with_percent/metadata.yaml | 2 +- .../metadata.yaml | 2 +- modules/umig/metadata.yaml | 2 +- 10 files changed, 37 insertions(+), 14 deletions(-) diff --git a/modules/compute_disk_snapshot/metadata.yaml b/modules/compute_disk_snapshot/metadata.yaml index b2c1cc7e..ee23a492 100644 --- a/modules/compute_disk_snapshot/metadata.yaml +++ b/modules/compute_disk_snapshot/metadata.yaml @@ -25,7 +25,7 @@ spec: repo: https://github.com/terraform-google-modules/terraform-google-vm sourceType: git dir: /modules/compute_disk_snapshot - version: 9.0.0 + version: 10.0.0 actuationTool: flavor: Terraform version: ">=0.13.0" diff --git a/modules/compute_instance/metadata.yaml b/modules/compute_instance/metadata.yaml index 7f14a5f0..db751c45 100644 --- a/modules/compute_instance/metadata.yaml +++ b/modules/compute_instance/metadata.yaml @@ -25,7 +25,7 @@ spec: repo: https://github.com/terraform-google-modules/terraform-google-vm sourceType: git dir: /modules/compute_instance - version: 9.0.0 + version: 10.0.0 actuationTool: flavor: Terraform version: ">=0.13.0" @@ -134,6 +134,10 @@ spec: description: Region where the instances should be created. varType: string defaultValue: null + - name: resource_manager_tags + description: (Optional) A tag is a key-value pair that can be attached to a Google Cloud resource. You can use tags to conditionally allow or deny policies based on whether a resource has a specific tag. This value is not returned by the API. In Terraform, this value cannot be updated and changing it will recreate the resource. + varType: map(string) + defaultValue: null - name: resource_policies description: (Optional) A list of short names or 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) diff --git a/modules/instance_template/README.md b/modules/instance_template/README.md index 13647251..e881f74e 100644 --- a/modules/instance_template/README.md +++ b/modules/instance_template/README.md @@ -41,6 +41,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({
email = string
scopes = set(string)
})
| n/a | yes | | shielded\_instance\_config | Not used unless enable\_shielded\_vm is true. Shielded VM configuration for the instance. |
object({
enable_secure_boot = bool
enable_vtpm = bool
enable_integrity_monitoring = bool
})
|
{
"enable_integrity_monitoring": true,
"enable_secure_boot": true,
"enable_vtpm": true
}
| 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 e05a8df6..af4d0d95 100644 --- a/modules/instance_template/main.tf +++ b/modules/instance_template/main.tf @@ -73,6 +73,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/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/instance_template/variables.tf b/modules/instance_template/variables.tf index a80ad371..1807d0cd 100644 --- a/modules/instance_template/variables.tf +++ b/modules/instance_template/variables.tf @@ -109,6 +109,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/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"