Merge pull request #11099 from hashicorp/b-root-module
config/module: disallow root modules named "root"
This commit is contained in:
commit
7f35b2015c
|
@ -0,0 +1 @@
|
|||
# Empty
|
|
@ -0,0 +1 @@
|
|||
module "root" { source = "./child" }
|
|
@ -0,0 +1,3 @@
|
|||
module "child" {
|
||||
source = "./child"
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
# Empty
|
|
@ -0,0 +1,3 @@
|
|||
module "root" {
|
||||
source = "./child"
|
||||
}
|
|
@ -261,6 +261,14 @@ func (t *Tree) Validate() error {
|
|||
// If something goes wrong, here is our error template
|
||||
newErr := &TreeError{Name: []string{t.Name()}}
|
||||
|
||||
// Terraform core does not handle root module children named "root".
|
||||
// We plan to fix this in the future but this bug was brought up in
|
||||
// the middle of a release and we don't want to introduce wide-sweeping
|
||||
// changes at that time.
|
||||
if len(t.path) == 1 && t.name == "root" {
|
||||
return fmt.Errorf("root module cannot contain module named 'root'")
|
||||
}
|
||||
|
||||
// Validate our configuration first.
|
||||
if err := t.config.Validate(); err != nil {
|
||||
newErr.Err = err
|
||||
|
|
|
@ -288,6 +288,18 @@ func TestTreeValidate_table(t *testing.T) {
|
|||
"validate-alias-bad",
|
||||
"alias must be defined",
|
||||
},
|
||||
|
||||
{
|
||||
"root module named root",
|
||||
"validate-module-root",
|
||||
"cannot contain module",
|
||||
},
|
||||
|
||||
{
|
||||
"grandchild module named root",
|
||||
"validate-module-root-grandchild",
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
|
|
Loading…
Reference in New Issue