diff --git a/terraform/context_test.go b/terraform/context_test.go index 907f21c4bc..2988fca6fa 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 0000000000..3d3b01634e --- /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 0000000000..d43b6c0c06 --- /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 0000000000..11ddb64bfa --- /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}" +}