From f366edde13c87d0499402feb97ac39a56e02b256 Mon Sep 17 00:00:00 2001 From: The Magician Date: Wed, 4 Mar 2020 09:31:25 -0800 Subject: [PATCH] update isEmptyValue function (#2907) (#5825) * 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 --- .changelog/2907.txt | 3 +++ google/resource_big_query_dataset.go | 2 +- google/resource_cloud_run_service.go | 2 +- google/resource_compute_backend_service.go | 2 +- google/resource_compute_firewall.go | 2 +- google/resource_compute_network.go | 2 +- google/resource_compute_region_backend_service.go | 2 +- google/transport.go | 4 ++++ 8 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 .changelog/2907.txt diff --git a/.changelog/2907.txt b/.changelog/2907.txt new file mode 100644 index 00000000000..d55091fe9ce --- /dev/null +++ b/.changelog/2907.txt @@ -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 +``` diff --git a/google/resource_big_query_dataset.go b/google/resource_big_query_dataset.go index d05b6bda174..c8e88fbeb14 100644 --- a/google/resource_big_query_dataset.go +++ b/google/resource_big_query_dataset.go @@ -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) diff --git a/google/resource_cloud_run_service.go b/google/resource_cloud_run_service.go index 264d1d55562..d75d8d57d1a 100644 --- a/google/resource_cloud_run_service.go +++ b/google/resource_cloud_run_service.go @@ -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) diff --git a/google/resource_compute_backend_service.go b/google/resource_compute_backend_service.go index f95edff4ab0..9c4e2c29a5a 100644 --- a/google/resource_compute_backend_service.go +++ b/google/resource_compute_backend_service.go @@ -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) diff --git a/google/resource_compute_firewall.go b/google/resource_compute_firewall.go index 862fa14fdaa..67743a82c38 100644 --- a/google/resource_compute_firewall.go +++ b/google/resource_compute_firewall.go @@ -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) diff --git a/google/resource_compute_network.go b/google/resource_compute_network.go index 555a06aeb6b..dfdf7e5ffe8 100644 --- a/google/resource_compute_network.go +++ b/google/resource_compute_network.go @@ -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 } diff --git a/google/resource_compute_region_backend_service.go b/google/resource_compute_region_backend_service.go index d801eed48d0..68acb77b185 100644 --- a/google/resource_compute_region_backend_service.go +++ b/google/resource_compute_region_backend_service.go @@ -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) diff --git a/google/transport.go b/google/transport.go index 40e0820c71b..94cb0596b51 100644 --- a/google/transport.go +++ b/google/transport.go @@ -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