diff --git a/.changelog/6649.txt b/.changelog/6649.txt new file mode 100644 index 00000000000..bb3617db362 --- /dev/null +++ b/.changelog/6649.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +container: Added support for the Disk type and size configuration on the GKE Node Auto-provisioning +``` diff --git a/google/resource_container_cluster.go b/google/resource_container_cluster.go old mode 100755 new mode 100644 index c25f5e8950b..9085641ebc7 --- a/google/resource_container_cluster.go +++ b/google/resource_container_cluster.go @@ -368,6 +368,20 @@ func resourceContainerCluster() *schema.Resource { Default: "default", Description: `The Google Cloud Platform Service Account to be used by the node VMs.`, }, + "disk_size": { + Type: schema.TypeInt, + Optional: true, + Default: 100, + Description: `Size of the disk attached to each node, specified in GB. The smallest allowed disk size is 10GB.`, + ValidateFunc: validation.IntAtLeast(10), + }, + "disk_type": { + Type: schema.TypeString, + Optional: true, + Default: "pd-standard", + Description: `Type of the disk attached to each node.`, + ValidateFunc: validation.StringInSlice([]string{"pd-standard", "pd-ssd", "pd-balanced"}, false), + }, "image_type": { Type: schema.TypeString, Optional: true, @@ -3121,6 +3135,8 @@ func expandAutoProvisioningDefaults(configured interface{}, d *schema.ResourceDa npd := &container.AutoprovisioningNodePoolDefaults{ OauthScopes: convertStringArr(config["oauth_scopes"].([]interface{})), ServiceAccount: config["service_account"].(string), + DiskSizeGb: int64(config["disk_size"].(int)), + DiskType: config["disk_type"].(string), ImageType: config["image_type"].(string), BootDiskKmsKey: config["boot_disk_kms_key"].(string), } @@ -3872,6 +3888,8 @@ func flattenAutoProvisioningDefaults(a *container.AutoprovisioningNodePoolDefaul r := make(map[string]interface{}) r["oauth_scopes"] = a.OauthScopes r["service_account"] = a.ServiceAccount + r["disk_size"] = a.DiskSizeGb + r["disk_type"] = a.DiskType r["image_type"] = a.ImageType r["boot_disk_kms_key"] = a.BootDiskKmsKey diff --git a/google/resource_container_cluster_test.go b/google/resource_container_cluster_test.go old mode 100755 new mode 100644 index 30d78375023..d497f9001ba --- a/google/resource_container_cluster_test.go +++ b/google/resource_container_cluster_test.go @@ -2061,6 +2061,72 @@ func TestAccContainerCluster_withSoleTenantGroup(t *testing.T) { }) } +func TestAccContainerCluster_nodeAutoprovisioningDefaultsDiskSizeGb(t *testing.T) { + t.Parallel() + + clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10)) + includeDiskSizeGb := true + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccContainerCluster_autoprovisioningDefaultsDiskSizeGb(clusterName, includeDiskSizeGb), + }, + { + ResourceName: "google_container_cluster.with_autoprovisioning", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"min_master_version"}, + }, + { + Config: testAccContainerCluster_autoprovisioningDefaultsDiskSizeGb(clusterName, !includeDiskSizeGb), + }, + { + ResourceName: "google_container_cluster.with_autoprovisioning", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"min_master_version"}, + }, + }, + }) +} + +func TestAccContainerCluster_nodeAutoprovisioningDefaultsDiskType(t *testing.T) { + t.Parallel() + + clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10)) + includeDiskType := true + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccContainerCluster_autoprovisioningDefaultsDiskType(clusterName, includeDiskType), + }, + { + ResourceName: "google_container_cluster.with_autoprovisioning", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"min_master_version"}, + }, + { + Config: testAccContainerCluster_autoprovisioningDefaultsDiskType(clusterName, !includeDiskType), + }, + { + ResourceName: "google_container_cluster.with_autoprovisioning", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"min_master_version"}, + }, + }, + }) +} + func TestAccContainerCluster_nodeAutoprovisioningDefaultsImageType(t *testing.T) { t.Parallel() @@ -3824,6 +3890,70 @@ resource "google_container_cluster" "with_autoprovisioning" { return config } +func testAccContainerCluster_autoprovisioningDefaultsDiskSizeGb(cluster string, includeDiskSizeGb bool) string { + DiskSizeGbCfg := "" + if includeDiskSizeGb { + DiskSizeGbCfg = `disk_size = 120` + } + + return fmt.Sprintf(` +data "google_container_engine_versions" "central1a" { + location = "us-central1-a" +} +resource "google_container_cluster" "with_autoprovisioning" { + name = "%s" + location = "us-central1-a" + initial_node_count = 1 + min_master_version = data.google_container_engine_versions.central1a.latest_master_version + cluster_autoscaling { + enabled = true + resource_limits { + resource_type = "cpu" + maximum = 2 + } + resource_limits { + resource_type = "memory" + maximum = 2048 + } + auto_provisioning_defaults { + %s + } + } +}`, cluster, DiskSizeGbCfg) +} + +func testAccContainerCluster_autoprovisioningDefaultsDiskType(cluster string, includeDiskType bool) string { + DiskTypeCfg := "" + if includeDiskType { + DiskTypeCfg = `disk_type = "pd-balanced"` + } + + return fmt.Sprintf(` +data "google_container_engine_versions" "central1a" { + location = "us-central1-a" +} +resource "google_container_cluster" "with_autoprovisioning" { + name = "%s" + location = "us-central1-a" + initial_node_count = 1 + min_master_version = data.google_container_engine_versions.central1a.latest_master_version + cluster_autoscaling { + enabled = true + resource_limits { + resource_type = "cpu" + maximum = 2 + } + resource_limits { + resource_type = "memory" + maximum = 2048 + } + auto_provisioning_defaults { + %s + } + } +}`, cluster, DiskTypeCfg) +} + func testAccContainerCluster_autoprovisioningDefaultsImageType(cluster string, includeImageType bool) string { imageTypeCfg := "" if includeImageType { diff --git a/website/docs/r/container_cluster.html.markdown b/website/docs/r/container_cluster.html.markdown old mode 100755 new mode 100644 index 4dc0e3a516e..6e2687bb8f2 --- a/website/docs/r/container_cluster.html.markdown +++ b/website/docs/r/container_cluster.html.markdown @@ -507,6 +507,10 @@ as "Intel Haswell" or "Intel Sandy Bridge". * `boot_disk_kms_key` - (Optional) The Customer Managed Encryption Key used to encrypt the boot disk attached to each node in the node pool. This should be of the form projects/[KEY_PROJECT_ID]/locations/[LOCATION]/keyRings/[RING_NAME]/cryptoKeys/[KEY_NAME]. For more information about protecting resources with Cloud KMS Keys please see: https://cloud.google.com/compute/docs/disks/customer-managed-encryption +* `disk_size` - (Optional) Size of the disk attached to each node, specified in GB. The smallest allowed disk size is 10GB. Defaults to `100` + +* `disk_type` - (Optional) Type of the disk attached to each node (e.g. 'pd-standard', 'pd-ssd' or 'pd-balanced'). Defaults to `pd-standard` + * `image_type` - (Optional) The default image type used by NAP once a new node pool is being created. Please note that according to the [official documentation](https://cloud.google.com/kubernetes-engine/docs/how-to/node-auto-provisioning#default-image-type) the value must be one of the [COS_CONTAINERD, COS, UBUNTU_CONTAINERD, UBUNTU]. __NOTE__ : COS AND UBUNTU are deprecated as of `GKE 1.24` The `authenticator_groups_config` block supports: