Merge pull request #12793 from hashicorp/b-config-module
config/module: don't panic when referencing undefined module
This commit is contained in:
commit
7f756d1738
|
@ -0,0 +1,3 @@
|
|||
resource "null_resource" "var" {
|
||||
key = "${module.unknown.value}"
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue