diff --git a/build/terraform b/build/terraform index 3035f1b0da3a..afff5faac6e6 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 3035f1b0da3a1b1a9e8bc6b48213bedce213f0e2 +Subproject commit afff5faac6e6bf72fe2f6717b9c7b3a4c3df6e2a diff --git a/build/terraform-beta b/build/terraform-beta index 454e8113d34b..e9c271b85662 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 454e8113d34bf72efdb5a3acafa868838f3643d2 +Subproject commit e9c271b856622d9f8a2c31d45ee1b7f8b81f358e diff --git a/provider/core.rb b/provider/core.rb index 882bba208f4a..671c5779b5ad 100644 --- a/provider/core.rb +++ b/provider/core.rb @@ -375,6 +375,19 @@ def properties_by_custom_update(properties) end end + # Takes a update_url and returns the list of custom updatable properties + # that can be updated at that URL. This allows flattened objects + # to determine which parent property in the API should be updated with + # the contents of the flattened object + def custom_update_properties_by_url(properties, update_url) + properties_by_custom_update(properties).select do |k, _| + k[:update_url] == update_url + end.first.last + # .first is to grab the element from the select which returns a list + # .last is because properties_by_custom_update returns a list of + # [{update_url}, [properties,...]] and we only need the 2nd part + end + def update_url(resource, url_part) return resource.self_link_url if url_part.nil? diff --git a/templates/terraform/resource.erb b/templates/terraform/resource.erb index 2d33996c6ce0..fcb1345a4970 100644 --- a/templates/terraform/resource.erb +++ b/templates/terraform/resource.erb @@ -277,7 +277,7 @@ func resource<%= resource_name -%>Read(d *schema.ResourceData, meta interface{}) return nil } -<% if updatable?(object, properties) -%> +<% if updatable?(object, object.root_properties) -%> func resource<%= resource_name -%>Update(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) @@ -287,8 +287,7 @@ func resource<%= resource_name -%>Update(d *schema.ResourceData, meta interface{ <% properties_by_custom_update(object.root_properties).each do |key, props| -%> if <%= props.map { |prop| "d.HasChange(\"#{prop.name.underscore}\")" }.join ' || ' -%> { obj := make(map[string]interface{}) -<% props.each do |prop| -%> -<% if update_body_properties.include? prop -%> +<% custom_update_properties_by_url(properties, key[:update_url]).each do |prop| -%> <% schemaPrefix = prop.flatten_object ? "nil" : "d.Get( \"#{prop.name.underscore}\" )" -%> <%= prop.api_name -%>Prop, err := expand<%= resource_name -%><%= titlelize_property(prop) -%>(<%= schemaPrefix -%>, d, config) if err != nil { @@ -317,10 +316,6 @@ if <%= props.map { |prop| "d.HasChange(\"#{prop.name.underscore}\")" }.join ' || <% end -%> obj["<%= prop.api_name -%>"] = <%= prop.api_name -%>Prop } -<% else # if update_body_properties.include? prop -%> - <%= prop.api_name -%>Prop := d.Get("<%= prop.name.underscore -%>") - obj["<%= prop.api_name -%>"] = <%= prop.api_name -%>Prop -<% end # if update_body_properties.include? prop -%> <% end # props.each -%> <% if object.mutex -%>