Skip to content

Commit c9dc932

Browse files
megan07modular-magician
authored andcommitted
allow master authorized networks config to be removed
Signed-off-by: Modular Magician <[email protected]>
1 parent b072474 commit c9dc932

3 files changed

+26
-5
lines changed

google/resource_container_cluster.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,9 @@ func expandMasterAuth(configured interface{}) *containerBeta.MasterAuth {
17711771
func expandMasterAuthorizedNetworksConfig(configured interface{}) *containerBeta.MasterAuthorizedNetworksConfig {
17721772
l := configured.([]interface{})
17731773
if len(l) == 0 {
1774-
return nil
1774+
return &containerBeta.MasterAuthorizedNetworksConfig{
1775+
Enabled: false,
1776+
}
17751777
}
17761778
result := &containerBeta.MasterAuthorizedNetworksConfig{
17771779
Enabled: true,
@@ -1990,7 +1992,7 @@ func flattenMasterAuth(ma *containerBeta.MasterAuth) []map[string]interface{} {
19901992
}
19911993

19921994
func flattenMasterAuthorizedNetworksConfig(c *containerBeta.MasterAuthorizedNetworksConfig) []map[string]interface{} {
1993-
if c == nil {
1995+
if c == nil || !c.Enabled {
19941996
return nil
19951997
}
19961998
result := make(map[string]interface{})

google/resource_container_cluster_test.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,15 @@ func TestAccContainerCluster_withMasterAuthorizedNetworksConfig(t *testing.T) {
390390
ImportState: true,
391391
ImportStateVerify: true,
392392
},
393+
{
394+
Config: testAccContainerCluster_removeMasterAuthorizedNetworksConfig(clusterName),
395+
},
396+
{
397+
ResourceName: "google_container_cluster.with_master_authorized_networks",
398+
ImportStateIdPrefix: "us-central1-a/",
399+
ImportState: true,
400+
ImportStateVerify: true,
401+
},
393402
},
394403
})
395404
}
@@ -1463,7 +1472,7 @@ func testAccContainerCluster_withMasterAuthorizedNetworksConfig(clusterName stri
14631472
return fmt.Sprintf(`
14641473
resource "google_container_cluster" "with_master_authorized_networks" {
14651474
name = "%s"
1466-
zone = "us-central1-a"
1475+
location = "us-central1-a"
14671476
initial_node_count = 1
14681477
14691478
master_authorized_networks_config {
@@ -1472,6 +1481,15 @@ resource "google_container_cluster" "with_master_authorized_networks" {
14721481
}`, clusterName, cidrBlocks)
14731482
}
14741483

1484+
func testAccContainerCluster_removeMasterAuthorizedNetworksConfig(clusterName string) string {
1485+
return fmt.Sprintf(`
1486+
resource "google_container_cluster" "with_master_authorized_networks" {
1487+
name = "%s"
1488+
location = "us-central1-a"
1489+
initial_node_count = 1
1490+
}`, clusterName)
1491+
}
1492+
14751493
func testAccContainerCluster_regional(clusterName string) string {
14761494
return fmt.Sprintf(`
14771495
resource "google_container_cluster" "regional" {

google/resource_service_networking_connection.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,12 @@ func resourceServiceNetworkingConnectionDelete(d *schema.ResourceData, meta inte
177177
obj["name"] = peering
178178
url := fmt.Sprintf("%s%s/removePeering", config.ComputeBasePath, serviceNetworkingNetworkName)
179179

180-
project, err := getProject(d, config)
180+
networkFieldValue, err := ParseNetworkFieldValue(network, d, config)
181181
if err != nil {
182-
return err
182+
return errwrap.Wrapf("Failed to retrieve network field value, err: {{err}}", err)
183183
}
184184

185+
project := networkFieldValue.Project
185186
res, err := sendRequestWithTimeout(config, "POST", project, url, obj, d.Timeout(schema.TimeoutUpdate))
186187
if err != nil {
187188
return handleNotFoundError(err, d, fmt.Sprintf("ServiceNetworkingConnection %q", d.Id()))

0 commit comments

Comments
 (0)