diff --git a/google/resource_container_cluster.go b/google/resource_container_cluster.go index eef57e674a1..58a5d5cba56 100644 --- a/google/resource_container_cluster.go +++ b/google/resource_container_cluster.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" "google.golang.org/api/container/v1" ) @@ -29,7 +30,7 @@ func resourceContainerCluster() *schema.Resource { Delete: schema.DefaultTimeout(10 * time.Minute), }, - SchemaVersion: 2, + SchemaVersion: 1, MigrateState: resourceContainerClusterMigrateState, Schema: map[string]*schema.Schema{ @@ -236,9 +237,18 @@ func resourceContainerCluster() *schema.Resource { ForceNew: true, // TODO(danawillow): Add ability to add/remove nodePools Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "initial_node_count": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Deprecated: "Use node_count instead", + }, + "node_count": { - Type: schema.TypeInt, - Required: true, + Type: schema.TypeInt, + Optional: true, + Computed: true, + ValidateFunc: validation.IntAtLeast(1), }, "name": { @@ -374,7 +384,19 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er for i := 0; i < nodePoolsCount; i++ { prefix := fmt.Sprintf("node_pool.%d", i) - nodeCount := d.Get(prefix + ".node_count").(int) + nodeCount := 0 + if initialNodeCount, ok := d.GetOk(prefix + ".initial_node_count"); ok { + nodeCount = initialNodeCount.(int) + } + if nc, ok := d.GetOk(prefix + ".node_count"); ok { + if nodeCount != 0 { + return fmt.Errorf("Cannot set both initial_node_count and node_count on node pool %d", i) + } + nodeCount = nc.(int) + } + if nodeCount == 0 { + return fmt.Errorf("Node pool %d cannot be set with 0 node count", i) + } name, err := generateNodePoolName(prefix, d) if err != nil { @@ -727,10 +749,11 @@ func flattenClusterNodePools(d *schema.ResourceData, config *Config, c []*contai size += int(igm.TargetSize) } nodePool := map[string]interface{}{ - "name": np.Name, - "name_prefix": d.Get(fmt.Sprintf("node_pool.%d.name_prefix", i)), - "node_config": flattenClusterNodeConfig(np.Config), - "node_count": size / len(np.InstanceGroupUrls), + "name": np.Name, + "name_prefix": d.Get(fmt.Sprintf("node_pool.%d.name_prefix", i)), + "initial_node_count": np.InitialNodeCount, + "node_count": size / len(np.InstanceGroupUrls), + "node_config": flattenClusterNodeConfig(np.Config), } nodePools = append(nodePools, nodePool) } diff --git a/google/resource_container_cluster_migrate.go b/google/resource_container_cluster_migrate.go index e2c77f34b05..720936b211a 100644 --- a/google/resource_container_cluster_migrate.go +++ b/google/resource_container_cluster_migrate.go @@ -21,9 +21,6 @@ func resourceContainerClusterMigrateState( case 0: log.Println("[INFO] Found Container Cluster State v0; migrating to v1") return migrateClusterStateV0toV1(is) - case 1: - log.Println("[INFO] Found Container Cluster State v1; migrating to v2") - return migrateClusterStateV1toV2(is) default: return is, fmt.Errorf("Unexpected schema version: %d", v) } @@ -71,23 +68,3 @@ func migrateClusterStateV0toV1(is *terraform.InstanceState) (*terraform.Instance log.Printf("[DEBUG] Attributes after migration: %#v", is.Attributes) return is, nil } - -func migrateClusterStateV1toV2(is *terraform.InstanceState) (*terraform.InstanceState, error) { - log.Printf("[DEBUG] Attributes before migration: %#v", is.Attributes) - - for k, v := range is.Attributes { - if !strings.HasPrefix(k, "node_pool.") { - continue - } - if !strings.HasSuffix(k, ".initial_node_count") { - continue - } - - is.Attributes[strings.Replace(k, "initial_node_count", "node_count", 1)] = v - - delete(is.Attributes, k) - } - - log.Printf("[DEBUG] Attributes after migration: %#v", is.Attributes) - return is, nil -} diff --git a/google/resource_container_cluster_migrate_test.go b/google/resource_container_cluster_migrate_test.go index d7ef4148c3d..84fa535b617 100644 --- a/google/resource_container_cluster_migrate_test.go +++ b/google/resource_container_cluster_migrate_test.go @@ -27,20 +27,6 @@ func TestContainerClusterMigrateState(t *testing.T) { }, Meta: &Config{}, }, - "rename node_pool.initial_node_count to node_pool.node_count": { - StateVersion: 1, - Attributes: map[string]string{ - "node_pool.#": "2", - "node_pool.0.initial_node_count": "3", - "node_pool.1.initial_node_count": "2", - }, - Expected: map[string]string{ - "node_pool.#": "2", - "node_pool.0.node_count": "3", - "node_pool.1.node_count": "2", - }, - Meta: &Config{}, - }, } for tn, tc := range cases { diff --git a/google/resource_container_cluster_test.go b/google/resource_container_cluster_test.go index 01cc82b8076..51ea8eb0e37 100644 --- a/google/resource_container_cluster_test.go +++ b/google/resource_container_cluster_test.go @@ -850,7 +850,7 @@ resource "google_container_cluster" "with_node_pool" { node_pool { name = "tf-cluster-nodepool-test-%s" - node_count = 2 + initial_node_count = 2 } }`, acctest.RandString(10), acctest.RandString(10))