mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-03 08:42:39 +00:00
Fix crash when creating node pools with name_prefix (#531)
This commit is contained in:
parent
d60deb044a
commit
5b3bd3455c
|
@ -158,8 +158,8 @@ func resourceContainerNodePoolRead(d *schema.ResourceData, meta interface{}) err
|
|||
}
|
||||
|
||||
zone := d.Get("zone").(string)
|
||||
name := d.Get("name").(string)
|
||||
cluster := d.Get("cluster").(string)
|
||||
name := getNodePoolName(d.Id())
|
||||
|
||||
nodePool, err := config.clientContainer.Projects.Zones.Clusters.NodePools.Get(
|
||||
project, zone, cluster, name).Do()
|
||||
|
@ -233,13 +233,13 @@ func resourceContainerNodePoolExists(d *schema.ResourceData, meta interface{}) (
|
|||
}
|
||||
|
||||
zone := d.Get("zone").(string)
|
||||
name := d.Get("name").(string)
|
||||
cluster := d.Get("cluster").(string)
|
||||
name := getNodePoolName(d.Id())
|
||||
|
||||
_, err = config.clientContainer.Projects.Zones.Clusters.NodePools.Get(
|
||||
project, zone, cluster, name).Do()
|
||||
if err != nil {
|
||||
if err = handleNotFoundError(err, d, fmt.Sprintf("Container NodePool %s", d.Get("name").(string))); err == nil {
|
||||
if err = handleNotFoundError(err, d, fmt.Sprintf("Container NodePool %s", name)); err == nil {
|
||||
return false, nil
|
||||
}
|
||||
// There was some other error in reading the resource
|
||||
|
@ -417,3 +417,8 @@ func nodePoolUpdate(d *schema.ResourceData, meta interface{}, clusterName, prefi
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
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]
|
||||
}
|
||||
|
|
|
@ -32,6 +32,42 @@ func TestAccContainerNodePool_basic(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccContainerNodePool_namePrefix(t *testing.T) {
|
||||
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-"),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckContainerNodePoolMatches("google_container_node_pool.np"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccContainerNodePool_noName(t *testing.T) {
|
||||
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_noName(cluster),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckContainerNodePoolMatches("google_container_node_pool.np"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccContainerNodePool_withNodeConfig(t *testing.T) {
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -238,6 +274,37 @@ 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" {
|
||||
name = "%s"
|
||||
zone = "us-central1-a"
|
||||
initial_node_count = 3
|
||||
}
|
||||
|
||||
resource "google_container_node_pool" "np" {
|
||||
zone = "us-central1-a"
|
||||
cluster = "${google_container_cluster.cluster.name}"
|
||||
initial_node_count = 2
|
||||
}`, cluster)
|
||||
}
|
||||
|
||||
func testAccContainerNodePool_autoscaling(cluster, np string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_container_cluster" "cluster" {
|
||||
|
|
Loading…
Reference in New Issue
Block a user