terraform: use InstanceInfo more appropriately, pass ID to ImportState

This commit is contained in:
Mitchell Hashimoto 2016-05-04 12:40:45 -07:00
parent f6a59734ef
commit d1a81379d0
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
4 changed files with 9 additions and 5 deletions

View File

@ -10,6 +10,7 @@ import (
type EvalImportState struct {
Provider *ResourceProvider
Info *InstanceInfo
Id string
Output *[]*InstanceState
}
@ -28,10 +29,10 @@ func (n *EvalImportState) Eval(ctx EvalContext) (interface{}, error) {
}
// Import!
state, err := provider.ImportState(n.Info)
state, err := provider.ImportState(n.Info, n.Id)
if err != nil {
return nil, fmt.Errorf(
"import %s (id: %s): %s", n.Info.Type, n.Info.Id, err)
"import %s (id: %s): %s", n.Info.HumanId(), n.Id, err)
}
if n.Output != nil {

View File

@ -96,7 +96,7 @@ type ResourceProvider interface {
// 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)
ImportState(*InstanceInfo, string) ([]*InstanceState, error)
}
// ResourceProviderCloser is an interface that providers that can close

View File

@ -58,6 +58,7 @@ type MockResourceProvider struct {
ImportStateCalled bool
ImportStateInfo *InstanceInfo
ImportStateID string
ImportStateReturn []*InstanceState
ImportStateReturnError error
ImportStateFn func(*InstanceInfo) ([]*InstanceState, error)
@ -182,12 +183,13 @@ func (p *MockResourceProvider) Resources() []ResourceType {
return p.ResourcesReturn
}
func (p *MockResourceProvider) ImportState(info *InstanceInfo) ([]*InstanceState, error) {
func (p *MockResourceProvider) ImportState(info *InstanceInfo, id string) ([]*InstanceState, error) {
p.Lock()
defer p.Unlock()
p.ImportStateCalled = true
p.ImportStateInfo = info
p.ImportStateID = id
if p.ImportStateFn != nil {
return p.ImportStateFn(info)
}

View File

@ -58,7 +58,7 @@ func (n *graphNodeImportState) Path() []string {
func (n *graphNodeImportState) EvalTree() EvalNode {
var provider ResourceProvider
info := &InstanceInfo{
Id: n.ID,
Id: fmt.Sprintf("%s.%s", n.Addr.Type, n.Addr.Name),
ModulePath: n.Path(),
Type: n.Addr.Type,
}
@ -76,6 +76,7 @@ func (n *graphNodeImportState) EvalTree() EvalNode {
&EvalImportState{
Provider: &provider,
Info: info,
Id: n.ID,
Output: &n.states,
},
},