From d2e15ab69ac8df57033bae9b7e3f8532a8cbff90 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 31 Aug 2016 11:49:25 -0700 Subject: [PATCH] terraform: add test explicitly for referencing count --- terraform/context_apply_test.go | 33 +++++++++++++++++++ terraform/terraform_test.go | 16 +++++++++ .../test-fixtures/apply-ref-count/main.tf | 7 ++++ 3 files changed, 56 insertions(+) create mode 100644 terraform/test-fixtures/apply-ref-count/main.tf diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 0462096ba..1d7c15f92 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -149,6 +149,39 @@ module.test: } } +func TestContext2Apply_refCount(t *testing.T) { + m := testModule(t, "apply-ref-count") + 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) + } + + mod := state.RootModule() + if len(mod.Resources) < 2 { + t.Fatalf("bad: %#v", mod.Resources) + } + + actual := strings.TrimSpace(state.String()) + expected := strings.TrimSpace(testTerraformApplyRefCountStr) + if actual != expected { + t.Fatalf("bad: \n%s", actual) + } +} + func TestContext2Apply_providerAlias(t *testing.T) { m := testModule(t, "apply-provider-alias") p := testProvider("aws") diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index e6dc575e5..4208eedec 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -238,6 +238,22 @@ aws_instance.foo: type = aws_instance ` +const testTerraformApplyRefCountStr = ` +aws_instance.bar: + ID = foo + foo = 3 + type = aws_instance + + Dependencies: + aws_instance.foo +aws_instance.foo.0: + ID = foo +aws_instance.foo.1: + ID = foo +aws_instance.foo.2: + ID = foo +` + const testTerraformApplyProviderAliasStr = ` aws_instance.bar: ID = foo diff --git a/terraform/test-fixtures/apply-ref-count/main.tf b/terraform/test-fixtures/apply-ref-count/main.tf new file mode 100644 index 000000000..8669ba572 --- /dev/null +++ b/terraform/test-fixtures/apply-ref-count/main.tf @@ -0,0 +1,7 @@ +resource "aws_instance" "foo" { + count = 3 +} + +resource "aws_instance" "bar" { + foo = "${aws_instance.foo.count}" +}