Merge pull request #8335 from hashicorp/b-import-index
terraform: import specific index works [GH-7691]
This commit is contained in:
commit
7c1d32719a
|
@ -40,6 +40,40 @@ func TestContextImport_basic(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestContextImport_countIndex(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
p.ImportStateReturn = []*InstanceState{
|
||||
&InstanceState{
|
||||
ID: "foo",
|
||||
Ephemeral: EphemeralState{Type: "aws_instance"},
|
||||
},
|
||||
}
|
||||
|
||||
state, err := ctx.Import(&ImportOpts{
|
||||
Targets: []*ImportTarget{
|
||||
&ImportTarget{
|
||||
Addr: "aws_instance.foo[0]",
|
||||
ID: "bar",
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(state.String())
|
||||
expected := strings.TrimSpace(testImportCountIndexStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad: \n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextImport_collision(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
|
@ -508,6 +542,12 @@ aws_instance.foo:
|
|||
provider = aws
|
||||
`
|
||||
|
||||
const testImportCountIndexStr = `
|
||||
aws_instance.foo.0:
|
||||
ID = foo
|
||||
provider = aws
|
||||
`
|
||||
|
||||
const testImportCollisionStr = `
|
||||
aws_instance.foo:
|
||||
ID = bar
|
||||
|
|
|
@ -204,7 +204,7 @@ func (n *graphNodeImportStateSub) EvalTree() EvalNode {
|
|||
key := &ResourceStateKey{
|
||||
Name: n.Target.Name,
|
||||
Type: info.Type,
|
||||
Index: -1,
|
||||
Index: n.Target.Index,
|
||||
}
|
||||
|
||||
// The eval sequence
|
||||
|
|
Loading…
Reference in New Issue