Merge pull request #12793 from hashicorp/b-config-module

config/module: don't panic when referencing undefined module
This commit is contained in:
Mitchell Hashimoto 2017-03-16 23:33:53 -07:00 committed by GitHub
commit 7f756d1738
3 changed files with 19 additions and 2 deletions

View File

@ -0,0 +1,3 @@
resource "null_resource" "var" {
key = "${module.unknown.value}"
}

View File

@ -354,8 +354,10 @@ func (t *Tree) Validate() error {
tree, ok := children[mv.Name]
if !ok {
// This should never happen because Load watches us
panic("module not found in children: " + mv.Name)
newErr.Add(fmt.Errorf(
"%s: undefined module referenced %s",
source, mv.Name))
continue
}
found := false

View File

@ -424,6 +424,18 @@ func TestTreeValidate_requiredChildVar(t *testing.T) {
}
}
func TestTreeValidate_unknownModule(t *testing.T) {
tree := NewTree("", testConfig(t, "validate-module-unknown"))
if err := tree.Load(testStorage(t), GetModeNone); err != nil {
t.Fatalf("err: %s", err)
}
if err := tree.Validate(); err == nil {
t.Fatal("should error")
}
}
const treeLoadStr = `
root
foo (path: foo)