From 761399f0556a552737493fedfeb869ff4be00531 Mon Sep 17 00:00:00 2001 From: Suryansh Singhal Date: Mon, 16 Mar 2026 16:52:34 +0530 Subject: [PATCH] Allow compute-vm disks to have custom names (#3792) * module support custom name if provided instead of just {vm_name}-boot * updated readme.md --- modules/compute-vm/README.md | 70 ++++++++++++++++----------------- modules/compute-vm/main.tf | 2 +- modules/compute-vm/variables.tf | 1 + 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/modules/compute-vm/README.md b/modules/compute-vm/README.md index e9a47a84b..dfb69663a 100644 --- a/modules/compute-vm/README.md +++ b/modules/compute-vm/README.md @@ -1169,43 +1169,43 @@ module "sole-tenancy" { | name | description | type | required | default | |---|---|:---:|:---:|:---:| -| [name](variables.tf#L322) | Instance name. | string | ✓ | | -| [network_interfaces](variables.tf#L334) | Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed. | list(object({…})) | ✓ | | -| [project_id](variables.tf#L429) | Project id. | string | ✓ | | -| [zone](variables.tf#L549) | Compute zone. | string | ✓ | | +| [name](variables.tf#L323) | Instance name. | string | ✓ | | +| [network_interfaces](variables.tf#L335) | Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed. | list(object({…})) | ✓ | | +| [project_id](variables.tf#L430) | Project id. | string | ✓ | | +| [zone](variables.tf#L550) | Compute zone. | string | ✓ | | | [attached_disk_defaults](variables.tf#L17) | Defaults for attached disks options. | object({…}) | | {…} | | [attached_disks](variables.tf#L37) | Additional disks, if options is null defaults will be used in its place. Source type is one of 'image' (zonal disks in vms and template), 'snapshot' (vm), 'existing', and null. | list(object({…})) | | [] | -| [boot_disk](variables.tf#L92) | Boot disk properties. Initialize params are ignored when source is set. | object({…}) | | {…} | -| [can_ip_forward](variables.tf#L134) | Enable IP forwarding. | bool | | false | -| [confidential_compute](variables.tf#L140) | Enable Confidential Compute for these instances. | bool | | false | -| [context](variables.tf#L146) | Context-specific interpolations. | object({…}) | | {} | -| [create_template](variables.tf#L163) | Create instance template instead of instances. Defaults to a global template. | object({…}) | | null | -| [description](variables.tf#L172) | Description of a Compute Instance. | string | | "Managed by the compute-vm Terraform module." | -| [enable_display](variables.tf#L178) | Enable virtual display on the instances. | bool | | false | -| [encryption](variables.tf#L184) | Encryption options. Only one of kms_key_self_link and disk_encryption_key_raw may be set. If needed, you can specify to encrypt or not the boot disk. | object({…}) | | null | -| [gpu](variables.tf#L194) | GPU information. Based on https://cloud.google.com/compute/docs/gpus. | object({…}) | | null | -| [group](variables.tf#L229) | Define this variable to create an instance group for instances. Disabled for template use. | object({…}) | | null | -| [hostname](variables.tf#L237) | Instance FQDN name. | string | | null | -| [iam](variables.tf#L243) | IAM bindings in {ROLE => [MEMBERS]} format. | map(list(string)) | | {} | -| [instance_schedule](variables.tf#L249) | Assign or create and assign an instance schedule policy. Either resource policy id or create_config must be specified if not null. Set active to null to dtach a policy from vm before destroying. | object({…}) | | null | -| [instance_type](variables.tf#L273) | Instance type. | string | | "f1-micro" | -| [kms_autokeys](variables.tf#L279) | KMS Autokey key handles. If location is not specified it will be inferred from the zone. Key handle names will be added to the kms_keys context with an `autokeys/` prefix. | map(object({…})) | | {} | -| [labels](variables.tf#L297) | Instance labels. | map(string) | | {} | -| [metadata](variables.tf#L303) | Instance metadata. | map(string) | | {} | -| [metadata_startup_script](variables.tf#L309) | Instance startup script. Will trigger recreation on change, even after importing. | string | | null | -| [min_cpu_platform](variables.tf#L316) | Minimum CPU platform. | string | | null | -| [network_attached_interfaces](variables.tf#L327) | Network interfaces using network attachments. | list(string) | | [] | -| [network_tag_bindings](variables.tf#L355) | Resource manager tag bindings in arbitrary key => tag key or value id format. Set on both the instance only for networking purposes, and modifiable without impacting the main resource lifecycle. | map(string) | | {} | -| [options](variables.tf#L362) | Instance options. | object({…}) | | {…} | -| [project_number](variables.tf#L434) | Project number. Used in tag bindings to avoid a permadiff. | string | | null | -| [resource_policies](variables.tf#L440) | Resource policies to attach to the instance or template. | list(string) | | null | -| [scratch_disks](variables.tf#L447) | Scratch disks configuration. | object({…}) | | {…} | -| [service_account](variables.tf#L459) | Service account email and scopes. If email is null, the default Compute service account will be used unless auto_create is true, in which case a service account will be created. Set the variable to null to avoid attaching a service account. | object({…}) | | {} | -| [shielded_config](variables.tf#L469) | Shielded VM configuration of the instances. | object({…}) | | null | -| [snapshot_schedules](variables.tf#L479) | Snapshot schedule resource policies that can be attached to disks. | map(object({…})) | | {} | -| [tag_bindings](variables.tf#L522) | Resource manager tag bindings in arbitrary key => tag key or value id format. Set on both the instance and zonal disks, and modifiable without impacting the main resource lifecycle. | map(string) | | {} | -| [tag_bindings_immutable](variables.tf#L529) | Immutable resource manager tag bindings, in tagKeys/id => tagValues/id format. These are set on the instance or instance template at creation time, and trigger recreation if changed. | map(string) | | null | -| [tags](variables.tf#L543) | Instance network tags for firewall rule targets. | list(string) | | [] | +| [boot_disk](variables.tf#L92) | Boot disk properties. Initialize params are ignored when source is set. | object({…}) | | {…} | +| [can_ip_forward](variables.tf#L135) | Enable IP forwarding. | bool | | false | +| [confidential_compute](variables.tf#L141) | Enable Confidential Compute for these instances. | bool | | false | +| [context](variables.tf#L147) | Context-specific interpolations. | object({…}) | | {} | +| [create_template](variables.tf#L164) | Create instance template instead of instances. Defaults to a global template. | object({…}) | | null | +| [description](variables.tf#L173) | Description of a Compute Instance. | string | | "Managed by the compute-vm Terraform module." | +| [enable_display](variables.tf#L179) | Enable virtual display on the instances. | bool | | false | +| [encryption](variables.tf#L185) | Encryption options. Only one of kms_key_self_link and disk_encryption_key_raw may be set. If needed, you can specify to encrypt or not the boot disk. | object({…}) | | null | +| [gpu](variables.tf#L195) | GPU information. Based on https://cloud.google.com/compute/docs/gpus. | object({…}) | | null | +| [group](variables.tf#L230) | Define this variable to create an instance group for instances. Disabled for template use. | object({…}) | | null | +| [hostname](variables.tf#L238) | Instance FQDN name. | string | | null | +| [iam](variables.tf#L244) | IAM bindings in {ROLE => [MEMBERS]} format. | map(list(string)) | | {} | +| [instance_schedule](variables.tf#L250) | Assign or create and assign an instance schedule policy. Either resource policy id or create_config must be specified if not null. Set active to null to dtach a policy from vm before destroying. | object({…}) | | null | +| [instance_type](variables.tf#L274) | Instance type. | string | | "f1-micro" | +| [kms_autokeys](variables.tf#L280) | KMS Autokey key handles. If location is not specified it will be inferred from the zone. Key handle names will be added to the kms_keys context with an `autokeys/` prefix. | map(object({…})) | | {} | +| [labels](variables.tf#L298) | Instance labels. | map(string) | | {} | +| [metadata](variables.tf#L304) | Instance metadata. | map(string) | | {} | +| [metadata_startup_script](variables.tf#L310) | Instance startup script. Will trigger recreation on change, even after importing. | string | | null | +| [min_cpu_platform](variables.tf#L317) | Minimum CPU platform. | string | | null | +| [network_attached_interfaces](variables.tf#L328) | Network interfaces using network attachments. | list(string) | | [] | +| [network_tag_bindings](variables.tf#L356) | Resource manager tag bindings in arbitrary key => tag key or value id format. Set on both the instance only for networking purposes, and modifiable without impacting the main resource lifecycle. | map(string) | | {} | +| [options](variables.tf#L363) | Instance options. | object({…}) | | {…} | +| [project_number](variables.tf#L435) | Project number. Used in tag bindings to avoid a permadiff. | string | | null | +| [resource_policies](variables.tf#L441) | Resource policies to attach to the instance or template. | list(string) | | null | +| [scratch_disks](variables.tf#L448) | Scratch disks configuration. | object({…}) | | {…} | +| [service_account](variables.tf#L460) | Service account email and scopes. If email is null, the default Compute service account will be used unless auto_create is true, in which case a service account will be created. Set the variable to null to avoid attaching a service account. | object({…}) | | {} | +| [shielded_config](variables.tf#L470) | Shielded VM configuration of the instances. | object({…}) | | null | +| [snapshot_schedules](variables.tf#L480) | Snapshot schedule resource policies that can be attached to disks. | map(object({…})) | | {} | +| [tag_bindings](variables.tf#L523) | Resource manager tag bindings in arbitrary key => tag key or value id format. Set on both the instance and zonal disks, and modifiable without impacting the main resource lifecycle. | map(string) | | {} | +| [tag_bindings_immutable](variables.tf#L530) | Immutable resource manager tag bindings, in tagKeys/id => tagValues/id format. These are set on the instance or instance template at creation time, and trigger recreation if changed. | map(string) | | null | +| [tags](variables.tf#L544) | Instance network tags for firewall rule targets. | list(string) | | [] | ## Outputs diff --git a/modules/compute-vm/main.tf b/modules/compute-vm/main.tf index 275ffc236..e8b5d7fbd 100644 --- a/modules/compute-vm/main.tf +++ b/modules/compute-vm/main.tf @@ -98,7 +98,7 @@ resource "google_compute_disk" "boot" { zone = local.zone # by default, GCP creates boot disks with the same name as instance, the deviation here is kept for backwards # compatibility - name = "${var.name}-boot" + name = coalesce(var.boot_disk.name, "${var.name}-boot") type = var.boot_disk.initialize_params.type size = var.boot_disk.initialize_params.size architecture = var.boot_disk.initialize_params.architecture diff --git a/modules/compute-vm/variables.tf b/modules/compute-vm/variables.tf index f8624c19d..ddbe31c7f 100644 --- a/modules/compute-vm/variables.tf +++ b/modules/compute-vm/variables.tf @@ -92,6 +92,7 @@ variable "attached_disks" { variable "boot_disk" { description = "Boot disk properties. Initialize params are ignored when source is set." type = object({ + name = optional(string) auto_delete = optional(bool, true) snapshot_schedule = optional(list(string)) source = optional(string)