From 4f8dc51a76bea427de1e15b79bf2fd206f8e866e Mon Sep 17 00:00:00 2001 From: Rauny Date: Mon, 24 Jun 2024 12:31:05 +0200 Subject: [PATCH 1/2] feat: add disk resource policies --- modules/instance_template/main.tf | 40 ++++++++++++++------------ modules/instance_template/variables.tf | 6 ++++ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/modules/instance_template/main.tf b/modules/instance_template/main.tf index 573a0e22..b8985425 100644 --- a/modules/instance_template/main.tf +++ b/modules/instance_template/main.tf @@ -25,12 +25,13 @@ locals { boot_disk = [ { - source_image = var.source_image != "" ? format("${local.source_image_project}/${local.source_image}") : format("${local.source_image_project}/${local.source_image_family}") - disk_size_gb = var.disk_size_gb - disk_type = var.disk_type - disk_labels = var.disk_labels - auto_delete = var.auto_delete - boot = "true" + source_image = var.source_image != "" ? format("${local.source_image_project}/${local.source_image}") : format("${local.source_image_project}/${local.source_image_family}") + disk_size_gb = var.disk_size_gb + disk_type = var.disk_type + disk_labels = var.disk_labels + auto_delete = var.auto_delete + boot = "true" + resource_policies = var.disk_resource_policies }, ] @@ -78,19 +79,20 @@ resource "google_compute_instance_template" "tpl" { dynamic "disk" { for_each = local.all_disks content { - auto_delete = lookup(disk.value, "auto_delete", null) - boot = lookup(disk.value, "boot", null) - device_name = lookup(disk.value, "device_name", null) - disk_name = lookup(disk.value, "disk_name", null) - disk_size_gb = lookup(disk.value, "disk_size_gb", lookup(disk.value, "disk_type", null) == "local-ssd" ? "375" : null) - disk_type = lookup(disk.value, "disk_type", null) - interface = lookup(disk.value, "interface", lookup(disk.value, "disk_type", null) == "local-ssd" ? "NVME" : null) - mode = lookup(disk.value, "mode", null) - source = lookup(disk.value, "source", null) - source_image = lookup(disk.value, "source_image", null) - source_snapshot = lookup(disk.value, "source_snapshot", null) - type = lookup(disk.value, "disk_type", null) == "local-ssd" ? "SCRATCH" : "PERSISTENT" - labels = lookup(disk.value, "disk_labels", null) + auto_delete = lookup(disk.value, "auto_delete", null) + boot = lookup(disk.value, "boot", null) + device_name = lookup(disk.value, "device_name", null) + disk_name = lookup(disk.value, "disk_name", null) + disk_size_gb = lookup(disk.value, "disk_size_gb", lookup(disk.value, "disk_type", null) == "local-ssd" ? "375" : null) + disk_type = lookup(disk.value, "disk_type", null) + interface = lookup(disk.value, "interface", lookup(disk.value, "disk_type", null) == "local-ssd" ? "NVME" : null) + mode = lookup(disk.value, "mode", null) + source = lookup(disk.value, "source", null) + source_image = lookup(disk.value, "source_image", null) + source_snapshot = lookup(disk.value, "source_snapshot", null) + type = lookup(disk.value, "disk_type", null) == "local-ssd" ? "SCRATCH" : "PERSISTENT" + labels = lookup(disk.value, "disk_labels", null) + resource_policies = lookup(disk.value, "resource_policies", []) dynamic "disk_encryption_key" { for_each = compact([var.disk_encryption_key == null ? null : 1]) diff --git a/modules/instance_template/variables.tf b/modules/instance_template/variables.tf index 2f92dc67..160935d7 100644 --- a/modules/instance_template/variables.tf +++ b/modules/instance_template/variables.tf @@ -195,6 +195,12 @@ variable "additional_disks" { default = [] } +variable "disk_resource_policies" { + description = "A list (short name or id) of resource policies to attach to this disk for automatic snapshot creations" + type = list(string) + default = [] +} + #################### # network_interface #################### From 3429c4c44b85098890460ed248c2cb11c7d68802 Mon Sep 17 00:00:00 2001 From: Rauny Date: Mon, 24 Jun 2024 13:01:32 +0200 Subject: [PATCH 2/2] feat: add disk resource policies --- modules/instance_template/README.md | 1 + modules/instance_template/metadata.yaml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/modules/instance_template/README.md b/modules/instance_template/README.md index 2cf3a49e..49ed81b9 100644 --- a/modules/instance_template/README.md +++ b/modules/instance_template/README.md @@ -22,6 +22,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example. | can\_ip\_forward | Enable IP forwarding, for NAT instances for example | `string` | `"false"` | no | | disk\_encryption\_key | The id of the encryption key that is stored in Google Cloud KMS to use to encrypt all the disks on this instance | `string` | `null` | no | | disk\_labels | Labels to be assigned to boot disk, provided as a map | `map(string)` | `{}` | no | +| disk\_resource\_policies | A list (short name or id) of resource policies to attach to this disk for automatic snapshot creations | `list(string)` | `[]` | no | | disk\_size\_gb | Boot disk size in GB | `string` | `"100"` | no | | disk\_type | Boot disk type, can be either pd-ssd, local-ssd, or pd-standard | `string` | `"pd-standard"` | no | | enable\_confidential\_vm | Whether to enable the Confidential VM configuration on the instance. Note that the instance image must support Confidential VMs. See https://cloud.google.com/compute/docs/images | `bool` | `false` | no | diff --git a/modules/instance_template/metadata.yaml b/modules/instance_template/metadata.yaml index 1dc83206..7879f694 100644 --- a/modules/instance_template/metadata.yaml +++ b/modules/instance_template/metadata.yaml @@ -153,6 +153,10 @@ spec: description: Labels to be assigned to boot disk, provided as a map varType: map(string) defaultValue: {} + - name: disk_resource_policies + description: A list (short name or id) of resource policies to attach to this disk for automatic snapshot creations + varType: list(string) + defaultValue: [] - name: disk_size_gb description: Boot disk size in GB varType: string