From a8df5586c0932e58ef9ef8b33ef217a211480272 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 12 Mar 2019 17:57:26 -0400 Subject: [PATCH] check for errors when loading a backend config We can't dereference the config module if there were any errors loading it. --- command/meta_config.go | 3 +++ command/unlock_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/command/meta_config.go b/command/meta_config.go index 33264498f..2989a7e72 100644 --- a/command/meta_config.go +++ b/command/meta_config.go @@ -173,6 +173,9 @@ func (m *Meta) dirIsConfigPath(dir string) bool { // directory even if loadBackendConfig succeeded.) func (m *Meta) loadBackendConfig(rootDir string) (*configs.Backend, tfdiags.Diagnostics) { mod, diags := m.loadSingleModule(rootDir) + if diags.HasErrors() { + return nil, diags + } return mod.Backend, diags } diff --git a/command/unlock_test.go b/command/unlock_test.go index 27fce9c83..db3256dd4 100644 --- a/command/unlock_test.go +++ b/command/unlock_test.go @@ -49,6 +49,16 @@ func TestUnlock(t *testing.T) { if code := c.Run(args); code != 1 { 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