terraform: add test explicitly for referencing count
This commit is contained in:
parent
08a9c8e2c2
commit
d2e15ab69a
|
@ -149,6 +149,39 @@ module.test:
|
|||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_refCount(t *testing.T) {
|
||||
m := testModule(t, "apply-ref-count")
|
||||
p := testProvider("aws")
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
if _, err := ctx.Plan(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
state, err := ctx.Apply()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
mod := state.RootModule()
|
||||
if len(mod.Resources) < 2 {
|
||||
t.Fatalf("bad: %#v", mod.Resources)
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(state.String())
|
||||
expected := strings.TrimSpace(testTerraformApplyRefCountStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad: \n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_providerAlias(t *testing.T) {
|
||||
m := testModule(t, "apply-provider-alias")
|
||||
p := testProvider("aws")
|
||||
|
|
|
@ -238,6 +238,22 @@ aws_instance.foo:
|
|||
type = aws_instance
|
||||
`
|
||||
|
||||
const testTerraformApplyRefCountStr = `
|
||||
aws_instance.bar:
|
||||
ID = foo
|
||||
foo = 3
|
||||
type = aws_instance
|
||||
|
||||
Dependencies:
|
||||
aws_instance.foo
|
||||
aws_instance.foo.0:
|
||||
ID = foo
|
||||
aws_instance.foo.1:
|
||||
ID = foo
|
||||
aws_instance.foo.2:
|
||||
ID = foo
|
||||
`
|
||||
|
||||
const testTerraformApplyProviderAliasStr = `
|
||||
aws_instance.bar:
|
||||
ID = foo
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
resource "aws_instance" "foo" {
|
||||
count = 3
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
foo = "${aws_instance.foo.count}"
|
||||
}
|
Loading…
Reference in New Issue