Skip to content

Commit

Permalink
Add support for disk config on the GKE Node Auto provisioning (#6649) (
Browse files Browse the repository at this point in the history
…#12786)

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Oct 13, 2022
1 parent 01f05e3 commit 70e87c8
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 0 deletions.
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

0 comments on commit 70e87c8

Please sign in to comment.