check for errors when loading a backend config

We can't dereference the config module if there were any errors loading
it.
This commit is contained in:
James Bardin 2019-03-12 17:57:26 -04:00
parent 8c966a85ee
commit a8df5586c0
2 changed files with 13 additions and 0 deletions

View File

@ -173,6 +173,9 @@ func (m *Meta) dirIsConfigPath(dir string) bool {
// directory even if loadBackendConfig succeeded.) // directory even if loadBackendConfig succeeded.)
func (m *Meta) loadBackendConfig(rootDir string) (*configs.Backend, tfdiags.Diagnostics) { func (m *Meta) loadBackendConfig(rootDir string) (*configs.Backend, tfdiags.Diagnostics) {
mod, diags := m.loadSingleModule(rootDir) mod, diags := m.loadSingleModule(rootDir)
if diags.HasErrors() {
return nil, diags
}
return mod.Backend, diags return mod.Backend, diags
} }

View File

@ -49,6 +49,16 @@ func TestUnlock(t *testing.T) {
if code := c.Run(args); code != 1 { if code := c.Run(args); code != 1 {
t.Fatalf("bad: %d\n%s\n%s", code, ui.OutputWriter.String(), ui.ErrorWriter.String()) t.Fatalf("bad: %d\n%s\n%s", code, ui.OutputWriter.String(), ui.ErrorWriter.String())
} }
// make sure we don't crash with arguments in the wrong order
args = []string{
"LOCK_ID",
"-force",
}
if code := c.Run(args); code != 1 {
t.Fatalf("bad: %d\n%s\n%s", code, ui.OutputWriter.String(), ui.ErrorWriter.String())
}
} }
// Newly configured backend // Newly configured backend