Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update isEmptyValue function #1822

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-beta/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-beta/resource_billing_budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func resourceBillingBudgetUpdate(d *schema.ResourceData, meta interface{}) error
budgetProp, err := expandBillingBudgetBudget(nil, d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("budget"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, budgetProp)) {
} else if !isEmptyValue(reflect.ValueOf(budgetProp)) {
obj["budget"] = budgetProp
}

Expand Down
2 changes: 1 addition & 1 deletion google-beta/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-beta/resource_compute_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,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
}
customRequestHeadersProp, err := expandComputeBackendServiceCustomRequestHeaders(d.Get("custom_request_headers"), d, config)
Expand Down
2 changes: 1 addition & 1 deletion google-beta/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-beta/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-beta/resource_compute_region_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,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-beta/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