Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for disk config on the GKE Node Auto provisioning #12786

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .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
```
18 changes: 18 additions & 0 deletions google/resource_container_cluster.go 100755 → 100644
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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

Expand Down
130 changes: 130 additions & 0 deletions google/resource_container_cluster_test.go 100755 → 100644
Expand Up @@ -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()

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/container_cluster.html.markdown 100755 → 100644
Expand Up @@ -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`

<a name="nested_authenticator_groups_config"></a>The `authenticator_groups_config` block supports:
Expand Down