Skip to content

Commit

Permalink
Add :exclude_import to Terraform resource properties (#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilymye authored Mar 13, 2019
1 parent 468831e commit 78ca21b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion overrides/terraform/resource_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def self.attributes
:examples,

# TODO(alexstephen): Deprecate once all resources using autogen async.
:autogen_async
:autogen_async,

# Flag - if false, resource is not importable
:exclude_import
]
end

Expand All @@ -57,6 +60,7 @@ def validate
check :docs, type: Provider::Terraform::Docs, default: Provider::Terraform::Docs.new
check :import_format, type: Array, item_type: String, default: []
check :autogen_async, type: :boolean, default: false
check :exclude_import, type: :boolean, default: false
end

def apply(resource)
Expand Down
5 changes: 4 additions & 1 deletion templates/terraform/resource.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ func resource<%= resource_name -%>() *schema.Resource {
),
<% end -%>

<% unless object.exclude_import -%>
Importer: &schema.ResourceImporter{
State: resource<%= resource_name -%>Import,
},

<% end -%>

Timeouts: &schema.ResourceTimeout {
Create: schema.DefaultTimeout(<%= timeouts.insert_sec -%> * time.Second),
Expand Down Expand Up @@ -562,6 +563,7 @@ func resource<%= resource_name -%>Delete(d *schema.ResourceData, meta interface{
return nil
}

<% unless object.exclude_import -%>
func resource<%= resource_name -%>Import(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
<% if object.custom_code.custom_import -%>
<%= lines(compile(object.custom_code.custom_import)) -%>
Expand All @@ -582,6 +584,7 @@ func resource<%= resource_name -%>Import(d *schema.ResourceData, meta interface{
return []*schema.ResourceData{d}, nil
<% end -%>
}
<% end -%>

<% properties.reject(&:ignore_read).each do |prop| -%>
<%= lines(build_flatten_method(resource_name, prop), 1) -%>
Expand Down

0 comments on commit 78ca21b

Please sign in to comment.