Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added updating master_global_access_config in google_container_cluster #6932

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2523,7 +2523,27 @@ 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("binary_authorization") {
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{
DesiredBinaryAuthorization: expandBinaryAuthorization(d.Get("binary_authorization"), d.Get("enable_binary_authorization").(bool)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ func TestAccContainerCluster_withTpu(t *testing.T) {
}
<% end -%>

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 @@ -902,7 +902,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 @@ -6112,7 +6120,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 @@ -6154,7 +6162,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 @@ -6164,7 +6172,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