terraform: test importing into an existing module

This commit is contained in:
Mitchell Hashimoto 2016-04-30 17:00:18 -05:00
parent 7fe8b21969
commit 2738fa7df5
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 59 additions and 0 deletions

View File

@ -181,6 +181,56 @@ func TestContextImport_moduleDepth2(t *testing.T) {
} }
} }
func TestContextImport_moduleExisting(t *testing.T) {
p := testProvider("aws")
ctx := testContext2(t, &ContextOpts{
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
State: &State{
Modules: []*ModuleState{
&ModuleState{
Path: []string{"root", "foo"},
Resources: map[string]*ResourceState{
"aws_instance.bar": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "bar",
},
},
},
},
},
},
})
p.ImportStateReturn = []*InstanceState{
&InstanceState{
ID: "foo",
Ephemeral: EphemeralState{Type: "aws_instance"},
},
}
state, err := ctx.Import(&ImportOpts{
Targets: []*ImportTarget{
&ImportTarget{
Addr: "module.foo.aws_instance.foo",
ID: "bar",
},
},
})
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace(testImportModuleExistingStr)
if actual != expected {
t.Fatalf("bad: \n%s", actual)
}
}
const testImportStr = ` const testImportStr = `
aws_instance.foo: aws_instance.foo:
ID = foo ID = foo
@ -203,6 +253,15 @@ module.a.b:
provider = aws provider = aws
` `
const testImportModuleExistingStr = `
module.foo:
aws_instance.bar:
ID = bar
aws_instance.foo:
ID = foo
provider = aws
`
const testImportRefreshStr = ` const testImportRefreshStr = `
aws_instance.foo: aws_instance.foo:
ID = foo ID = foo