terraform: test for referencing counts that are from vars

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

View File

@ -1156,6 +1156,34 @@ func TestContext2Apply_countVariable(t *testing.T) {
}
}
func TestContext2Apply_countVariableRef(t *testing.T) {
m := testModule(t, "apply-count-variable-ref")
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)
}
actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace(testTerraformApplyCountVariableRefStr)
if actual != expected {
t.Fatalf("bad: \n%s", actual)
}
}
func TestContext2Apply_mapVariableOverride(t *testing.T) {
m := testModule(t, "apply-map-var-override")
p := testProvider("aws")

View File

@ -386,6 +386,20 @@ aws_instance.foo.1:
type = aws_instance
`
const testTerraformApplyCountVariableRefStr = `
aws_instance.bar:
ID = foo
foo = 2
type = aws_instance
Dependencies:
aws_instance.foo
aws_instance.foo.0:
ID = foo
aws_instance.foo.1:
ID = foo
`
const testTerraformApplyMinimalStr = `
aws_instance.bar:
ID = foo

View File

@ -0,0 +1,11 @@
variable "foo" {
default = "2"
}
resource "aws_instance" "foo" {
count = "${var.foo}"
}
resource "aws_instance" "bar" {
foo = "${aws_instance.foo.count}"
}