terraform: add test explicitly for referencing count

This commit is contained in:
Mitchell Hashimoto 2016-08-31 11:49:25 -07:00
parent 08a9c8e2c2
commit d2e15ab69a
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 56 additions and 0 deletions

View File

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

View File

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

View File

@ -0,0 +1,7 @@
resource "aws_instance" "foo" {
count = 3
}
resource "aws_instance" "bar" {
foo = "${aws_instance.foo.count}"
}