helper/schema: sets Importable to true for resources that have importer

This commit is contained in:
Mitchell Hashimoto 2016-04-26 09:39:39 -07:00
parent 19609bde0e
commit 84531a3fd5
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 27 additions and 2 deletions

View File

@ -197,8 +197,17 @@ func (p *Provider) Resources() []terraform.ResourceType {
result := make([]terraform.ResourceType, 0, len(keys))
for _, k := range keys {
resource := p.ResourcesMap[k]
// This isn't really possible (it'd fail InternalValidate), but
// we do it anyways to avoid a panic.
if resource == nil {
resource = &Resource{}
}
result = append(result, terraform.ResourceType{
Name: k,
Name: k,
Importable: resource.Importer != nil,
})
}

View File

@ -107,6 +107,21 @@ func TestProviderResources(t *testing.T) {
terraform.ResourceType{Name: "foo"},
},
},
{
P: &Provider{
ResourcesMap: map[string]*Resource{
"foo": nil,
"bar": &Resource{Importer: &ResourceImporter{}},
"baz": nil,
},
},
Result: []terraform.ResourceType{
terraform.ResourceType{Name: "bar", Importable: true},
terraform.ResourceType{Name: "baz"},
terraform.ResourceType{Name: "foo"},
},
},
}
for i, tc := range cases {

View File

@ -79,7 +79,8 @@ type ResourceProviderCloser interface {
// ResourceType is a type of resource that a resource provider can manage.
type ResourceType struct {
Name string
Name string // Name of the resource, example "instance" (no provider prefix)
Importable bool // Whether this resource supports importing
}
// ResourceProviderFactory is a function type that creates a new instance