From ab414de0abbb0c495727928ff82135a434fa791e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 20 Feb 2015 10:02:52 -0800 Subject: [PATCH] terraform: test case for destroying with a count [GH-527] --- terraform/context_test.go | 42 +++++++++++++++++++ .../child/main.tf | 5 +++ .../apply-module-var-resource-count/main.tf | 6 +++ 3 files changed, 53 insertions(+) create mode 100644 terraform/test-fixtures/apply-module-var-resource-count/child/main.tf create mode 100644 terraform/test-fixtures/apply-module-var-resource-count/main.tf diff --git a/terraform/context_test.go b/terraform/context_test.go index cb943c117..01f3745be 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -3229,6 +3229,48 @@ func TestContext2Apply_module(t *testing.T) { } } +func TestContext2Apply_moduleVarResourceCount(t *testing.T) { + m := testModule(t, "apply-module-var-resource-count") + p := testProvider("aws") + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn + ctx := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + Variables: map[string]string{ + "count": "2", + }, + }) + + if _, err := ctx.Plan(nil); err != nil { + t.Fatalf("err: %s", err) + } + + if _, err := ctx.Apply(); err != nil { + t.Fatalf("err: %s", err) + } + + ctx = testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + Variables: map[string]string{ + "count": "5", + }, + }) + + if _, err := ctx.Plan(&PlanOpts{Destroy: true}); err != nil { + t.Fatalf("err: %s", err) + } + + if _, err := ctx.Apply(); err != nil { + t.Fatalf("err: %s", err) + } +} + func TestContext2Apply_multiProvider(t *testing.T) { m := testModule(t, "apply-multi-provider") p := testProvider("aws") diff --git a/terraform/test-fixtures/apply-module-var-resource-count/child/main.tf b/terraform/test-fixtures/apply-module-var-resource-count/child/main.tf new file mode 100644 index 000000000..e624b53a6 --- /dev/null +++ b/terraform/test-fixtures/apply-module-var-resource-count/child/main.tf @@ -0,0 +1,5 @@ +variable "count" {} + +resource "aws_instance" "foo" { + count = "${var.count}" +} diff --git a/terraform/test-fixtures/apply-module-var-resource-count/main.tf b/terraform/test-fixtures/apply-module-var-resource-count/main.tf new file mode 100644 index 000000000..1afaeb758 --- /dev/null +++ b/terraform/test-fixtures/apply-module-var-resource-count/main.tf @@ -0,0 +1,6 @@ +variable "count" {} + +module "child" { + source = "./child" + count = "${var.count}" +}