Skip to content

Commit 227a097

Browse files
fix bug that causes updates on no-cp clusters without sa keys changing (#14980)
1 parent b175083 commit 227a097

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

mmv1/third_party/terraform/services/container/resource_container_cluster.go.tmpl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6547,11 +6547,17 @@ func expandUserManagedKeysConfig(configured interface{}) *container.UserManagedK
65476547
}
65486548
if v, ok := config["service_account_signing_keys"]; ok {
65496549
sk := v.(*schema.Set)
6550-
umkc.ServiceAccountSigningKeys = tpgresource.ConvertStringSet(sk)
6550+
skss := tpgresource.ConvertStringSet(sk)
6551+
if len(skss) > 0 {
6552+
umkc.ServiceAccountSigningKeys = skss
6553+
}
65516554
}
65526555
if v, ok := config["service_account_verification_keys"]; ok {
65536556
vk := v.(*schema.Set)
6554-
umkc.ServiceAccountVerificationKeys = tpgresource.ConvertStringSet(vk)
6557+
vkss := tpgresource.ConvertStringSet(vk)
6558+
if len(vkss) > 0 {
6559+
umkc.ServiceAccountVerificationKeys = vkss
6560+
}
65556561
}
65566562
return umkc
65576563
}

mmv1/third_party/terraform/services/container/resource_container_cluster_test.go.tmpl

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ func TestAccContainerCluster_basic(t *testing.T) {
6363
ImportStateVerifyIgnore: []string{"deletion_protection"},
6464
},
6565
{
66-
ResourceName: "google_container_cluster.primary",
66+
ResourceName: "google_container_cluster.primary",
6767
ImportStateId: fmt.Sprintf("%s/us-central1-a/%s", envvar.GetTestProjectFromEnv(), clusterName),
6868
ImportState: true,
6969
ImportStateVerify: true,
7070
ImportStateVerifyIgnore: []string{"deletion_protection"},
7171
},
7272
{
73-
ResourceName: "google_container_cluster.primary",
73+
ResourceName: "google_container_cluster.primary",
7474
ImportState: true,
7575
ImportStateVerify: true,
7676
ImportStateVerifyIgnore: []string{"deletion_protection"},
@@ -79,6 +79,39 @@ func TestAccContainerCluster_basic(t *testing.T) {
7979
})
8080
}
8181

82+
// This is to ensure that updates don't get trigerred with incorrect interpration of
83+
// nil serviceAccount keys as empty array.
84+
func TestAccContainerCluster_basic_noCpaUpgrade(t *testing.T) {
85+
t.Parallel()
86+
87+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
88+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
89+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
90+
acctest.VcrTest(t, resource.TestCase{
91+
PreCheck: func() { acctest.AccTestPreCheck(t) },
92+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
93+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
94+
Steps: []resource.TestStep{
95+
{
96+
Config: testAccContainerCluster_basic(clusterName, networkName, subnetworkName),
97+
Check: resource.ComposeAggregateTestCheckFunc(
98+
resource.TestCheckResourceAttrSet("google_container_cluster.primary", "services_ipv4_cidr"),
99+
resource.TestCheckResourceAttrSet("google_container_cluster.primary", "self_link"),
100+
resource.TestCheckResourceAttr("google_container_cluster.primary", "networking_mode", "VPC_NATIVE"),
101+
),
102+
},
103+
{
104+
Config: testAccContainerCluster_basic(clusterName, networkName, subnetworkName),
105+
ConfigPlanChecks: resource.ConfigPlanChecks{
106+
PreApply: []plancheck.PlanCheck{
107+
plancheck.ExpectResourceAction("google_container_cluster.primary", plancheck.ResourceActionNoop),
108+
},
109+
},
110+
},
111+
},
112+
})
113+
}
114+
82115
func TestAccContainerCluster_resourceManagerTags(t *testing.T) {
83116
t.Parallel()
84117

0 commit comments

Comments
 (0)