From dd9fd0d75441273dd101eed6fe6cb03c5b5bf4dc Mon Sep 17 00:00:00 2001 From: Dana Hoffman Date: Wed, 4 Mar 2020 09:27:10 -0800 Subject: [PATCH] update isEmptyValue function (#2907) * update isEmptyValue function * never mind, we still use 1.12 in the magician and teamcity * revert bigtable change and fix flatten_object in update --- templates/terraform/resource.erb | 16 ++++++++++------ third_party/terraform/utils/transport.go | 4 ++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/templates/terraform/resource.erb b/templates/terraform/resource.erb index b74aee6f12a8..99403e234ff5 100644 --- a/templates/terraform/resource.erb +++ b/templates/terraform/resource.erb @@ -539,10 +539,12 @@ if <%= props.map { |prop| "d.HasChange(\"#{prop.name.underscore}\")" }.join ' || `NullFields` is a special case of `send_empty_value` where the empty value in question is go's literal nil. -%> -<% unless prop.send_empty_value -%> - } else if v, ok := d.GetOkExists("<%= prop.name.underscore -%>"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, <%= prop.api_name -%>Prop)) { -<% else -%> +<% if prop.send_empty_value -%> } else if v, ok := d.GetOkExists("<%= prop.name.underscore -%>"); ok || !reflect.DeepEqual(v, <%= prop.api_name -%>Prop) { +<% elsif prop.flatten_object -%> + } else if !isEmptyValue(reflect.ValueOf(<%= prop.api_name -%>Prop)) { +<% else -%> + } else if v, ok := d.GetOkExists("<%= prop.name.underscore -%>"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, <%= prop.api_name -%>Prop)) { <% end -%> obj["<%= prop.api_name -%>"] = <%= prop.api_name -%>Prop } @@ -611,10 +613,12 @@ if <%= props.map { |prop| "d.HasChange(\"#{prop.name.underscore}\")" }.join ' || <%= prop.api_name -%>Prop, err := expand<%= resource_name -%><%= titlelize_property(prop) -%>(<%= schemaPrefix -%>, d, config) if err != nil { return err -<% unless prop.send_empty_value -%> - } else if v, ok := d.GetOkExists("<%= prop.name.underscore -%>"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, <%= prop.api_name -%>Prop)) { -<% else -%> +<% if prop.send_empty_value -%> } else if v, ok := d.GetOkExists("<%= prop.name.underscore -%>"); ok || !reflect.DeepEqual(v, <%= prop.api_name -%>Prop) { +<% elsif prop.flatten_object -%> + } else if !isEmptyValue(reflect.ValueOf(<%= prop.api_name -%>Prop)) { +<% else -%> + } else if v, ok := d.GetOkExists("<%= prop.name.underscore -%>"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, <%= prop.api_name -%>Prop)) { <% end -%> obj["<%= prop.api_name -%>"] = <%= prop.api_name -%>Prop } diff --git a/third_party/terraform/utils/transport.go b/third_party/terraform/utils/transport.go index 40e0820c71bb..94cb0596b51a 100644 --- a/third_party/terraform/utils/transport.go +++ b/third_party/terraform/utils/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