terraform: add ImportState to the provider interface

This commit is contained in:
Mitchell Hashimoto 2016-04-26 10:56:41 -07:00
parent 9142ec400e
commit 531f609564
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 34 additions and 0 deletions

View File

@ -82,6 +82,21 @@ type ResourceProvider interface {
* Functions related to importing
*********************************************************************/
// ImportState requests that the given resource be imported.
//
// The returned InstanceState only requires ID be set. Importing
// will always call Refresh after the state to complete it.
//
// IMPORTANT: InstanceState doesn't have the resource type attached
// to it. A type must be specified on the state via the Ephemeral
// field on the state.
//
// This function can return multiple states. Normally, an import
// will map 1:1 to a physical resource. However, some resources map
// to multiple. For example, an AWS security group may contain many rules.
// Each rule is represented by a separate resource in Terraform,
// therefore multiple states are returned.
ImportState(*InstanceInfo) ([]*InstanceState, error)
}
// ResourceProviderCloser is an interface that providers that can close

View File

@ -55,6 +55,12 @@ type MockResourceProvider struct {
ValidateResourceConfig *ResourceConfig
ValidateResourceReturnWarns []string
ValidateResourceReturnErrors []error
ImportStateCalled bool
ImportStateInfo *InstanceInfo
ImportStateReturn []*InstanceState
ImportStateReturnError error
ImportStateFn func(*InstanceInfo) ([]*InstanceState, error)
}
func (p *MockResourceProvider) Close() error {
@ -175,3 +181,16 @@ func (p *MockResourceProvider) Resources() []ResourceType {
p.ResourcesCalled = true
return p.ResourcesReturn
}
func (p *MockResourceProvider) ImportState(info *InstanceInfo) ([]*InstanceState, error) {
p.Lock()
defer p.Unlock()
p.ImportStateCalled = true
p.ImportStateInfo = info
if p.ImportStateFn != nil {
return p.ImportStateFn(info)
}
return p.ImportStateReturn, p.ImportStateReturnError
}