plugin: implement new interface methods

This commit is contained in:
Mitchell Hashimoto 2016-05-04 10:58:49 -07:00
parent d6c059c43e
commit 498e23162d
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 40 additions and 2 deletions

View File

@ -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 {

View File

@ -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