diff --git a/terraform/context_test.go b/terraform/context_test.go index dd19c654e..5137b6611 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -1203,6 +1203,35 @@ func TestContextApply_countTainted(t *testing.T) { 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) { m := testModule(t, "apply-module") p := testProvider("aws") diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index 7447010b7..543862950 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -228,6 +228,17 @@ const testTerraformApplyCountTaintedStr = ` ` +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 = ` aws_instance.bar: ID = foo diff --git a/terraform/test-fixtures/apply-count-variable/main.tf b/terraform/test-fixtures/apply-count-variable/main.tf new file mode 100644 index 000000000..6f322f218 --- /dev/null +++ b/terraform/test-fixtures/apply-count-variable/main.tf @@ -0,0 +1,8 @@ +variable "foo" { + default = "2" +} + +resource "aws_instance" "foo" { + foo = "foo" + count = "${var.foo}" +}