command/output: don't panic if no root module in state [GH-1263]
This commit is contained in:
parent
27f4f5889b
commit
83cb277583
|
@ -39,7 +39,7 @@ func (c *OutputCommand) Run(args []string) int {
|
|||
}
|
||||
|
||||
state := stateStore.State()
|
||||
if len(state.RootModule().Outputs) == 0 {
|
||||
if state.Empty() || len(state.RootModule().Outputs) == 0 {
|
||||
c.Ui.Error(fmt.Sprintf(
|
||||
"The state file has no outputs defined. Define an output\n" +
|
||||
"in your configuration with the `output` directive and re-run\n" +
|
||||
|
|
|
@ -142,6 +142,27 @@ func TestOutput_noArgs(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestOutput_noState(t *testing.T) {
|
||||
originalState := &terraform.State{}
|
||||
statePath := testStateFile(t, originalState)
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
c := &OutputCommand{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(testProvider()),
|
||||
Ui: ui,
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"-state", statePath,
|
||||
"foo",
|
||||
}
|
||||
if code := c.Run(args); code != 1 {
|
||||
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutput_noVars(t *testing.T) {
|
||||
originalState := &terraform.State{
|
||||
Modules: []*terraform.ModuleState{
|
||||
|
|
Loading…
Reference in New Issue