Skip to content

Commit

Permalink
update isEmptyValue function (#2907) (#5825)
Browse files Browse the repository at this point in the history
* update isEmptyValue function

* never mind, we still use 1.12 in the magician and teamcity

* revert bigtable change and fix flatten_object in update

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Mar 4, 2020
1 parent 8909a0a commit f366edd
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/2907.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
all: fixed issue where nested objects were getting sent as null values to GCP on create instead of being omitted from requests
```
2 changes: 1 addition & 1 deletion google/resource_big_query_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func resourceBigQueryDatasetUpdate(d *schema.ResourceData, meta interface{}) err
datasetReferenceProp, err := expandBigQueryDatasetDatasetReference(nil, d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("dataset_reference"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, datasetReferenceProp)) {
} else if !isEmptyValue(reflect.ValueOf(datasetReferenceProp)) {
obj["datasetReference"] = datasetReferenceProp
}
defaultTableExpirationMsProp, err := expandBigQueryDatasetDefaultTableExpirationMs(d.Get("default_table_expiration_ms"), d, config)
Expand Down
2 changes: 1 addition & 1 deletion google/resource_cloud_run_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ func resourceCloudRunServiceUpdate(d *schema.ResourceData, meta interface{}) err
specProp, err := expandCloudRunServiceSpec(nil, d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("spec"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, specProp)) {
} else if !isEmptyValue(reflect.ValueOf(specProp)) {
obj["spec"] = specProp
}
metadataProp, err := expandCloudRunServiceMetadata(d.Get("metadata"), d, config)
Expand Down
2 changes: 1 addition & 1 deletion google/resource_compute_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ func resourceComputeBackendServiceUpdate(d *schema.ResourceData, meta interface{
connectionDrainingProp, err := expandComputeBackendServiceConnectionDraining(nil, d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("connection_draining"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, connectionDrainingProp)) {
} else if !isEmptyValue(reflect.ValueOf(connectionDrainingProp)) {
obj["connectionDraining"] = connectionDrainingProp
}
fingerprintProp, err := expandComputeBackendServiceFingerprint(d.Get("fingerprint"), d, config)
Expand Down
2 changes: 1 addition & 1 deletion google/resource_compute_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func resourceComputeFirewallUpdate(d *schema.ResourceData, meta interface{}) err
logConfigProp, err := expandComputeFirewallLogConfig(nil, d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("log_config"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, logConfigProp)) {
} else if !isEmptyValue(reflect.ValueOf(logConfigProp)) {
obj["logConfig"] = logConfigProp
}
networkProp, err := expandComputeFirewallNetwork(d.Get("network"), d, config)
Expand Down
2 changes: 1 addition & 1 deletion google/resource_compute_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func resourceComputeNetworkUpdate(d *schema.ResourceData, meta interface{}) erro
routingConfigProp, err := expandComputeNetworkRoutingConfig(nil, d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("routing_config"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, routingConfigProp)) {
} else if !isEmptyValue(reflect.ValueOf(routingConfigProp)) {
obj["routingConfig"] = routingConfigProp
}

Expand Down
2 changes: 1 addition & 1 deletion google/resource_compute_region_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func resourceComputeRegionBackendServiceUpdate(d *schema.ResourceData, meta inte
connectionDrainingProp, err := expandComputeRegionBackendServiceConnectionDraining(nil, d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("connection_draining"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, connectionDrainingProp)) {
} else if !isEmptyValue(reflect.ValueOf(connectionDrainingProp)) {
obj["connectionDraining"] = connectionDrainingProp
}
descriptionProp, err := expandComputeRegionBackendServiceDescription(d.Get("description"), d, config)
Expand Down
4 changes: 4 additions & 0 deletions google/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
var DefaultRequestTimeout = 5 * time.Minute

func isEmptyValue(v reflect.Value) bool {
if !v.IsValid() {
return true
}

switch v.Kind() {
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
return v.Len() == 0
Expand Down

0 comments on commit f366edd

Please sign in to comment.