2016-04-26 12:47:56 -05:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-04-28 12:25:58 -05:00
|
|
|
func TestContextImport_basic(t *testing.T) {
|
2016-04-26 12:47:56 -05:00
|
|
|
p := testProvider("aws")
|
|
|
|
ctx := testContext2(t, &ContextOpts{
|
|
|
|
Providers: map[string]ResourceProviderFactory{
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2016-04-28 12:25:58 -05:00
|
|
|
p.ImportStateReturn = []*InstanceState{
|
|
|
|
&InstanceState{
|
|
|
|
ID: "foo",
|
|
|
|
Ephemeral: EphemeralState{Type: "aws_instance"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-04-28 04:46:46 -05:00
|
|
|
state, err := ctx.Import(&ImportOpts{
|
|
|
|
Targets: []*ImportTarget{
|
|
|
|
&ImportTarget{
|
|
|
|
Addr: "aws_instance.foo",
|
|
|
|
ID: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2016-04-26 12:47:56 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := strings.TrimSpace(state.String())
|
2016-04-28 04:46:46 -05:00
|
|
|
expected := strings.TrimSpace(testImportStr)
|
2016-04-26 12:47:56 -05:00
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: \n%s", actual)
|
|
|
|
}
|
|
|
|
}
|
2016-04-28 04:46:46 -05:00
|
|
|
|
2016-04-28 12:25:58 -05:00
|
|
|
const testImportStr = `
|
|
|
|
aws_instance.foo:
|
|
|
|
ID = foo
|
|
|
|
provider = aws
|
|
|
|
`
|