diff --git a/modules/compute-vm/README.md b/modules/compute-vm/README.md index a5de7a20f..46b014d13 100644 --- a/modules/compute-vm/README.md +++ b/modules/compute-vm/README.md @@ -1212,45 +1212,45 @@ module "sole-tenancy" { | name | description | type | required | default | |---|---|:---:|:---:|:---:| -| [name](variables.tf#L358) | Instance name. | string | ✓ | | -| [network_interfaces](variables.tf#L370) | Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed. | list(object({…})) | ✓ | | -| [project_id](variables.tf#L410) | Project id. | string | ✓ | | -| [zone](variables.tf#L567) | Compute zone. | string | ✓ | | +| [name](variables.tf#L356) | Instance name. | string | ✓ | | +| [network_interfaces](variables.tf#L368) | Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed. | list(object({…})) | ✓ | | +| [project_id](variables.tf#L408) | Project id. | string | ✓ | | +| [zone](variables.tf#L565) | Compute zone. | string | ✓ | | | [attached_disks](variables.tf#L17) | Additional disks. Source type is one of 'image' (zonal disks in vms and template), 'snapshot' (vm), 'existing', and null. | map(object({…})) | | {} | | [boot_disk](variables.tf#L57) | Boot disk properties. | object({…}) | | {} | -| [can_ip_forward](variables.tf#L114) | Enable IP forwarding. | bool | | false | -| [confidential_compute](variables.tf#L120) | Confidential Compute configuration. Set to 'SEV' or 'SEV_SNP' to enable. | string | | null | -| [context](variables.tf#L130) | Context-specific interpolations. | object({…}) | | {} | -| [create_template](variables.tf#L151) | Create instance template instead of instances. Defaults to a global template. | object({…}) | | null | -| [description](variables.tf#L160) | Description of a Compute Instance. | string | | "Managed by the compute-vm Terraform module." | -| [enable_display](variables.tf#L166) | Enable virtual display on the instances. | bool | | false | -| [encryption](variables.tf#L172) | 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#L183) | GPU information. Based on https://cloud.google.com/compute/docs/gpus. | object({…}) | | null | -| [group](variables.tf#L218) | Instance group configuration. Set 'named_ports' to create a new unmanaged instance group, or provide an existing group self_link/id in 'membership' to join one. | object({…}) | | null | -| [hostname](variables.tf#L227) | Instance FQDN name. | string | | null | -| [iam](variables.tf#L233) | IAM bindings in {ROLE => [MEMBERS]} format. | map(list(string)) | | {} | -| [instance_schedule](variables.tf#L239) | Assign or create and assign an instance schedule policy. Set active to null to detach a policy from vm before destroying. | object({…}) | | null | -| [kms_autokeys](variables.tf#L263) | 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#L281) | Instance labels. | map(string) | | {} | -| [lifecycle_config](variables.tf#L287) | Instance lifecycle and operational configurations. | object({…}) | | {} | -| [machine_features_config](variables.tf#L309) | Machine-level configuration. | object({…}) | | {} | -| [machine_type](variables.tf#L333) | Machine type. | string | | "e2-micro" | -| [metadata](variables.tf#L339) | Instance metadata. | map(string) | | {} | -| [metadata_startup_script](variables.tf#L345) | Instance startup script. Will trigger recreation on change, even after importing. | string | | null | -| [min_cpu_platform](variables.tf#L352) | Minimum CPU platform. | string | | null | -| [network_attached_interfaces](variables.tf#L363) | Network interfaces using network attachments. | list(string) | | [] | -| [network_performance_tier](variables.tf#L393) | Network performance total egress bandwidth tier. | string | | null | -| [network_tag_bindings](variables.tf#L403) | 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) | | {} | -| [project_number](variables.tf#L415) | Project number. Used in tag bindings to avoid a permadiff. | string | | null | -| [resource_policies](variables.tf#L421) | Resource policies to attach to the instance or template. | list(string) | | null | -| [scheduling_config](variables.tf#L428) | Scheduling configuration for the instance. | object({…}) | | {} | -| [scratch_disks](variables.tf#L463) | Scratch disks configuration. | object({…}) | | {…} | -| [service_account](variables.tf#L476) | 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#L487) | Shielded VM configuration of the instances. | object({…}) | | null | -| [snapshot_schedules](variables.tf#L497) | Snapshot schedule resource policies that can be attached to disks. | map(object({…})) | | {} | -| [tag_bindings](variables.tf#L540) | 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#L547) | 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#L561) | Instance network tags for firewall rule targets. | list(string) | | [] | +| [can_ip_forward](variables.tf#L112) | Enable IP forwarding. | bool | | false | +| [confidential_compute](variables.tf#L118) | Confidential Compute configuration. Set to 'SEV' or 'SEV_SNP' to enable. | string | | null | +| [context](variables.tf#L128) | Context-specific interpolations. | object({…}) | | {} | +| [create_template](variables.tf#L149) | Create instance template instead of instances. Defaults to a global template. | object({…}) | | null | +| [description](variables.tf#L158) | Description of a Compute Instance. | string | | "Managed by the compute-vm Terraform module." | +| [enable_display](variables.tf#L164) | Enable virtual display on the instances. | bool | | false | +| [encryption](variables.tf#L170) | 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#L181) | GPU information. Based on https://cloud.google.com/compute/docs/gpus. | object({…}) | | null | +| [group](variables.tf#L216) | Instance group configuration. Set 'named_ports' to create a new unmanaged instance group, or provide an existing group self_link/id in 'membership' to join one. | object({…}) | | null | +| [hostname](variables.tf#L225) | Instance FQDN name. | string | | null | +| [iam](variables.tf#L231) | IAM bindings in {ROLE => [MEMBERS]} format. | map(list(string)) | | {} | +| [instance_schedule](variables.tf#L237) | Assign or create and assign an instance schedule policy. Set active to null to detach a policy from vm before destroying. | object({…}) | | null | +| [kms_autokeys](variables.tf#L261) | 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#L279) | Instance labels. | map(string) | | {} | +| [lifecycle_config](variables.tf#L285) | Instance lifecycle and operational configurations. | object({…}) | | {} | +| [machine_features_config](variables.tf#L307) | Machine-level configuration. | object({…}) | | {} | +| [machine_type](variables.tf#L331) | Machine type. | string | | "e2-micro" | +| [metadata](variables.tf#L337) | Instance metadata. | map(string) | | {} | +| [metadata_startup_script](variables.tf#L343) | Instance startup script. Will trigger recreation on change, even after importing. | string | | null | +| [min_cpu_platform](variables.tf#L350) | Minimum CPU platform. | string | | null | +| [network_attached_interfaces](variables.tf#L361) | Network interfaces using network attachments. | list(string) | | [] | +| [network_performance_tier](variables.tf#L391) | Network performance total egress bandwidth tier. | string | | null | +| [network_tag_bindings](variables.tf#L401) | 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) | | {} | +| [project_number](variables.tf#L413) | Project number. Used in tag bindings to avoid a permadiff. | string | | null | +| [resource_policies](variables.tf#L419) | Resource policies to attach to the instance or template. | list(string) | | null | +| [scheduling_config](variables.tf#L426) | Scheduling configuration for the instance. | object({…}) | | {} | +| [scratch_disks](variables.tf#L461) | Scratch disks configuration. | object({…}) | | {…} | +| [service_account](variables.tf#L474) | 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#L485) | Shielded VM configuration of the instances. | object({…}) | | null | +| [snapshot_schedules](variables.tf#L495) | Snapshot schedule resource policies that can be attached to disks. | map(object({…})) | | {} | +| [tag_bindings](variables.tf#L538) | 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#L545) | 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#L559) | Instance network tags for firewall rule targets. | list(string) | | [] | ## Outputs diff --git a/modules/compute-vm/instance.tf b/modules/compute-vm/instance.tf index 55666b393..5c8a86277 100644 --- a/modules/compute-vm/instance.tf +++ b/modules/compute-vm/instance.tf @@ -111,10 +111,8 @@ resource "google_compute_instance" "default" { var.boot_disk.initialize_params == null || var.boot_disk.use_independent_disk != null - || ( - var.boot_disk.source.snapshot != null && - var.boot_disk.source.attach != null - ) + || + var.boot_disk.source.attach != null ? [] : [""] ) diff --git a/modules/compute-vm/variables.tf b/modules/compute-vm/variables.tf index 626ee8e5e..15627a9ec 100644 --- a/modules/compute-vm/variables.tf +++ b/modules/compute-vm/variables.tf @@ -85,14 +85,12 @@ variable "boot_disk" { nullable = false validation { condition = ( - var.boot_disk.initialize_params == null || - ( - var.boot_disk.source.attach == null && - var.boot_disk.source.snapshot == null && - var.boot_disk.source.disk == null - ) + var.boot_disk.initialize_params != null || + var.boot_disk.source.attach != null || + var.boot_disk.source.snapshot != null || + var.boot_disk.source.disk != null ) - error_message = "Initialize params cannot be used when attaching an existing disk or creating from a snapshot." + error_message = "Either initialize params or one of attach, snapshot, source disk should be specified." } validation { condition = (