Skip to content

Commit

Permalink
Add default_if_empty to google_compute_router_nat defaults (#2946)
Browse files Browse the repository at this point in the history
Merged PR #2946.
  • Loading branch information
rileykarson authored and modular-magician committed Jan 9, 2020
1 parent 1b1fa73 commit 0b6ac1b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
2 changes: 1 addition & 1 deletion build/terraform-mapper
8 changes: 8 additions & 0 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,14 @@ overrides: !ruby/object:Overrides::ResourceOverrides
required: false
default_from_api: true
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.erb'
udpIdleTimeoutSec: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: 'templates/terraform/custom_flatten/default_if_empty.erb'
icmpIdleTimeoutSec: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: 'templates/terraform/custom_flatten/default_if_empty.erb'
tcpEstablishedIdleTimeoutSec: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: 'templates/terraform/custom_flatten/default_if_empty.erb'
tcpTransitoryIdleTimeoutSec: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: 'templates/terraform/custom_flatten/default_if_empty.erb'
custom_code: !ruby/object:Provider::Terraform::CustomCode
constants: 'templates/terraform/constants/router_nat.go.erb'
resource_definition: 'templates/terraform/resource_definition/router_nat.go.erb'
Expand Down
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 0b6ac1b

Please sign in to comment.