import blocks are only allowed in the root module

This commit is contained in:
CJ Horton 2023-05-12 16:04:47 -07:00
parent bd6ba6cf99
commit 2dd89d9776
4 changed files with 27 additions and 0 deletions

View File

@ -4,6 +4,7 @@
package configs package configs
import ( import (
"fmt"
"sort" "sort"
version "github.com/hashicorp/go-version" version "github.com/hashicorp/go-version"
@ -101,6 +102,15 @@ func buildChildModules(parent *Config, walker ModuleWalker) (map[string]*Config,
}) })
} }
if len(mod.Import) > 0 {
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid import configuration",
Detail: fmt.Sprintf("An import block was detected in %q. Import blocks are only allowed in the root module.", child.Path),
Subject: mod.Import[0].DeclRange.Ptr(),
})
}
ret[call.Name] = child ret[call.Name] = child
} }

View File

@ -0,0 +1,6 @@
resource "aws_instance" "web" {}
import {
to = aws_instance.web
id = "test"
}

View File

@ -0,0 +1 @@
import-in-child-module/child/main.tf:3,1-7: Invalid import configuration; An import block was detected in "module.child". Import blocks are only allowed in the root module.

View File

@ -0,0 +1,10 @@
resource "aws_instance" "web" {}
import {
to = aws_instance.web
id = "test"
}
module "child" {
source = "./child"
}