don't build a config if it didn't load properly
This commit is contained in:
parent
8d4d333efe
commit
655f18c393
|
@ -20,7 +20,7 @@ import (
|
|||
// required to process the individual modules
|
||||
func (l *Loader) LoadConfig(rootDir string) (*configs.Config, hcl.Diagnostics) {
|
||||
rootMod, diags := l.parser.LoadConfigDir(rootDir)
|
||||
if rootMod == nil {
|
||||
if rootMod == nil || diags.HasErrors() {
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
|
|
|
@ -80,3 +80,19 @@ func TestLoaderLoadConfig_addVersion(t *testing.T) {
|
|||
t.Fatalf("wrong error\ngot:\n%s\n\nwant: containing %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoaderLoadConfig_loadDiags(t *testing.T) {
|
||||
// building a config which didn't load correctly may cause configs to panic
|
||||
fixtureDir := filepath.Clean("testdata/invalid-names")
|
||||
loader, err := NewLoader(&Config{
|
||||
ModulesDir: filepath.Join(fixtureDir, ".terraform/modules"),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error from NewLoader: %s", err)
|
||||
}
|
||||
|
||||
_, diags := loader.LoadConfig(fixtureDir)
|
||||
if !diags.HasErrors() {
|
||||
t.Fatalf("success; want error")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
provider "42_bad!" {
|
||||
invalid_provider_name = "yes"
|
||||
}
|
Loading…
Reference in New Issue