Fix boot disk validation when attaching existing disk in compute-vm (#4015)
This commit is contained in:
committed by
GitHub
parent
4a9245d20a
commit
24775a03ae
@@ -1212,45 +1212,45 @@ module "sole-tenancy" {
|
||||
|
||||
| name | description | type | required | default |
|
||||
|---|---|:---:|:---:|:---:|
|
||||
| [name](variables.tf#L358) | Instance name. | <code>string</code> | ✓ | |
|
||||
| [network_interfaces](variables.tf#L370) | Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed. | <code>list(object({…}))</code> | ✓ | |
|
||||
| [project_id](variables.tf#L410) | Project id. | <code>string</code> | ✓ | |
|
||||
| [zone](variables.tf#L567) | Compute zone. | <code>string</code> | ✓ | |
|
||||
| [name](variables.tf#L356) | Instance name. | <code>string</code> | ✓ | |
|
||||
| [network_interfaces](variables.tf#L368) | Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed. | <code>list(object({…}))</code> | ✓ | |
|
||||
| [project_id](variables.tf#L408) | Project id. | <code>string</code> | ✓ | |
|
||||
| [zone](variables.tf#L565) | Compute zone. | <code>string</code> | ✓ | |
|
||||
| [attached_disks](variables.tf#L17) | Additional disks. Source type is one of 'image' (zonal disks in vms and template), 'snapshot' (vm), 'existing', and null. | <code>map(object({…}))</code> | | <code>{}</code> |
|
||||
| [boot_disk](variables.tf#L57) | Boot disk properties. | <code>object({…})</code> | | <code>{}</code> |
|
||||
| [can_ip_forward](variables.tf#L114) | Enable IP forwarding. | <code>bool</code> | | <code>false</code> |
|
||||
| [confidential_compute](variables.tf#L120) | Confidential Compute configuration. Set to 'SEV' or 'SEV_SNP' to enable. | <code>string</code> | | <code>null</code> |
|
||||
| [context](variables.tf#L130) | Context-specific interpolations. | <code>object({…})</code> | | <code>{}</code> |
|
||||
| [create_template](variables.tf#L151) | Create instance template instead of instances. Defaults to a global template. | <code>object({…})</code> | | <code>null</code> |
|
||||
| [description](variables.tf#L160) | Description of a Compute Instance. | <code>string</code> | | <code>"Managed by the compute-vm Terraform module."</code> |
|
||||
| [enable_display](variables.tf#L166) | Enable virtual display on the instances. | <code>bool</code> | | <code>false</code> |
|
||||
| [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. | <code>object({…})</code> | | <code>null</code> |
|
||||
| [gpu](variables.tf#L183) | GPU information. Based on https://cloud.google.com/compute/docs/gpus. | <code>object({…})</code> | | <code>null</code> |
|
||||
| [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. | <code>object({…})</code> | | <code>null</code> |
|
||||
| [hostname](variables.tf#L227) | Instance FQDN name. | <code>string</code> | | <code>null</code> |
|
||||
| [iam](variables.tf#L233) | IAM bindings in {ROLE => [MEMBERS]} format. | <code>map(list(string))</code> | | <code>{}</code> |
|
||||
| [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. | <code>object({…})</code> | | <code>null</code> |
|
||||
| [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. | <code>map(object({…}))</code> | | <code>{}</code> |
|
||||
| [labels](variables.tf#L281) | Instance labels. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [lifecycle_config](variables.tf#L287) | Instance lifecycle and operational configurations. | <code>object({…})</code> | | <code>{}</code> |
|
||||
| [machine_features_config](variables.tf#L309) | Machine-level configuration. | <code>object({…})</code> | | <code>{}</code> |
|
||||
| [machine_type](variables.tf#L333) | Machine type. | <code>string</code> | | <code>"e2-micro"</code> |
|
||||
| [metadata](variables.tf#L339) | Instance metadata. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [metadata_startup_script](variables.tf#L345) | Instance startup script. Will trigger recreation on change, even after importing. | <code>string</code> | | <code>null</code> |
|
||||
| [min_cpu_platform](variables.tf#L352) | Minimum CPU platform. | <code>string</code> | | <code>null</code> |
|
||||
| [network_attached_interfaces](variables.tf#L363) | Network interfaces using network attachments. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [network_performance_tier](variables.tf#L393) | Network performance total egress bandwidth tier. | <code>string</code> | | <code>null</code> |
|
||||
| [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. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [project_number](variables.tf#L415) | Project number. Used in tag bindings to avoid a permadiff. | <code>string</code> | | <code>null</code> |
|
||||
| [resource_policies](variables.tf#L421) | Resource policies to attach to the instance or template. | <code>list(string)</code> | | <code>null</code> |
|
||||
| [scheduling_config](variables.tf#L428) | Scheduling configuration for the instance. | <code>object({…})</code> | | <code>{}</code> |
|
||||
| [scratch_disks](variables.tf#L463) | Scratch disks configuration. | <code>object({…})</code> | | <code>{…}</code> |
|
||||
| [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. | <code>object({…})</code> | | <code>{}</code> |
|
||||
| [shielded_config](variables.tf#L487) | Shielded VM configuration of the instances. | <code>object({…})</code> | | <code>null</code> |
|
||||
| [snapshot_schedules](variables.tf#L497) | Snapshot schedule resource policies that can be attached to disks. | <code>map(object({…}))</code> | | <code>{}</code> |
|
||||
| [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. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [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. | <code>map(string)</code> | | <code>null</code> |
|
||||
| [tags](variables.tf#L561) | Instance network tags for firewall rule targets. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [can_ip_forward](variables.tf#L112) | Enable IP forwarding. | <code>bool</code> | | <code>false</code> |
|
||||
| [confidential_compute](variables.tf#L118) | Confidential Compute configuration. Set to 'SEV' or 'SEV_SNP' to enable. | <code>string</code> | | <code>null</code> |
|
||||
| [context](variables.tf#L128) | Context-specific interpolations. | <code>object({…})</code> | | <code>{}</code> |
|
||||
| [create_template](variables.tf#L149) | Create instance template instead of instances. Defaults to a global template. | <code>object({…})</code> | | <code>null</code> |
|
||||
| [description](variables.tf#L158) | Description of a Compute Instance. | <code>string</code> | | <code>"Managed by the compute-vm Terraform module."</code> |
|
||||
| [enable_display](variables.tf#L164) | Enable virtual display on the instances. | <code>bool</code> | | <code>false</code> |
|
||||
| [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. | <code>object({…})</code> | | <code>null</code> |
|
||||
| [gpu](variables.tf#L181) | GPU information. Based on https://cloud.google.com/compute/docs/gpus. | <code>object({…})</code> | | <code>null</code> |
|
||||
| [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. | <code>object({…})</code> | | <code>null</code> |
|
||||
| [hostname](variables.tf#L225) | Instance FQDN name. | <code>string</code> | | <code>null</code> |
|
||||
| [iam](variables.tf#L231) | IAM bindings in {ROLE => [MEMBERS]} format. | <code>map(list(string))</code> | | <code>{}</code> |
|
||||
| [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. | <code>object({…})</code> | | <code>null</code> |
|
||||
| [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. | <code>map(object({…}))</code> | | <code>{}</code> |
|
||||
| [labels](variables.tf#L279) | Instance labels. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [lifecycle_config](variables.tf#L285) | Instance lifecycle and operational configurations. | <code>object({…})</code> | | <code>{}</code> |
|
||||
| [machine_features_config](variables.tf#L307) | Machine-level configuration. | <code>object({…})</code> | | <code>{}</code> |
|
||||
| [machine_type](variables.tf#L331) | Machine type. | <code>string</code> | | <code>"e2-micro"</code> |
|
||||
| [metadata](variables.tf#L337) | Instance metadata. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [metadata_startup_script](variables.tf#L343) | Instance startup script. Will trigger recreation on change, even after importing. | <code>string</code> | | <code>null</code> |
|
||||
| [min_cpu_platform](variables.tf#L350) | Minimum CPU platform. | <code>string</code> | | <code>null</code> |
|
||||
| [network_attached_interfaces](variables.tf#L361) | Network interfaces using network attachments. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [network_performance_tier](variables.tf#L391) | Network performance total egress bandwidth tier. | <code>string</code> | | <code>null</code> |
|
||||
| [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. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [project_number](variables.tf#L413) | Project number. Used in tag bindings to avoid a permadiff. | <code>string</code> | | <code>null</code> |
|
||||
| [resource_policies](variables.tf#L419) | Resource policies to attach to the instance or template. | <code>list(string)</code> | | <code>null</code> |
|
||||
| [scheduling_config](variables.tf#L426) | Scheduling configuration for the instance. | <code>object({…})</code> | | <code>{}</code> |
|
||||
| [scratch_disks](variables.tf#L461) | Scratch disks configuration. | <code>object({…})</code> | | <code>{…}</code> |
|
||||
| [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. | <code>object({…})</code> | | <code>{}</code> |
|
||||
| [shielded_config](variables.tf#L485) | Shielded VM configuration of the instances. | <code>object({…})</code> | | <code>null</code> |
|
||||
| [snapshot_schedules](variables.tf#L495) | Snapshot schedule resource policies that can be attached to disks. | <code>map(object({…}))</code> | | <code>{}</code> |
|
||||
| [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. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [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. | <code>map(string)</code> | | <code>null</code> |
|
||||
| [tags](variables.tf#L559) | Instance network tags for firewall rule targets. | <code>list(string)</code> | | <code>[]</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
||||
@@ -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
|
||||
? []
|
||||
: [""]
|
||||
)
|
||||
|
||||
@@ -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 = (
|
||||
|
||||
Reference in New Issue
Block a user