From 84531a3fd593bf28962c77dcc14597e3c91fe086 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 26 Apr 2016 09:39:39 -0700 Subject: [PATCH] helper/schema: sets Importable to true for resources that have importer --- helper/schema/provider.go | 11 ++++++++++- helper/schema/provider_test.go | 15 +++++++++++++++ terraform/resource_provider.go | 3 ++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/helper/schema/provider.go b/helper/schema/provider.go index aa35d32d0..0b2863db3 100644 --- a/helper/schema/provider.go +++ b/helper/schema/provider.go @@ -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, }) } diff --git a/helper/schema/provider_test.go b/helper/schema/provider_test.go index 5701520a2..a8122007a 100644 --- a/helper/schema/provider_test.go +++ b/helper/schema/provider_test.go @@ -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 { diff --git a/terraform/resource_provider.go b/terraform/resource_provider.go index ea23b031d..dd95e7bf8 100644 --- a/terraform/resource_provider.go +++ b/terraform/resource_provider.go @@ -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