Skip to content

Commit d4ac69c

Browse files
Added updating master_global_access_config in google_container_cluster (#6932) (#13383)
Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 96af27e commit d4ac69c

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

.changelog/6932.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
container: fixed a bug preventing updates to `master_global_access_config` in `google_container_cluster`
3+
```

google/resource_container_cluster.go

+20
Original file line numberDiff line numberDiff line change
@@ -2359,6 +2359,26 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
23592359
log.Printf("[INFO] GKE cluster %s's enable private endpoint has been updated to %v", d.Id(), enabled)
23602360
}
23612361

2362+
if d.HasChange("private_cluster_config") && d.HasChange("private_cluster_config.0.master_global_access_config") {
2363+
config := d.Get("private_cluster_config.0.master_global_access_config")
2364+
req := &container.UpdateClusterRequest{
2365+
Update: &container.ClusterUpdate{
2366+
DesiredPrivateClusterConfig: &container.PrivateClusterConfig{
2367+
MasterGlobalAccessConfig: expandPrivateClusterConfigMasterGlobalAccessConfig(config),
2368+
ForceSendFields: []string{"MasterGlobalAccessConfig"},
2369+
},
2370+
},
2371+
}
2372+
2373+
updateF := updateFunc(req, "updating master global access config")
2374+
// Call update serially.
2375+
if err := lockedCall(lockKey, updateF); err != nil {
2376+
return err
2377+
}
2378+
2379+
log.Printf("[INFO] GKE cluster %s's master global access config has been updated to %v", d.Id(), config)
2380+
}
2381+
23622382
if d.HasChange("binary_authorization") {
23632383
req := &container.UpdateClusterRequest{
23642384
Update: &container.ClusterUpdate{

google/resource_container_cluster_test.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ func TestAccContainerCluster_regionalWithNodeLocations(t *testing.T) {
812812
})
813813
}
814814

815-
func TestAccContainerCluster_withPrivateClusterConfig(t *testing.T) {
815+
func TestAccContainerCluster_withPrivateClusterConfigBasic(t *testing.T) {
816816
t.Parallel()
817817

818818
clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
@@ -824,7 +824,15 @@ func TestAccContainerCluster_withPrivateClusterConfig(t *testing.T) {
824824
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
825825
Steps: []resource.TestStep{
826826
{
827-
Config: testAccContainerCluster_withPrivateClusterConfig(containerNetName, clusterName),
827+
Config: testAccContainerCluster_withPrivateClusterConfig(containerNetName, clusterName, false),
828+
},
829+
{
830+
ResourceName: "google_container_cluster.with_private_cluster",
831+
ImportState: true,
832+
ImportStateVerify: true,
833+
},
834+
{
835+
Config: testAccContainerCluster_withPrivateClusterConfig(containerNetName, clusterName, true),
828836
},
829837
{
830838
ResourceName: "google_container_cluster.with_private_cluster",
@@ -5484,7 +5492,7 @@ resource "google_container_cluster" "with_private_cluster" {
54845492
`, containerNetName, clusterName, location, autopilotEnabled)
54855493
}
54865494

5487-
func testAccContainerCluster_withPrivateClusterConfig(containerNetName string, clusterName string) string {
5495+
func testAccContainerCluster_withPrivateClusterConfig(containerNetName string, clusterName string, masterGlobalAccessEnabled bool) string {
54885496
return fmt.Sprintf(`
54895497
resource "google_compute_network" "container_network" {
54905498
name = "%s"
@@ -5526,7 +5534,7 @@ resource "google_container_cluster" "with_private_cluster" {
55265534
enable_private_nodes = true
55275535
master_ipv4_cidr_block = "10.42.0.0/28"
55285536
master_global_access_config {
5529-
enabled = true
5537+
enabled = %t
55305538
}
55315539
}
55325540
master_authorized_networks_config {
@@ -5536,7 +5544,7 @@ resource "google_container_cluster" "with_private_cluster" {
55365544
services_secondary_range_name = google_compute_subnetwork.container_subnetwork.secondary_ip_range[1].range_name
55375545
}
55385546
}
5539-
`, containerNetName, clusterName)
5547+
`, containerNetName, clusterName, masterGlobalAccessEnabled)
55405548
}
55415549

55425550
func testAccContainerCluster_withShieldedNodes(clusterName string, enabled bool) string {

0 commit comments

Comments
 (0)