From c3ce23c7b43913a90e7516141494b562a7b960d7 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Mon, 4 May 2015 15:43:23 -0500 Subject: [PATCH] core: failing test for a bad module cycle passing output of one module into input of the following module results in a cycle --- terraform/context_test.go | 20 +++++++++++++++++++ .../validate-module-deps-cycle/a/main.tf | 5 +++++ .../validate-module-deps-cycle/b/main.tf | 4 ++++ .../validate-module-deps-cycle/main.tf | 8 ++++++++ 4 files changed, 37 insertions(+) create mode 100644 terraform/test-fixtures/validate-module-deps-cycle/a/main.tf create mode 100644 terraform/test-fixtures/validate-module-deps-cycle/b/main.tf create mode 100644 terraform/test-fixtures/validate-module-deps-cycle/main.tf diff --git a/terraform/context_test.go b/terraform/context_test.go index 907f21c4b..2988fca6f 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -2443,6 +2443,26 @@ func TestContext2Validate_moduleBadResource(t *testing.T) { } } +func TestContext2Validate_moduleDepsShouldNotCycle(t *testing.T) { + m := testModule(t, "validate-module-deps-cycle") + p := testProvider("aws") + ctx := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + }) + + w, e := ctx.Validate() + + if len(w) > 0 { + t.Fatalf("expected no warnings, got: %s", w) + } + if len(e) > 0 { + t.Fatalf("expected no errors, got: %s", e) + } +} + func TestContext2Validate_moduleProviderInherit(t *testing.T) { m := testModule(t, "validate-module-pc-inherit") p := testProvider("aws") diff --git a/terraform/test-fixtures/validate-module-deps-cycle/a/main.tf b/terraform/test-fixtures/validate-module-deps-cycle/a/main.tf new file mode 100644 index 000000000..3d3b01634 --- /dev/null +++ b/terraform/test-fixtures/validate-module-deps-cycle/a/main.tf @@ -0,0 +1,5 @@ +resource "aws_instance" "a" { } + +output "output" { + value = "${aws_instance.a.id}" +} diff --git a/terraform/test-fixtures/validate-module-deps-cycle/b/main.tf b/terraform/test-fixtures/validate-module-deps-cycle/b/main.tf new file mode 100644 index 000000000..d43b6c0c0 --- /dev/null +++ b/terraform/test-fixtures/validate-module-deps-cycle/b/main.tf @@ -0,0 +1,4 @@ +variable "input" {} +resource "aws_instance" "b" { + name = "${var.input}" +} diff --git a/terraform/test-fixtures/validate-module-deps-cycle/main.tf b/terraform/test-fixtures/validate-module-deps-cycle/main.tf new file mode 100644 index 000000000..11ddb64bf --- /dev/null +++ b/terraform/test-fixtures/validate-module-deps-cycle/main.tf @@ -0,0 +1,8 @@ +module "a" { + source = "./a" +} + +module "b" { + source = "./b" + input = "${module.a.output}" +}