Skip to content

Commit

Permalink
Add support for one-field-at-a-time update to Subnetwork (#4688)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored and rileykarson committed Oct 16, 2019
1 parent 33af39f commit d14a228
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 6 deletions.
2 changes: 2 additions & 0 deletions google/resource_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error {

if d.HasChange("label_fingerprint") || d.HasChange("labels") {
obj := make(map[string]interface{})

labelFingerprintProp, err := expandComputeDiskLabelFingerprint(d.Get("label_fingerprint"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -711,6 +712,7 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error {
}
if d.HasChange("size") {
obj := make(map[string]interface{})

sizeGbProp, err := expandComputeDiskSize(d.Get("size"), d, config)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions google/resource_compute_forwarding_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ func resourceComputeForwardingRuleUpdate(d *schema.ResourceData, meta interface{

if d.HasChange("target") {
obj := make(map[string]interface{})

targetProp, err := expandComputeForwardingRuleTarget(d.Get("target"), d, config)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions google/resource_compute_global_forwarding_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ func resourceComputeGlobalForwardingRuleUpdate(d *schema.ResourceData, meta inte

if d.HasChange("target") {
obj := make(map[string]interface{})

targetProp, err := expandComputeGlobalForwardingRuleTarget(d.Get("target"), d, config)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions google/resource_compute_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ func resourceComputeImageUpdate(d *schema.ResourceData, meta interface{}) error

if d.HasChange("labels") || d.HasChange("label_fingerprint") {
obj := make(map[string]interface{})

labelsProp, err := expandComputeImageLabels(d.Get("labels"), d, config)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions google/resource_compute_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ func resourceComputeNetworkUpdate(d *schema.ResourceData, meta interface{}) erro

if d.HasChange("routing_mode") {
obj := make(map[string]interface{})

routingConfigProp, err := expandComputeNetworkRoutingConfig(nil, d, config)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions google/resource_compute_node_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func resourceComputeNodeGroupUpdate(d *schema.ResourceData, meta interface{}) er

if d.HasChange("node_template") {
obj := make(map[string]interface{})

nodeTemplateProp, err := expandComputeNodeGroupNodeTemplate(d.Get("node_template"), d, config)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions google/resource_compute_region_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ func resourceComputeRegionDiskUpdate(d *schema.ResourceData, meta interface{}) e

if d.HasChange("label_fingerprint") || d.HasChange("labels") {
obj := make(map[string]interface{})

labelFingerprintProp, err := expandComputeRegionDiskLabelFingerprint(d.Get("label_fingerprint"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -455,6 +456,7 @@ func resourceComputeRegionDiskUpdate(d *schema.ResourceData, meta interface{}) e
}
if d.HasChange("size") {
obj := make(map[string]interface{})

sizeGbProp, err := expandComputeRegionDiskSize(d.Get("size"), d, config)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions google/resource_compute_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ func resourceComputeSnapshotUpdate(d *schema.ResourceData, meta interface{}) err

if d.HasChange("labels") || d.HasChange("label_fingerprint") {
obj := make(map[string]interface{})

labelsProp, err := expandComputeSnapshotLabels(d.Get("labels"), d, config)
if err != nil {
return err
Expand Down
68 changes: 62 additions & 6 deletions google/resource_compute_subnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) e

if d.HasChange("ip_cidr_range") {
obj := make(map[string]interface{})

ipCidrRangeProp, err := expandComputeSubnetworkIpCidrRange(d.Get("ip_cidr_range"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -410,20 +411,76 @@ func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) e

d.SetPartial("ip_cidr_range")
}
if d.HasChange("enable_flow_logs") || d.HasChange("fingerprint") || d.HasChange("secondary_ip_range") {
if d.HasChange("enable_flow_logs") {
obj := make(map[string]interface{})

getUrl, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/subnetworks/{{name}}")
if err != nil {
return err
}

project, err := getProject(d, config)
if err != nil {
return err
}
getRes, err := sendRequest(config, "GET", project, getUrl, nil)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("ComputeSubnetwork %q", d.Id()))
}

obj["fingerprint"] = getRes["fingerprint"]

enableFlowLogsProp, err := expandComputeSubnetworkEnableFlowLogs(d.Get("enable_flow_logs"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("enable_flow_logs"); ok || !reflect.DeepEqual(v, enableFlowLogsProp) {
obj["enableFlowLogs"] = enableFlowLogsProp
}
fingerprintProp, err := expandComputeSubnetworkFingerprint(d.Get("fingerprint"), d, config)

url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/subnetworks/{{name}}")
if err != nil {
return err
} else if v, ok := d.GetOkExists("fingerprint"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, fingerprintProp)) {
obj["fingerprint"] = fingerprintProp
}
res, err := sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate))
if err != nil {
return fmt.Errorf("Error updating Subnetwork %q: %s", d.Id(), err)
}

op := &compute.Operation{}
err = Convert(res, op)
if err != nil {
return err
}

err = computeOperationWaitTime(
config.clientCompute, op, project, "Updating Subnetwork",
int(d.Timeout(schema.TimeoutUpdate).Minutes()))

if err != nil {
return err
}

d.SetPartial("enable_flow_logs")
}
if d.HasChange("secondary_ip_range") {
obj := make(map[string]interface{})

getUrl, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/subnetworks/{{name}}")
if err != nil {
return err
}

project, err := getProject(d, config)
if err != nil {
return err
}
getRes, err := sendRequest(config, "GET", project, getUrl, nil)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("ComputeSubnetwork %q", d.Id()))
}

obj["fingerprint"] = getRes["fingerprint"]

secondaryIpRangesProp, err := expandComputeSubnetworkSecondaryIpRange(d.Get("secondary_ip_range"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -454,12 +511,11 @@ func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) e
return err
}

d.SetPartial("enable_flow_logs")
d.SetPartial("fingerprint")
d.SetPartial("secondary_ip_range")
}
if d.HasChange("private_ip_google_access") {
obj := make(map[string]interface{})

privateIpGoogleAccessProp, err := expandComputeSubnetworkPrivateIpGoogleAccess(d.Get("private_ip_google_access"), d, config)
if err != nil {
return err
Expand Down
35 changes: 35 additions & 0 deletions google/resource_compute_subnetwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ func TestAccComputeSubnetwork_update(t *testing.T) {
"google_compute_subnetwork.network-with-private-google-access", &subnetwork),
),
},
{
// Add a secondary range and enable flow logs at once
Config: testAccComputeSubnetwork_update3(cnName, "10.2.0.0/24", subnetworkName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeSubnetworkExists(
"google_compute_subnetwork.network-with-private-google-access", &subnetwork),
),
},
{
ResourceName: "google_compute_subnetwork.network-with-private-google-access",
ImportState: true,
ImportStateVerify: true,
},
},
})

Expand Down Expand Up @@ -356,6 +369,28 @@ resource "google_compute_subnetwork" "network-with-private-google-access" {
`, cnName, subnetworkName, cidrRange)
}

func testAccComputeSubnetwork_update3(cnName, cidrRange, subnetworkName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "custom-test" {
name = "%s"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "network-with-private-google-access" {
name = "%s"
ip_cidr_range = "%s"
region = "us-central1"
network = "${google_compute_network.custom-test.self_link}"
enable_flow_logs = true
secondary_ip_range {
range_name = "tf-test-secondary-range-update"
ip_cidr_range = "192.168.10.0/24"
}
}
`, cnName, subnetworkName, cidrRange)
}

func testAccComputeSubnetwork_secondaryIpRanges_update1(cnName, subnetworkName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "custom-test" {
Expand Down
1 change: 1 addition & 0 deletions google/resource_compute_target_http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func resourceComputeTargetHttpProxyUpdate(d *schema.ResourceData, meta interface

if d.HasChange("url_map") {
obj := make(map[string]interface{})

urlMapProp, err := expandComputeTargetHttpProxyUrlMap(d.Get("url_map"), d, config)
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions google/resource_compute_target_https_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac

if d.HasChange("quic_override") {
obj := make(map[string]interface{})

quicOverrideProp, err := expandComputeTargetHttpsProxyQuicOverride(d.Get("quic_override"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -282,6 +283,7 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac
}
if d.HasChange("ssl_certificates") {
obj := make(map[string]interface{})

sslCertificatesProp, err := expandComputeTargetHttpsProxySslCertificates(d.Get("ssl_certificates"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -316,6 +318,7 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac
}
if d.HasChange("ssl_policy") {
obj := make(map[string]interface{})

sslPolicyProp, err := expandComputeTargetHttpsProxySslPolicy(d.Get("ssl_policy"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -350,6 +353,7 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac
}
if d.HasChange("url_map") {
obj := make(map[string]interface{})

urlMapProp, err := expandComputeTargetHttpsProxyUrlMap(d.Get("url_map"), d, config)
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions google/resource_compute_target_ssl_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ func resourceComputeTargetSslProxyUpdate(d *schema.ResourceData, meta interface{

if d.HasChange("proxy_header") {
obj := make(map[string]interface{})

proxyHeaderProp, err := expandComputeTargetSslProxyProxyHeader(d.Get("proxy_header"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -283,6 +284,7 @@ func resourceComputeTargetSslProxyUpdate(d *schema.ResourceData, meta interface{
}
if d.HasChange("backend_service") {
obj := make(map[string]interface{})

serviceProp, err := expandComputeTargetSslProxyBackendService(d.Get("backend_service"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -317,6 +319,7 @@ func resourceComputeTargetSslProxyUpdate(d *schema.ResourceData, meta interface{
}
if d.HasChange("ssl_certificates") {
obj := make(map[string]interface{})

sslCertificatesProp, err := expandComputeTargetSslProxySslCertificates(d.Get("ssl_certificates"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -351,6 +354,7 @@ func resourceComputeTargetSslProxyUpdate(d *schema.ResourceData, meta interface{
}
if d.HasChange("ssl_policy") {
obj := make(map[string]interface{})

sslPolicyProp, err := expandComputeTargetSslProxySslPolicy(d.Get("ssl_policy"), d, config)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions google/resource_compute_target_tcp_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func resourceComputeTargetTcpProxyUpdate(d *schema.ResourceData, meta interface{

if d.HasChange("proxy_header") {
obj := make(map[string]interface{})

proxyHeaderProp, err := expandComputeTargetTcpProxyProxyHeader(d.Get("proxy_header"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -251,6 +252,7 @@ func resourceComputeTargetTcpProxyUpdate(d *schema.ResourceData, meta interface{
}
if d.HasChange("backend_service") {
obj := make(map[string]interface{})

serviceProp, err := expandComputeTargetTcpProxyBackendService(d.Get("backend_service"), d, config)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions google/resource_dns_managed_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ func resourceDNSManagedZoneUpdate(d *schema.ResourceData, meta interface{}) erro

if d.HasChange("description") || d.HasChange("labels") || d.HasChange("private_visibility_config") {
obj := make(map[string]interface{})

descriptionProp, err := expandDNSManagedZoneDescription(d.Get("description"), d, config)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions google/resource_tpu_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ func resourceTPUNodeUpdate(d *schema.ResourceData, meta interface{}) error {

if d.HasChange("tensorflow_version") {
obj := make(map[string]interface{})

tensorflowVersionProp, err := expandTPUNodeTensorflowVersion(d.Get("tensorflow_version"), d, config)
if err != nil {
return err
Expand Down

0 comments on commit d14a228

Please sign in to comment.