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 ephemeral_storage_config in container node_config #3023

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/4510.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
container: added field `ephemeral_storage_config` to resource `google_container_node_pool` and `google_container_cluster` (beta)
```
35 changes: 35 additions & 0 deletions google-beta/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
48 changes: 48 additions & 0 deletions google-beta/resource_container_node_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`.
Expand Down