From a4bd8c6cf9de00b51188369d1d54ce49e1ed5134 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Wed, 3 Mar 2021 21:10:48 +0000 Subject: [PATCH] Add support for ephemeral_storage_config in container node_config (#4510) * Add support for ephemeral_storage_config in container node_config * Add missing beta guards and don't check for nil version * Fix bad cast of local_ssd_count * fixup! Add missing beta guards and don't check for nil version * Better represent current limitations around ephemeral storage in tests * Remove min_master_version from node_pool Co-authored-by: Riley Karson * Add min_master_version to cluster Co-authored-by: Riley Karson Co-authored-by: Riley Karson Signed-off-by: Modular Magician --- .changelog/4510.txt | 3 ++ google-beta/node_config.go | 35 ++++++++++++++ .../resource_container_node_pool_test.go | 48 +++++++++++++++++++ .../docs/r/container_cluster.html.markdown | 12 +++++ 4 files changed, 98 insertions(+) create mode 100644 .changelog/4510.txt diff --git a/.changelog/4510.txt b/.changelog/4510.txt new file mode 100644 index 0000000000..67d390a563 --- /dev/null +++ b/.changelog/4510.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +container: added field `ephemeral_storage_config` to resource `google_container_node_pool` and `google_container_cluster` (beta) +``` diff --git a/google-beta/node_config.go b/google-beta/node_config.go index ba00c46bbb..0de9da3204 100644 --- a/google-beta/node_config.go +++ b/google-beta/node_config.go @@ -93,6 +93,23 @@ func schemaNodeConfig() *schema.Schema { ValidateFunc: validation.IntAtLeast(0), }, + "ephemeral_storage_config": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + ForceNew: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "local_ssd_count": { + Type: schema.TypeInt, + Required: true, + ForceNew: true, + ValidateFunc: validation.IntAtLeast(0), + }, + }, + }, + }, + "machine_type": { Type: schema.TypeString, Optional: true, @@ -331,6 +348,13 @@ func expandNodeConfig(v interface{}) *containerBeta.NodeConfig { nc.LocalSsdCount = int64(v.(int)) } + if v, ok := nodeConfig["ephemeral_storage_config"]; ok && len(v.([]interface{})) > 0 { + conf := v.([]interface{})[0].(map[string]interface{}) + nc.EphemeralStorageConfig = &containerBeta.EphemeralStorageConfig{ + LocalSsdCount: int64(conf["local_ssd_count"].(int)), + } + } + if scopes, ok := nodeConfig["oauth_scopes"]; ok { scopesSet := scopes.(*schema.Set) scopes := make([]string, scopesSet.Len()) @@ -505,6 +529,7 @@ func flattenNodeConfig(c *containerBeta.NodeConfig) []map[string]interface{} { "disk_type": c.DiskType, "guest_accelerator": flattenContainerGuestAccelerators(c.Accelerators), "local_ssd_count": c.LocalSsdCount, + "ephemeral_storage_config": flattenEphemeralStorageConfig(c.EphemeralStorageConfig), "service_account": c.ServiceAccount, "metadata": c.Metadata, "image_type": c.ImageType, @@ -550,6 +575,16 @@ func flattenShieldedInstanceConfig(c *containerBeta.ShieldedInstanceConfig) []ma return result } +func flattenEphemeralStorageConfig(c *containerBeta.EphemeralStorageConfig) []map[string]interface{} { + result := []map[string]interface{}{} + if c != nil { + result = append(result, map[string]interface{}{ + "local_ssd_count": c.LocalSsdCount, + }) + } + return result +} + func flattenTaints(c []*containerBeta.NodeTaint) []map[string]interface{} { result := []map[string]interface{}{} for _, taint := range c { diff --git a/google-beta/resource_container_node_pool_test.go b/google-beta/resource_container_node_pool_test.go index 68292baacb..cc633eadca 100644 --- a/google-beta/resource_container_node_pool_test.go +++ b/google-beta/resource_container_node_pool_test.go @@ -841,6 +841,54 @@ func TestAccContainerNodePool_shieldedInstanceConfig(t *testing.T) { }) } +func TestAccContainerNodePool_ephemeralStorageConfig(t *testing.T) { + t.Parallel() + + cluster := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10)) + np := fmt.Sprintf("tf-test-nodepool-%s", randString(t, 10)) + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccContainerNodePool_ephemeralStorageConfig(cluster, np), + }, + { + ResourceName: "google_container_node_pool.np", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccContainerNodePool_ephemeralStorageConfig(cluster, np string) string { + return fmt.Sprintf(` +resource "google_container_cluster" "cluster" { + name = "%s" + location = "us-central1-a" + initial_node_count = 1 + min_master_version = "1.18" +} + +resource "google_container_node_pool" "np" { + name = "%s" + location = "us-central1-a" + cluster = google_container_cluster.cluster.name + initial_node_count = 1 + + node_config { + machine_type = "n1-standard-1" + ephemeral_storage_config { + local_ssd_count = 1 + } + } +} +`, cluster, np) +} + func testAccCheckContainerNodePoolDestroyProducer(t *testing.T) func(s *terraform.State) error { return func(s *terraform.State) error { config := googleProviderConfig(t) diff --git a/website/docs/r/container_cluster.html.markdown b/website/docs/r/container_cluster.html.markdown index 7cc47905c2..c78a5e5bf3 100644 --- a/website/docs/r/container_cluster.html.markdown +++ b/website/docs/r/container_cluster.html.markdown @@ -582,6 +582,14 @@ The `node_config` block supports: * `disk_type` - (Optional) Type of the disk attached to each node (e.g. 'pd-standard', 'pd-balanced' or 'pd-ssd'). If unspecified, the default disk type is 'pd-standard' +* `ephemeral_storage_config` - (Optional, [Beta]) Parameters for the ephemeral storage filesystem. If unspecified, ephemeral storage is backed by the boot disk. Structure is documented below. + +```hcl +ephemeral_storage_config { + local_ssd_count = 2 +} +``` + * `guest_accelerator` - (Optional) List of the type and count of accelerator cards attached to the instance. Structure documented below. To support removal of guest_accelerators in Terraform 0.12 this field is an @@ -673,6 +681,10 @@ linux_node_config { } ``` +The `ephemeral_storage_config` block supports: + +* `local_ssd_count` (Required) - Number of local SSDs to use to back ephemeral storage. Uses NVMe interfaces. Each local SSD is 375 GB in size. If zero, it means to disable using local SSDs as ephemeral storage. + The `guest_accelerator` block supports: * `type` (Required) - The accelerator type resource to expose to this instance. E.g. `nvidia-tesla-k80`.