mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
terraform: add ImportState to the provider interface
This commit is contained in:
parent
9142ec400e
commit
531f609564
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user