Merge pull request #1308 from hashicorp/b-nil-state-output
command/output: don't panic if no root module in state [GH-1263]
This commit is contained in:
commit
8f11118840
|
@ -39,7 +39,7 @@ func (c *OutputCommand) Run(args []string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
state := stateStore.State()
|
state := stateStore.State()
|
||||||
if len(state.RootModule().Outputs) == 0 {
|
if state.Empty() || len(state.RootModule().Outputs) == 0 {
|
||||||
c.Ui.Error(fmt.Sprintf(
|
c.Ui.Error(fmt.Sprintf(
|
||||||
"The state file has no outputs defined. Define an output\n" +
|
"The state file has no outputs defined. Define an output\n" +
|
||||||
"in your configuration with the `output` directive and re-run\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) {
|
func TestOutput_noVars(t *testing.T) {
|
||||||
originalState := &terraform.State{
|
originalState := &terraform.State{
|
||||||
Modules: []*terraform.ModuleState{
|
Modules: []*terraform.ModuleState{
|
||||||
|
|
Loading…
Reference in New Issue