diff --git a/terraform/context.go b/terraform/context.go index 49c5da1ef..72166f8d6 100644 --- a/terraform/context.go +++ b/terraform/context.go @@ -1623,6 +1623,12 @@ func (c *walkContext) computeModuleVariable( // Get that module from our state mod := c.Context.state.ModuleByPath(path) if mod == nil { + // If the module doesn't exist, then we can return an empty string. + // This happens usually only in Refresh() when we haven't populated + // a state. During validation, we semantically verify that all + // modules reference other modules, and graph ordering should + // ensure that the module is in the state, so if we reach this + // point otherwise it really is a panic. return "", nil } diff --git a/terraform/test-fixtures/refresh-module-var-module/bar/main.tf b/terraform/test-fixtures/refresh-module-var-module/bar/main.tf new file mode 100644 index 000000000..46ea37f14 --- /dev/null +++ b/terraform/test-fixtures/refresh-module-var-module/bar/main.tf @@ -0,0 +1,3 @@ +variable "value" {} + +resource "aws_instance" "bar" {} diff --git a/terraform/test-fixtures/refresh-module-var-module/foo/main.tf b/terraform/test-fixtures/refresh-module-var-module/foo/main.tf new file mode 100644 index 000000000..2ee798058 --- /dev/null +++ b/terraform/test-fixtures/refresh-module-var-module/foo/main.tf @@ -0,0 +1,7 @@ +output "output" { + value = "${aws_instance.foo.foo}" +} + +resource "aws_instance" "foo" { + compute = "foo" +} diff --git a/terraform/test-fixtures/refresh-module-var-module/main.tf b/terraform/test-fixtures/refresh-module-var-module/main.tf new file mode 100644 index 000000000..76775e3e6 --- /dev/null +++ b/terraform/test-fixtures/refresh-module-var-module/main.tf @@ -0,0 +1,8 @@ +module "foo" { + source = "./foo" +} + +module "bar" { + source = "./bar" + value = "${module.foo.output}" +}