From 776608cd23fdacde853599bc6754a8b7b70cafb3 Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 6 Dec 2018 13:19:22 -0800 Subject: [PATCH] Remove beta fields from GA Container resources (#2601) /cc @rileykarson --- google/node_config.go | 82 ++++----------- google/resource_container_cluster_test.go | 95 ----------------- google/resource_container_node_pool_test.go | 108 -------------------- 3 files changed, 18 insertions(+), 267 deletions(-) diff --git a/google/node_config.go b/google/node_config.go index 948f60db117..02416abe608 100644 --- a/google/node_config.go +++ b/google/node_config.go @@ -142,7 +142,7 @@ var schemaNodeConfig = &schema.Schema{ }, "taint": { - Deprecated: "This field is in beta and will be removed from this provider. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", Type: schema.TypeList, Optional: true, ForceNew: true, @@ -170,11 +170,11 @@ var schemaNodeConfig = &schema.Schema{ }, "workload_metadata_config": { - Deprecated: "This field is in beta and will be removed from this provider. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", - Type: schema.TypeList, - Optional: true, - ForceNew: true, - MaxItems: 1, + Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", + Type: schema.TypeList, + Optional: true, + ForceNew: true, + MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "node_metadata": { @@ -283,28 +283,6 @@ func expandNodeConfig(v interface{}) *containerBeta.NodeConfig { nc.MinCpuPlatform = v.(string) } - if v, ok := nodeConfig["taint"]; ok && len(v.([]interface{})) > 0 { - taints := v.([]interface{}) - nodeTaints := make([]*containerBeta.NodeTaint, 0, len(taints)) - for _, raw := range taints { - data := raw.(map[string]interface{}) - taint := &containerBeta.NodeTaint{ - Key: data["key"].(string), - Value: data["value"].(string), - Effect: data["effect"].(string), - } - nodeTaints = append(nodeTaints, taint) - } - nc.Taints = nodeTaints - } - - if v, ok := nodeConfig["workload_metadata_config"]; ok && len(v.([]interface{})) > 0 { - conf := v.([]interface{})[0].(map[string]interface{}) - nc.WorkloadMetadataConfig = &containerBeta.WorkloadMetadataConfig{ - NodeMetadata: conf["node_metadata"].(string), - } - } - return nc } @@ -316,20 +294,18 @@ func flattenNodeConfig(c *containerBeta.NodeConfig) []map[string]interface{} { } config = append(config, map[string]interface{}{ - "machine_type": c.MachineType, - "disk_size_gb": c.DiskSizeGb, - "disk_type": c.DiskType, - "guest_accelerator": flattenContainerGuestAccelerators(c.Accelerators), - "local_ssd_count": c.LocalSsdCount, - "service_account": c.ServiceAccount, - "metadata": c.Metadata, - "image_type": c.ImageType, - "labels": c.Labels, - "tags": c.Tags, - "preemptible": c.Preemptible, - "min_cpu_platform": c.MinCpuPlatform, - "taint": flattenTaints(c.Taints), - "workload_metadata_config": flattenWorkloadMetadataConfig(c.WorkloadMetadataConfig), + "machine_type": c.MachineType, + "disk_size_gb": c.DiskSizeGb, + "disk_type": c.DiskType, + "guest_accelerator": flattenContainerGuestAccelerators(c.Accelerators), + "local_ssd_count": c.LocalSsdCount, + "service_account": c.ServiceAccount, + "metadata": c.Metadata, + "image_type": c.ImageType, + "labels": c.Labels, + "tags": c.Tags, + "preemptible": c.Preemptible, + "min_cpu_platform": c.MinCpuPlatform, }) if len(c.OauthScopes) > 0 { @@ -350,28 +326,6 @@ func flattenContainerGuestAccelerators(c []*containerBeta.AcceleratorConfig) []m return result } -func flattenTaints(c []*containerBeta.NodeTaint) []map[string]interface{} { - result := []map[string]interface{}{} - for _, taint := range c { - result = append(result, map[string]interface{}{ - "key": taint.Key, - "value": taint.Value, - "effect": taint.Effect, - }) - } - return result -} - -func flattenWorkloadMetadataConfig(c *containerBeta.WorkloadMetadataConfig) []map[string]interface{} { - result := []map[string]interface{}{} - if c != nil { - result = append(result, map[string]interface{}{ - "node_metadata": c.NodeMetadata, - }) - } - return result -} - func taintDiffSuppress(k, old, new string, d *schema.ResourceData) bool { if strings.HasSuffix(k, "#") { oldCount, oldErr := strconv.Atoi(old) diff --git a/google/resource_container_cluster_test.go b/google/resource_container_cluster_test.go index de2d0053b10..a8b5979bfc8 100644 --- a/google/resource_container_cluster_test.go +++ b/google/resource_container_cluster_test.go @@ -658,52 +658,6 @@ func TestAccContainerCluster_withNodeConfigScopeAlias(t *testing.T) { }) } -func TestAccContainerCluster_withNodeConfigTaints(t *testing.T) { - t.Parallel() - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerClusterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccContainerCluster_withNodeConfigTaints(), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("google_container_cluster.with_node_config", "node_config.0.taint.#", "2"), - ), - }, - // Don't include an import step because beta features can't yet be imported. - // Once taints are in GA, consider merging this test with the _withNodeConfig test. - }, - }) -} - -func TestAccContainerCluster_withWorkloadMetadataConfig(t *testing.T) { - t.Parallel() - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerClusterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccContainerCluster_withWorkloadMetadataConfig(), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("google_container_cluster.with_workload_metadata_config", - "node_config.0.workload_metadata_config.0.node_metadata", "SECURE"), - ), - }, - { - ResourceName: "google_container_cluster.with_workload_metadata_config", - ImportStateIdPrefix: "us-central1-a/", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"min_master_version"}, - }, - }, - }) -} - func TestAccContainerCluster_network(t *testing.T) { t.Parallel() @@ -1760,55 +1714,6 @@ resource "google_container_cluster" "with_node_config_scope_alias" { }`, acctest.RandString(10)) } -func testAccContainerCluster_withNodeConfigTaints() string { - return fmt.Sprintf(` -resource "google_container_cluster" "with_node_config" { - name = "cluster-test-%s" - zone = "us-central1-f" - initial_node_count = 1 - - node_config { - taint { - key = "taint_key" - value = "taint_value" - effect = "PREFER_NO_SCHEDULE" - } - taint { - key = "taint_key2" - value = "taint_value2" - effect = "NO_EXECUTE" - } - } -}`, acctest.RandString(10)) -} - -func testAccContainerCluster_withWorkloadMetadataConfig() string { - return fmt.Sprintf(` -data "google_container_engine_versions" "central1a" { - zone = "us-central1-a" -} - -resource "google_container_cluster" "with_workload_metadata_config" { - name = "cluster-test-%s" - zone = "us-central1-a" - initial_node_count = 1 - min_master_version = "${data.google_container_engine_versions.central1a.latest_master_version}" - node_version = "${data.google_container_engine_versions.central1a.latest_node_version}" - - node_config { - oauth_scopes = [ - "https://www.googleapis.com/auth/logging.write", - "https://www.googleapis.com/auth/monitoring" - ] - - workload_metadata_config { - node_metadata = "SECURE" - } - } -} -`, acctest.RandString(10)) -} - func testAccContainerCluster_networkRef() string { return fmt.Sprintf(` resource "google_compute_network" "container_network" { diff --git a/google/resource_container_node_pool_test.go b/google/resource_container_node_pool_test.go index 3bb8b998631..a64be0e17dc 100644 --- a/google/resource_container_node_pool_test.go +++ b/google/resource_container_node_pool_test.go @@ -91,55 +91,6 @@ func TestAccContainerNodePool_withNodeConfig(t *testing.T) { }) } -func TestAccContainerNodePool_withNodeConfigTaints(t *testing.T) { - t.Parallel() - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerNodePoolDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccContainerNodePool_withNodeConfigTaints(), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("google_container_node_pool.np_with_node_config", "node_config.0.taint.#", "2"), - ), - }, - // Don't include an import step because beta features can't yet be imported. - // Once taints are in GA, consider merging this test with the _withNodeConfig test. - }, - }) -} - -func TestAccContainerNodePool_withWorkloadMetadataConfig(t *testing.T) { - t.Parallel() - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerClusterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccContainerNodePool_withWorkloadMetadataConfig(), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("google_container_node_pool.with_workload_metadata_config", - "node_config.0.workload_metadata_config.0.node_metadata", "SECURE"), - ), - }, - { - ResourceName: "google_container_node_pool.with_workload_metadata_config", - ImportState: true, - ImportStateVerify: true, - // Import always uses the v1 API, so beta features don't get imported. - ImportStateVerifyIgnore: []string{ - "node_config.0.workload_metadata_config.#", - "node_config.0.workload_metadata_config.0.node_metadata", - }, - }, - }, - }) -} - func TestAccContainerNodePool_withGPU(t *testing.T) { t.Parallel() @@ -707,65 +658,6 @@ resource "google_container_node_pool" "np_with_node_config" { }`, cluster, nodePool) } -func testAccContainerNodePool_withNodeConfigTaints() string { - return fmt.Sprintf(` -resource "google_container_cluster" "cluster" { - name = "tf-cluster-nodepool-test-%s" - zone = "us-central1-a" - initial_node_count = 1 -} -resource "google_container_node_pool" "np_with_node_config" { - name = "tf-nodepool-test-%s" - zone = "us-central1-a" - cluster = "${google_container_cluster.cluster.name}" - initial_node_count = 1 - node_config { - taint { - key = "taint_key" - value = "taint_value" - effect = "PREFER_NO_SCHEDULE" - } - taint { - key = "taint_key2" - value = "taint_value2" - effect = "NO_EXECUTE" - } - } -}`, acctest.RandString(10), acctest.RandString(10)) -} - -func testAccContainerNodePool_withWorkloadMetadataConfig() string { - return fmt.Sprintf(` -data "google_container_engine_versions" "central1a" { - zone = "us-central1-a" -} - -resource "google_container_cluster" "cluster" { - name = "tf-cluster-nodepool-test-%s" - zone = "us-central1-a" - initial_node_count = 1 - min_master_version = "${data.google_container_engine_versions.central1a.latest_master_version}" -} - -resource "google_container_node_pool" "with_workload_metadata_config" { - name = "tf-nodepool-test-%s" - zone = "us-central1-a" - cluster = "${google_container_cluster.cluster.name}" - initial_node_count = 1 - node_config { - oauth_scopes = [ - "https://www.googleapis.com/auth/logging.write", - "https://www.googleapis.com/auth/monitoring" - ] - - workload_metadata_config { - node_metadata = "SECURE" - } - } -} -`, acctest.RandString(10), acctest.RandString(10)) -} - func testAccContainerNodePool_withGPU() string { return fmt.Sprintf(` data "google_container_engine_versions" "central1c" {