Skip to content

Commit

Permalink
Added updating master_global_access_config in google_container_cluster (
Browse files Browse the repository at this point in the history
#6932) (#13383)

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Jan 4, 2023
1 parent 96af27e commit d4ac69c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/6932.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
container: fixed a bug preventing updates to `master_global_access_config` in `google_container_cluster`
```
20 changes: 20 additions & 0 deletions google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2359,6 +2359,26 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
log.Printf("[INFO] GKE cluster %s's enable private endpoint has been updated to %v", d.Id(), enabled)
}

if d.HasChange("private_cluster_config") && d.HasChange("private_cluster_config.0.master_global_access_config") {
config := d.Get("private_cluster_config.0.master_global_access_config")
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
DesiredPrivateClusterConfig: &container.PrivateClusterConfig{
MasterGlobalAccessConfig: expandPrivateClusterConfigMasterGlobalAccessConfig(config),
ForceSendFields: []string{"MasterGlobalAccessConfig"},
},
},
}

updateF := updateFunc(req, "updating master global access config")
// Call update serially.
if err := lockedCall(lockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] GKE cluster %s's master global access config has been updated to %v", d.Id(), config)
}

if d.HasChange("binary_authorization") {
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
Expand Down
18 changes: 13 additions & 5 deletions google/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ func TestAccContainerCluster_regionalWithNodeLocations(t *testing.T) {
})
}

func TestAccContainerCluster_withPrivateClusterConfig(t *testing.T) {
func TestAccContainerCluster_withPrivateClusterConfigBasic(t *testing.T) {
t.Parallel()

clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
Expand All @@ -824,7 +824,15 @@ func TestAccContainerCluster_withPrivateClusterConfig(t *testing.T) {
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withPrivateClusterConfig(containerNetName, clusterName),
Config: testAccContainerCluster_withPrivateClusterConfig(containerNetName, clusterName, false),
},
{
ResourceName: "google_container_cluster.with_private_cluster",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContainerCluster_withPrivateClusterConfig(containerNetName, clusterName, true),
},
{
ResourceName: "google_container_cluster.with_private_cluster",
Expand Down Expand Up @@ -5484,7 +5492,7 @@ resource "google_container_cluster" "with_private_cluster" {
`, containerNetName, clusterName, location, autopilotEnabled)
}

func testAccContainerCluster_withPrivateClusterConfig(containerNetName string, clusterName string) string {
func testAccContainerCluster_withPrivateClusterConfig(containerNetName string, clusterName string, masterGlobalAccessEnabled bool) string {
return fmt.Sprintf(`
resource "google_compute_network" "container_network" {
name = "%s"
Expand Down Expand Up @@ -5526,7 +5534,7 @@ resource "google_container_cluster" "with_private_cluster" {
enable_private_nodes = true
master_ipv4_cidr_block = "10.42.0.0/28"
master_global_access_config {
enabled = true
enabled = %t
}
}
master_authorized_networks_config {
Expand All @@ -5536,7 +5544,7 @@ resource "google_container_cluster" "with_private_cluster" {
services_secondary_range_name = google_compute_subnetwork.container_subnetwork.secondary_ip_range[1].range_name
}
}
`, containerNetName, clusterName)
`, containerNetName, clusterName, masterGlobalAccessEnabled)
}

func testAccContainerCluster_withShieldedNodes(clusterName string, enabled bool) string {
Expand Down

0 comments on commit d4ac69c

Please sign in to comment.