From 498e23162d36537a48c6fac631cfcd3f4dcf7eef Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 4 May 2016 10:58:49 -0700 Subject: [PATCH] plugin: implement new interface methods --- plugin/resource_provider.go | 38 ++++++++++++++++++++++++++++++++ plugin/resource_provider_test.go | 4 ++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/plugin/resource_provider.go b/plugin/resource_provider.go index 712e79c86..62362ce80 100644 --- a/plugin/resource_provider.go +++ b/plugin/resource_provider.go @@ -176,6 +176,24 @@ func (p *ResourceProvider) Refresh( return resp.State, err } +func (p *ResourceProvider) ImportState( + info *terraform.InstanceInfo) ([]*terraform.InstanceState, error) { + var resp ResourceProviderImportStateResponse + args := &ResourceProviderImportStateArgs{ + Info: info, + } + + err := p.Client.Call("Plugin.ImportState", args, &resp) + if err != nil { + return nil, err + } + if resp.Error != nil { + err = resp.Error + } + + return resp.State, err +} + func (p *ResourceProvider) Resources() []terraform.ResourceType { var result []terraform.ResourceType @@ -245,6 +263,15 @@ type ResourceProviderRefreshResponse struct { Error *plugin.BasicError } +type ResourceProviderImportStateArgs struct { + Info *terraform.InstanceInfo +} + +type ResourceProviderImportStateResponse struct { + State []*terraform.InstanceState + Error *plugin.BasicError +} + type ResourceProviderValidateArgs struct { Config *terraform.ResourceConfig } @@ -361,6 +388,17 @@ func (s *ResourceProviderServer) Refresh( return nil } +func (s *ResourceProviderServer) ImportState( + args *ResourceProviderImportStateArgs, + result *ResourceProviderImportStateResponse) error { + states, err := s.Provider.ImportState(args.Info) + *result = ResourceProviderImportStateResponse{ + State: states, + Error: plugin.NewBasicError(err), + } + return nil +} + func (s *ResourceProviderServer) Resources( nothing interface{}, result *[]terraform.ResourceType) error { diff --git a/plugin/resource_provider_test.go b/plugin/resource_provider_test.go index 944041d3e..de4efdbad 100644 --- a/plugin/resource_provider_test.go +++ b/plugin/resource_provider_test.go @@ -334,8 +334,8 @@ func TestResourceProvider_resources(t *testing.T) { provider := raw.(terraform.ResourceProvider) expected := []terraform.ResourceType{ - {"foo"}, - {"bar"}, + terraform.ResourceType{Name: "foo"}, + terraform.ResourceType{Name: "bar", Importable: true}, } p.ResourcesReturn = expected