Skip to content

Commit

Permalink
update isEmptyValue function (#2907)
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
  • Loading branch information
danawillow authored Mar 4, 2020
1 parent bb7197a commit dd9fd0d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 10 additions & 6 deletions templates/terraform/resource.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions third_party/terraform/utils/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 dd9fd0d

Please sign in to comment.