mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-07 03:01:06 +00:00
Fix crash when updating container cluster resource labels.
We had a bad type coercion in the code to update container cluster resource labels. This fixes the coercion. We didn't notice this because there was no test exercising the update code path. I've added the test, which reproduced the panic before this PR was applied and passes successfully now that the coercion is fixed.
This commit is contained in:
parent
687f8d0857
commit
0435b1f387
@ -1145,7 +1145,11 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("resource_labels") {
|
if d.HasChange("resource_labels") {
|
||||||
resourceLabels := d.Get("resource_labels").(map[string]string)
|
resourceLabelsI := d.Get("resource_labels").(map[string]interface{})
|
||||||
|
resourceLabels := make(map[string]string, len(resourceLabelsI))
|
||||||
|
for k, v := range resourceLabelsI {
|
||||||
|
resourceLabels[k] = v.(string)
|
||||||
|
}
|
||||||
|
|
||||||
req := &containerBeta.SetLabelsRequest{
|
req := &containerBeta.SetLabelsRequest{
|
||||||
ResourceLabels: resourceLabels,
|
ResourceLabels: resourceLabels,
|
||||||
|
@ -1183,6 +1183,32 @@ func TestAccContainerCluster_withResourceLabels(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccContainerCluster_withResourceLabelsUpdate(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccContainerCluster_withoutResourceLabels(clusterName),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Config: testAccContainerCluster_withResourceLabels(clusterName),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ResourceName: "google_container_cluster.with_resource_labels",
|
||||||
|
ImportStateIdPrefix: "us-central1-a/",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckContainerClusterDestroy(s *terraform.State) error {
|
func testAccCheckContainerClusterDestroy(s *terraform.State) error {
|
||||||
config := testAccProvider.Meta().(*Config)
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
@ -2254,6 +2280,16 @@ resource "google_container_cluster" "shared_vpc_cluster" {
|
|||||||
}`, projectName, org, billingId, projectName, org, billingId, acctest.RandString(10), acctest.RandString(10), name)
|
}`, projectName, org, billingId, projectName, org, billingId, acctest.RandString(10), acctest.RandString(10), name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccContainerCluster_withoutResourceLabels(clusterName string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "google_container_cluster" "with_resource_labels" {
|
||||||
|
name = "%s"
|
||||||
|
zone = "us-central1-a"
|
||||||
|
initial_node_count = 1
|
||||||
|
}
|
||||||
|
`, clusterName)
|
||||||
|
}
|
||||||
|
|
||||||
func testAccContainerCluster_withResourceLabels(clusterName string) string {
|
func testAccContainerCluster_withResourceLabels(clusterName string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_container_cluster" "with_resource_labels" {
|
resource "google_container_cluster" "with_resource_labels" {
|
||||||
|
Loading…
Reference in New Issue
Block a user