From 86a4a6c7c8f36532df42b42fd0050784cbc53bc3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 23 Sep 2014 17:13:50 -0700 Subject: [PATCH] terraform: test apply with modules --- terraform/context_test.go | 28 +++++++++++++++++++ terraform/terraform_test.go | 17 +++++++++++ .../test-fixtures/apply-module/child/main.tf | 3 ++ terraform/test-fixtures/apply-module/main.tf | 11 ++++++++ 4 files changed, 59 insertions(+) create mode 100644 terraform/test-fixtures/apply-module/child/main.tf create mode 100644 terraform/test-fixtures/apply-module/main.tf diff --git a/terraform/context_test.go b/terraform/context_test.go index 4b6bfbfc7..cc345f006 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -524,6 +524,34 @@ func TestContextApply_compute(t *testing.T) { } } +func TestContextApply_module(t *testing.T) { + m := testModule(t, "apply-module") + 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(testTerraformApplyModuleStr) + if actual != expected { + t.Fatalf("bad: \n%s", actual) + } +} + func TestContextApply_nilDiff(t *testing.T) { m := testModule(t, "apply-good") p := testProvider("aws") diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index 75e5d3475..e42f6c4b6 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -152,6 +152,23 @@ aws_instance.foo: ID = foo ` +const testTerraformApplyModuleStr = ` +aws_instance.bar: + ID = foo + foo = bar + type = aws_instance +aws_instance.foo: + ID = foo + num = 2 + type = aws_instance + +module.child: + aws_instance.baz: + ID = foo + foo = bar + type = aws_instance +` + const testTerraformApplyProvisionerStr = ` aws_instance.bar: ID = foo diff --git a/terraform/test-fixtures/apply-module/child/main.tf b/terraform/test-fixtures/apply-module/child/main.tf new file mode 100644 index 000000000..f279d9b80 --- /dev/null +++ b/terraform/test-fixtures/apply-module/child/main.tf @@ -0,0 +1,3 @@ +resource "aws_instance" "baz" { + foo = "bar" +} diff --git a/terraform/test-fixtures/apply-module/main.tf b/terraform/test-fixtures/apply-module/main.tf new file mode 100644 index 000000000..f9119a109 --- /dev/null +++ b/terraform/test-fixtures/apply-module/main.tf @@ -0,0 +1,11 @@ +module "child" { + source = "./child" +} + +resource "aws_instance" "foo" { + num = "2" +} + +resource "aws_instance" "bar" { + foo = "bar" +}