Skip to content

Commit

Permalink
Remove name_prefix from container node pool (#638)
Browse files Browse the repository at this point in the history
Merged PR #638.
  • Loading branch information
chrisst authored and modular-magician committed Oct 30, 2018
1 parent 41adcd5 commit 266691e
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ var schemaNodePool = map[string]*schema.Schema{
Optional: true,
Computed: true,
ForceNew: true,
Deprecated: "Use the random provider instead. See migration instructions at " +
Removed: "Use the random provider instead. See migration instructions at " +
"https://github.com/terraform-providers/terraform-provider-google/issues/1054#issuecomment-377390209",
},

Expand Down Expand Up @@ -447,12 +447,7 @@ func resourceContainerNodePoolStateImporter(d *schema.ResourceData, meta interfa
func expandNodePool(d *schema.ResourceData, prefix string) (*containerBeta.NodePool, error) {
var name string
if v, ok := d.GetOk(prefix + "name"); ok {
if _, ok := d.GetOk(prefix + "name_prefix"); ok {
return nil, fmt.Errorf("Cannot specify both name and name_prefix for a node_pool")
}
name = v.(string)
} else if v, ok := d.GetOk(prefix + "name_prefix"); ok {
name = resource.PrefixedUniqueId(v.(string))
} else {
name = resource.UniqueId()
}
Expand Down Expand Up @@ -526,7 +521,6 @@ func flattenNodePool(d *schema.ResourceData, config *Config, np *containerBeta.N
}
nodePool := map[string]interface{}{
"name": np.Name,
"name_prefix": d.Get(prefix + "name_prefix"),
"initial_node_count": np.InitialNodeCount,
"node_count": size / len(np.InstanceGroupUrls),
"node_config": flattenNodeConfig(np.Config),
Expand Down Expand Up @@ -750,6 +744,5 @@ func nodePoolUpdate(d *schema.ResourceData, meta interface{}, nodePoolInfo *Node
}

func getNodePoolName(id string) string {
// name can be specified with name, name_prefix, or neither, so read it from the id.
return strings.Split(id, "/")[2]
}
68 changes: 0 additions & 68 deletions provider/terraform/tests/resource_container_cluster_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (

"strconv"

"regexp"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
Expand Down Expand Up @@ -1001,28 +999,6 @@ func TestAccContainerCluster_withNodePoolAutoscaling(t *testing.T) {
})
}

func TestAccContainerCluster_withNodePoolNamePrefix(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withNodePoolNamePrefix(),
},
{
ResourceName: "google_container_cluster.with_node_pool_name_prefix",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"node_pool.0.name_prefix"},
},
},
})
}

func TestAccContainerCluster_withNodePoolMultiple(t *testing.T) {
t.Parallel()

Expand All @@ -1044,22 +1020,6 @@ func TestAccContainerCluster_withNodePoolMultiple(t *testing.T) {
})
}

func TestAccContainerCluster_withNodePoolConflictingNameFields(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withNodePoolConflictingNameFields(),
ExpectError: regexp.MustCompile("Cannot specify both name and name_prefix for a node_pool"),
},
},
})
}

func TestAccContainerCluster_withNodePoolNodeConfig(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -2239,19 +2199,6 @@ resource "google_container_cluster" "with_node_pool" {
}`, cluster, np)
}

func testAccContainerCluster_withNodePoolNamePrefix() string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_node_pool_name_prefix" {
name = "tf-cluster-nodepool-test-%s"
zone = "us-central1-a"

node_pool {
name_prefix = "tf-np-test"
node_count = 2
}
}`, acctest.RandString(10))
}

func testAccContainerCluster_withNodePoolMultiple() string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_node_pool_multiple" {
Expand All @@ -2270,21 +2217,6 @@ resource "google_container_cluster" "with_node_pool_multiple" {
}`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
}

func testAccContainerCluster_withNodePoolConflictingNameFields() string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_node_pool_multiple" {
name = "tf-cluster-nodepool-test-%s"
zone = "us-central1-a"

node_pool {
# ERROR: name and name_prefix cannot be both specified
name = "tf-cluster-nodepool-test-%s"
name_prefix = "tf-cluster-nodepool-test-"
node_count = 1
}
}`, acctest.RandString(10), acctest.RandString(10))
}

func testAccContainerCluster_withNodePoolNodeConfig() string {
testId := acctest.RandString(10)
return fmt.Sprintf(`
Expand Down
39 changes: 0 additions & 39 deletions provider/terraform/tests/resource_container_node_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,6 @@ func TestAccContainerNodePool_maxPodsPerNode(t *testing.T) {
})
}

func TestAccContainerNodePool_namePrefix(t *testing.T) {
t.Parallel()

cluster := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerNodePoolDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccContainerNodePool_namePrefix(cluster, "tf-np-"),
},
resource.TestStep{
ResourceName: "google_container_node_pool.np",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name_prefix"},
},
},
})
}

func TestAccContainerNodePool_noName(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -604,22 +581,6 @@ resource "google_container_node_pool" "np" {
}`, cluster, np)
}

func testAccContainerNodePool_namePrefix(cluster, np string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "cluster" {
name = "%s"
zone = "us-central1-a"
initial_node_count = 3
}
resource "google_container_node_pool" "np" {
name_prefix = "%s"
zone = "us-central1-a"
cluster = "${google_container_cluster.cluster.name}"
initial_node_count = 2
}`, cluster, np)
}

func testAccContainerNodePool_noName(cluster string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "cluster" {
Expand Down

0 comments on commit 266691e

Please sign in to comment.