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:
Mitchell Hashimoto 2015-03-25 16:54:46 -07:00
commit 8f11118840
2 changed files with 22 additions and 1 deletions

View File

@ -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" +

View File

@ -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{