command: "terraform output" mustn't panic when no state is present

This is verified by TestOutput_noArgs.
This commit is contained in:
Martin Atkins 2018-11-16 17:24:06 -08:00
parent 53b5b95ef5
commit 37bc187f95

View File

@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/config/hcl2shim"
"github.com/hashicorp/terraform/repl"
"github.com/hashicorp/terraform/states"
"github.com/hashicorp/terraform/tfdiags"
)
@ -95,6 +96,10 @@ func (c *OutputCommand) Run(args []string) int {
}
state := stateStore.State()
if state == nil {
state = states.NewState()
}
mod := state.Module(moduleAddr)
if mod == nil {
c.Ui.Error(fmt.Sprintf(