terraform: test case for variable count

This commit is contained in:
Mitchell Hashimoto 2014-10-17 18:03:30 -07:00
parent 35352a2746
commit bf7c40d115
3 changed files with 48 additions and 0 deletions

View File

@ -1203,6 +1203,35 @@ func TestContextApply_countTainted(t *testing.T) {
t.Fatalf("bad: \n%s", actual) t.Fatalf("bad: \n%s", actual)
} }
} }
func TestContextApply_countVariable(t *testing.T) {
m := testModule(t, "apply-count-variable")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
if _, err := ctx.Plan(nil); 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(testTerraformApplyCountVariableStr)
if actual != expected {
t.Fatalf("bad: \n%s", actual)
}
}
func TestContextApply_module(t *testing.T) { func TestContextApply_module(t *testing.T) {
m := testModule(t, "apply-module") m := testModule(t, "apply-module")
p := testProvider("aws") p := testProvider("aws")

View File

@ -228,6 +228,17 @@ const testTerraformApplyCountTaintedStr = `
<no state> <no state>
` `
const testTerraformApplyCountVariableStr = `
aws_instance.foo.0:
ID = foo
foo = foo
type = aws_instance
aws_instance.foo.1:
ID = foo
foo = foo
type = aws_instance
`
const testTerraformApplyMinimalStr = ` const testTerraformApplyMinimalStr = `
aws_instance.bar: aws_instance.bar:
ID = foo ID = foo

View File

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