From ced4125037028ff90194b24ffaf3b1d873427382 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 2 Oct 2014 15:47:00 -0700 Subject: [PATCH] teraform: test that count can be a variable --- terraform/context_test.go | 26 +++++++++++++++++++ terraform/terraform_test.go | 21 +++++++++++++++ .../test-fixtures/plan-count-var/main.tf | 10 +++++++ 3 files changed, 57 insertions(+) create mode 100644 terraform/test-fixtures/plan-count-var/main.tf diff --git a/terraform/context_test.go b/terraform/context_test.go index 6ebd9ac0b..1313a6f27 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -2428,6 +2428,32 @@ func TestContextPlan_count(t *testing.T) { } } +func TestContextPlan_countVar(t *testing.T) { + m := testModule(t, "plan-count-var") + p := testProvider("aws") + p.DiffFn = testDiffFn + ctx := testContext(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + Variables: map[string]string{ + "count": "3", + }, + }) + + plan, err := ctx.Plan(nil) + if err != nil { + t.Fatalf("err: %s", err) + } + + actual := strings.TrimSpace(plan.String()) + expected := strings.TrimSpace(testTerraformPlanCountVarStr) + if actual != expected { + t.Fatalf("bad:\n%s", actual) + } +} + func TestContextPlan_countDecreaseToOne(t *testing.T) { m := testModule(t, "plan-count-dec") p := testProvider("aws") diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index cdcb6ea20..350a2354d 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -477,6 +477,27 @@ STATE: ` +const testTerraformPlanCountVarStr = ` +DIFF: + +CREATE: aws_instance.bar + foo: "" => "foo,foo,foo" + type: "" => "aws_instance" +CREATE: aws_instance.foo.0 + foo: "" => "foo" + type: "" => "aws_instance" +CREATE: aws_instance.foo.1 + foo: "" => "foo" + type: "" => "aws_instance" +CREATE: aws_instance.foo.2 + foo: "" => "foo" + type: "" => "aws_instance" + +STATE: + + +` + const testTerraformPlanCountDecreaseStr = ` DIFF: diff --git a/terraform/test-fixtures/plan-count-var/main.tf b/terraform/test-fixtures/plan-count-var/main.tf new file mode 100644 index 000000000..f64b9655b --- /dev/null +++ b/terraform/test-fixtures/plan-count-var/main.tf @@ -0,0 +1,10 @@ +variable "count" {} + +resource "aws_instance" "foo" { + count = "${var.count}" + foo = "foo" +} + +resource "aws_instance" "bar" { + foo = "${aws_instance.foo.*.foo}" +}