Skip to content

Commit

Permalink
Change default id format from {{name}} to self_link_uri (#2461)
Browse files Browse the repository at this point in the history
* Change default id format from {{name}} to self_link_uri
  • Loading branch information
slevenick authored and rileykarson committed Nov 13, 2019
1 parent aec98d6 commit 99311c6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion overrides/terraform/resource_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def validate
@examples ||= []

check :legacy_name, type: String
check :id_format, type: String, default: '{{name}}'
check :id_format, type: String
check :examples, item_type: Provider::Terraform::Examples, type: Array, default: []
check :virtual_fields,
item_type: Provider::Terraform::VirtualFields,
Expand Down
1 change: 1 addition & 0 deletions products/resourcemanager/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
autogen_async: true
exclude: true
Lien: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "{{name}}"
import_format: ["{{parent}}/{{name}}"]
examples:
- !ruby/object:Provider::Terraform::Examples
Expand Down
7 changes: 7 additions & 0 deletions provider/terraform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,12 @@ def build_object_data(object, output_folder, version)
def extract_identifiers(url)
url.scan(/\{\{(\w+)\}\}/).flatten
end

# Returns the id format of an object, or self_link_uri if none is explicitly defined
# We prefer the long name of a resource as the id so that users can reference
# resources in a standard way, and most APIs accept short name, long name or self_link
def id_format(object)
object.id_format || object.self_link_uri
end
end
end
4 changes: 2 additions & 2 deletions templates/terraform/resource.erb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{
}

// Store the ID now
id, err := replaceVars(d, config, "<%= object.id_format -%>")
id, err := replaceVars(d, config, "<%= id_format(object) -%>")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
Expand Down Expand Up @@ -630,7 +630,7 @@ func resource<%= resource_name -%>Import(d *schema.ResourceData, meta interface{
}

// Replace import id for the resource id
id, err := replaceVars(d, config, "<%= object.id_format -%>")
id, err := replaceVars(d, config, "<%= id_format(object) -%>")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
Expand Down

0 comments on commit 99311c6

Please sign in to comment.