From c1079b59bd638145c07edab4fb7bea2f3d86d560 Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Mon, 15 Apr 2019 12:22:07 -0400 Subject: [PATCH] command/state_list.go: fix bug loading user-defined state (#21015) * command/state_list.go: fix bug loading user-defined state If the user supplied a state path via the `-state` flag and terraform was running in a workspace other than `default`, the state was not being loaded properly. Fixes #19920 --- command/state_list.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/command/state_list.go b/command/state_list.go index 3e173fb65..adaff6fc1 100644 --- a/command/state_list.go +++ b/command/state_list.go @@ -23,14 +23,19 @@ func (c *StateListCommand) Run(args []string) int { return 1 } + var statePath string cmdFlags := c.Meta.defaultFlagSet("state list") - cmdFlags.StringVar(&c.Meta.statePath, "state", "", "path") + cmdFlags.StringVar(&statePath, "state", "", "path") lookupId := cmdFlags.String("id", "", "Restrict output to paths with a resource having the specified ID.") if err := cmdFlags.Parse(args); err != nil { return cli.RunResultHelp } args = cmdFlags.Args() + if statePath != "" { + c.Meta.statePath = statePath + } + // Load the backend b, backendDiags := c.Backend(nil) if backendDiags.HasErrors() { @@ -46,7 +51,7 @@ func (c *StateListCommand) Run(args []string) int { return 1 } if err := stateMgr.RefreshState(); err != nil { - c.Ui.Error(fmt.Sprintf("Failed to refresh state: %s", err)) + c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err)) return 1 }