From 705a9a754d1a93d8c26b05ab88e8783be00200d2 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 4 Mar 2019 18:03:58 -0800 Subject: [PATCH] Just don't set remove_node_pool on import (#3180) Signed-off-by: Modular Magician --- google/resource_container_cluster.go | 16 +------ google/resource_container_cluster_test.go | 45 ++++++++++--------- .../docs/r/container_cluster.html.markdown | 8 ++-- 3 files changed, 31 insertions(+), 38 deletions(-) diff --git a/google/resource_container_cluster.go b/google/resource_container_cluster.go index 05daf489..1263c3fe 100644 --- a/google/resource_container_cluster.go +++ b/google/resource_container_cluster.go @@ -1799,15 +1799,14 @@ func resourceContainerClusterStateImporter(d *schema.ResourceData, meta interfac return nil, fmt.Errorf("Invalid container cluster specifier. Expecting {zone}/{name} or {project}/{zone}/{name}") } - if len(project) > 0 { - d.Set("project", project) - } else { + if len(project) == 0 { var err error project, err = getProject(d, config) if err != nil { return nil, err } } + d.Set("project", project) if isZone(location) { d.Set("zone", location) @@ -1818,17 +1817,6 @@ func resourceContainerClusterStateImporter(d *schema.ResourceData, meta interfac d.Set("name", clusterName) d.SetId(clusterName) - // Try to determine remove_default_node_pool from presence of default - // node pool; if still present and user has it set to true, the pool - // will get removed on next apply. - nodePool := fmt.Sprintf("%s/nodePools/%s", containerClusterFullName(project, location, clusterName), "default-pool") - _, err := config.clientContainerBeta.Projects.Locations.Clusters.NodePools.Get(nodePool).Do() - if err != nil && isGoogleApiErrorWithCode(err, 404) { - d.Set("remove_default_node_pool", true) - } else if err != nil { - log.Printf("[WARN] Unable to import value for remove_default_node_pool, got error while trying to get default node pool: %s", err) - } - return []*schema.ResourceData{d}, nil } diff --git a/google/resource_container_cluster_test.go b/google/resource_container_cluster_test.go index ec1c545e..2bd1645d 100644 --- a/google/resource_container_cluster_test.go +++ b/google/resource_container_cluster_test.go @@ -206,10 +206,11 @@ func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) { ), }, { - ResourceName: "google_container_cluster.with_network_policy_enabled", - ImportStateIdPrefix: "us-central1-a/", - ImportState: true, - ImportStateVerify: true, + ResourceName: "google_container_cluster.with_network_policy_enabled", + ImportStateIdPrefix: "us-central1-a/", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"remove_default_node_pool"}, }, { Config: testAccContainerCluster_removeNetworkPolicy(clusterName), @@ -219,10 +220,11 @@ func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) { ), }, { - ResourceName: "google_container_cluster.with_network_policy_enabled", - ImportStateIdPrefix: "us-central1-a/", - ImportState: true, - ImportStateVerify: true, + ResourceName: "google_container_cluster.with_network_policy_enabled", + ImportStateIdPrefix: "us-central1-a/", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"remove_default_node_pool"}, }, { Config: testAccContainerCluster_withNetworkPolicyDisabled(clusterName), @@ -232,10 +234,11 @@ func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) { ), }, { - ResourceName: "google_container_cluster.with_network_policy_enabled", - ImportStateIdPrefix: "us-central1-a/", - ImportState: true, - ImportStateVerify: true, + ResourceName: "google_container_cluster.with_network_policy_enabled", + ImportStateIdPrefix: "us-central1-a/", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"remove_default_node_pool"}, }, { Config: testAccContainerCluster_withNetworkPolicyConfigDisabled(clusterName), @@ -245,10 +248,11 @@ func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) { ), }, { - ResourceName: "google_container_cluster.with_network_policy_enabled", - ImportStateIdPrefix: "us-central1-a/", - ImportState: true, - ImportStateVerify: true, + ResourceName: "google_container_cluster.with_network_policy_enabled", + ImportStateIdPrefix: "us-central1-a/", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"remove_default_node_pool"}, }, { Config: testAccContainerCluster_withNetworkPolicyConfigDisabled(clusterName), @@ -1023,10 +1027,11 @@ func TestAccContainerCluster_withDefaultNodePoolRemoved(t *testing.T) { "google_container_cluster.with_default_node_pool_removed", "node_pool.#", "0"), }, { - ResourceName: "google_container_cluster.with_default_node_pool_removed", - ImportStateIdPrefix: "us-central1-a/", - ImportState: true, - ImportStateVerify: true, + ResourceName: "google_container_cluster.with_default_node_pool_removed", + ImportStateIdPrefix: "us-central1-a/", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"remove_default_node_pool"}, }, }, }) diff --git a/website/docs/r/container_cluster.html.markdown b/website/docs/r/container_cluster.html.markdown index 1d7ddc9f..85a5123e 100644 --- a/website/docs/r/container_cluster.html.markdown +++ b/website/docs/r/container_cluster.html.markdown @@ -589,9 +589,9 @@ $ terraform import google_container_cluster.mycluster my-gcp-project/us-east1-a/ $ terraform import google_container_cluster.mycluster us-east1-a/my-cluster ``` -~> **Note:** This resource has several fields that control Terraform-specific behavior and aren't present in the API. If they are set in config and you import a cluster, Terraform may need to perform an update immediately after import. Some of these updates are no-ops, and some may modify your cluster. +~> **Note:** This resource has several fields that control Terraform-specific behavior and aren't present in the API. If they are set in config and you import a cluster, Terraform may need to perform an update immediately after import. Most of these updates should be no-ops but some may modify your cluster if the imported state differs. -For example: +For example, the following fields will show diffs if set in config: -- `min_master_version` will not be set on import and will show a no-op diff if set in config. -- `remove_default_node_pool`: If the default node pool does not exist at import, this value will be set to true in state, but it will not be set otherwise. Thus, you may see a no-op diff if set to false in config, or a diff if set to true in config when the default node pool still exists. +- `min_master_version` +- `remove_default_node_pool`