Skip to content

Commit

Permalink
Add integer case, handle non-string types
Browse files Browse the repository at this point in the history
  • Loading branch information
rileykarson committed Jan 9, 2020
1 parent 9c355b8 commit 0f90bdf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion templates/terraform/custom_flatten/default_if_empty.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
# limitations under the License.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData) interface{} {
if v == nil || v.(string) == "" {
if v == nil || isEmptyValue(reflect.ValueOf(v)) {
return <%= go_literal(property.default_value) -%>
}
<%- if property.is_a?(Api::Type::Integer) -%>
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
} // let terraform core handle it if we can't convert the string to an int.
}
<%- end %>
return v
}

0 comments on commit 0f90bdf

Please sign in to comment.