Skip to content

Commit 4143031

Browse files
fix bug that causes updates on no-cp clusters without sa keys changing (#14980) (#10668)
[upstream:227a097e9ab6a46168a86785955e0e304615c1a8] Signed-off-by: Modular Magician <[email protected]>
1 parent 23a9a96 commit 4143031

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

.changelog/14980.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
container: fixed faulty diff for arrays on user_managed_keys_config that caused faulty cluster updates to be triggered.
3+
```

google-beta/services/container/resource_container_cluster.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6499,11 +6499,17 @@ func expandUserManagedKeysConfig(configured interface{}) *container.UserManagedK
64996499
}
65006500
if v, ok := config["service_account_signing_keys"]; ok {
65016501
sk := v.(*schema.Set)
6502-
umkc.ServiceAccountSigningKeys = tpgresource.ConvertStringSet(sk)
6502+
skss := tpgresource.ConvertStringSet(sk)
6503+
if len(skss) > 0 {
6504+
umkc.ServiceAccountSigningKeys = skss
6505+
}
65036506
}
65046507
if v, ok := config["service_account_verification_keys"]; ok {
65056508
vk := v.(*schema.Set)
6506-
umkc.ServiceAccountVerificationKeys = tpgresource.ConvertStringSet(vk)
6509+
vkss := tpgresource.ConvertStringSet(vk)
6510+
if len(vkss) > 0 {
6511+
umkc.ServiceAccountVerificationKeys = vkss
6512+
}
65076513
}
65086514
return umkc
65096515
}

google-beta/services/container/resource_container_cluster_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,39 @@ func TestAccContainerCluster_basic(t *testing.T) {
9595
})
9696
}
9797

98+
// This is to ensure that updates don't get trigerred with incorrect interpration of
99+
// nil serviceAccount keys as empty array.
100+
func TestAccContainerCluster_basic_noCpaUpgrade(t *testing.T) {
101+
t.Parallel()
102+
103+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
104+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
105+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
106+
acctest.VcrTest(t, resource.TestCase{
107+
PreCheck: func() { acctest.AccTestPreCheck(t) },
108+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
109+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
110+
Steps: []resource.TestStep{
111+
{
112+
Config: testAccContainerCluster_basic(clusterName, networkName, subnetworkName),
113+
Check: resource.ComposeAggregateTestCheckFunc(
114+
resource.TestCheckResourceAttrSet("google_container_cluster.primary", "services_ipv4_cidr"),
115+
resource.TestCheckResourceAttrSet("google_container_cluster.primary", "self_link"),
116+
resource.TestCheckResourceAttr("google_container_cluster.primary", "networking_mode", "VPC_NATIVE"),
117+
),
118+
},
119+
{
120+
Config: testAccContainerCluster_basic(clusterName, networkName, subnetworkName),
121+
ConfigPlanChecks: resource.ConfigPlanChecks{
122+
PreApply: []plancheck.PlanCheck{
123+
plancheck.ExpectResourceAction("google_container_cluster.primary", plancheck.ResourceActionNoop),
124+
},
125+
},
126+
},
127+
},
128+
})
129+
}
130+
98131
func TestAccContainerCluster_resourceManagerTags(t *testing.T) {
99132
t.Parallel()
100133

0 commit comments

Comments
 (0)