Merge pull request #8335 from hashicorp/b-import-index

terraform: import specific index works [GH-7691]
This commit is contained in:
Mitchell Hashimoto 2016-08-19 23:57:39 -04:00 committed by GitHub
commit 7c1d32719a
2 changed files with 41 additions and 1 deletions

View File

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

View File

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