hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.36k stars 1.75k forks source link

disk_type is not required under auto_provisioning_defaults for node autoprovisioning #18546

Open ttruong-actian opened 5 months ago

ttruong-actian commented 5 months ago

Community Note

Terraform Version & Provider Version(s)

Terraform v1.8.3 on darwin_arm64

Affected Resource(s)

node autoprovisioning does not required disk_type to be defined with default settings. that way, we NAP can create node pools with N2/N4 where different disk_type are required.

Terraform Configuration


      for_each = var.cluster_autoscaling.enabled ? [1] : []
      content {
        service_account   = google_service_account.main_cluster.email
        oauth_scopes      = local.node_oauth_scopes
        boot_disk_kms_key = var.cluster_autoscaling.manual_updated_nap ? var.kms_encryption_key : null
        management {
          auto_repair  = lookup(var.cluster_autoscaling, "auto_repair", false)
          auto_upgrade = lookup(var.cluster_autoscaling, "auto_upgrade", false)
        }
        upgrade_settings {
          strategy        = "SURGE"
          max_surge       = 1
          max_unavailable = 0
        }
        disk_size = lookup(var.cluster_autoscaling, "disk_size", 100)
      }```

### Debug Output

``` ~ cluster_autoscaling {
            # (2 unchanged attributes hidden)

          ~ auto_provisioning_defaults {
              ~ disk_size         = 0 -> 100
              + disk_type         = "pd-balanced"```

### Expected Behavior

I do not want to define the `disk_type` especially with N4 instance family, there's a new `hyerdisk-balanced` that i want to use and not support in older generations of family

### Actual Behavior

``` ~ cluster_autoscaling {
            # (2 unchanged attributes hidden)

          ~ auto_provisioning_defaults {
              ~ disk_size         = 0 -> 100
              + disk_type         =  "pd-standard"```

Terraform want to set the `disk_type` to the default value.

### Steps to reproduce

1. `terraform apply`

### Important Factoids

_No response_

### References

_No response_
ggtisc commented 5 months ago

Hi @ttruong-actian!

To replicate this issue we need the full name of the terraform resource, I found the service google_service_account in terraform registry, but it don't contain any argument or attribute called disk_type

Also please share the full code of the resource, because we can't replicate the issue with information that only you know. For sensitive information you could change it with examples like:

project = "my-project" org_id = "1234567890" email = "my-user@my-domain.com"

ttruong-actian commented 5 months ago

hi @ggtisc ,

my bad about the missing details. Here's my sample code for the cluster_autoscaling block with auto_provisioning_defaults. I wanted to use this block to define the ServiceAccount and KMSEncryptionKey for all node pools. In this block, the disk_type and disk_size are indicated as optional but they're set with a Default Value of 100Gb and pd-standard.

    enabled = var.cluster_autoscaling.enabled
    dynamic "auto_provisioning_defaults" {
      for_each = var.cluster_autoscaling.enabled ? [1] : []
      content {
        service_account   = google_service_account.main_cluster.email
        oauth_scopes      = local.node_oauth_scopes
        boot_disk_kms_key = var.cluster_autoscaling.manual_updated_nap ? var.kms_encryption_key : null
        management {
          auto_repair  = lookup(var.cluster_autoscaling, "auto_repair", false)
          auto_upgrade = lookup(var.cluster_autoscaling, "auto_upgrade", false)
        }
        upgrade_settings {
          strategy        = "SURGE"
          max_surge       = 1
          max_unavailable = 0
        }
      }
    }

When I tried to enable node-autoprovisioning via gcloud cli with a config file, the disk_type and disk_size are not required. my sample nap-config file below

autoprovisioningLocations:
  - us-central1-a
  - us-central1-c
  bootDiskKmsKey: projects/<name>/locations/us-central1/keyRings/<ring>/cryptoKeys/<key>
  imageType: COS_CONTAINERD
  serviceAccount: <name>@<project>.iam.gserviceaccount.com
  scopes:
    - https://www.googleapis.com/auth/logging.write
    - https://www.googleapis.com/auth/monitoring
  resourceLimits:
    - resourceType: 'cpu'
      maximum: 100
    - resourceType: 'memory'
      maximum: 100
ggtisc commented 5 months ago

Thanks!

As you can see in Google Cloud documentation looking for the diskType field you'll notice that the default disk type is pd-standard if you don't set a value for this optional field.

If you're looking to use a hyperdisk-balanced you need to define it. If you need help on how to use it you could check the documentation here, and the different disk types here.

If after this you continue with issues please share a full code of your google_container_cluster like this.