Skip to content

Commit

Permalink
allow master authorized networks config to be removed
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
megan07 authored and modular-magician committed Sep 16, 2019
1 parent b072474 commit c9dc932
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
6 changes: 4 additions & 2 deletions google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,9 @@ func expandMasterAuth(configured interface{}) *containerBeta.MasterAuth {
func expandMasterAuthorizedNetworksConfig(configured interface{}) *containerBeta.MasterAuthorizedNetworksConfig {
l := configured.([]interface{})
if len(l) == 0 {
return nil
return &containerBeta.MasterAuthorizedNetworksConfig{
Enabled: false,
}
}
result := &containerBeta.MasterAuthorizedNetworksConfig{
Enabled: true,
Expand Down Expand Up @@ -1990,7 +1992,7 @@ func flattenMasterAuth(ma *containerBeta.MasterAuth) []map[string]interface{} {
}

func flattenMasterAuthorizedNetworksConfig(c *containerBeta.MasterAuthorizedNetworksConfig) []map[string]interface{} {
if c == nil {
if c == nil || !c.Enabled {
return nil
}
result := make(map[string]interface{})
Expand Down
20 changes: 19 additions & 1 deletion google/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,15 @@ func TestAccContainerCluster_withMasterAuthorizedNetworksConfig(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContainerCluster_removeMasterAuthorizedNetworksConfig(clusterName),
},
{
ResourceName: "google_container_cluster.with_master_authorized_networks",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -1463,7 +1472,7 @@ func testAccContainerCluster_withMasterAuthorizedNetworksConfig(clusterName stri
return fmt.Sprintf(`
resource "google_container_cluster" "with_master_authorized_networks" {
name = "%s"
zone = "us-central1-a"
location = "us-central1-a"
initial_node_count = 1
master_authorized_networks_config {
Expand All @@ -1472,6 +1481,15 @@ resource "google_container_cluster" "with_master_authorized_networks" {
}`, clusterName, cidrBlocks)
}

func testAccContainerCluster_removeMasterAuthorizedNetworksConfig(clusterName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_master_authorized_networks" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
}`, clusterName)
}

func testAccContainerCluster_regional(clusterName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "regional" {
Expand Down
5 changes: 3 additions & 2 deletions google/resource_service_networking_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ func resourceServiceNetworkingConnectionDelete(d *schema.ResourceData, meta inte
obj["name"] = peering
url := fmt.Sprintf("%s%s/removePeering", config.ComputeBasePath, serviceNetworkingNetworkName)

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

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

0 comments on commit c9dc932

Please sign in to comment.