Merge pull request #9640 from hashicorp/jbardin/GH-9572
Fix panic during "terraform show" with empty state
This commit is contained in:
commit
07d10dad00
|
@ -55,6 +55,10 @@ func (c *StateShowCommand) Run(args []string) int {
|
|||
return 1
|
||||
}
|
||||
|
||||
if instance == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
is := instance.Value.(*terraform.InstanceState)
|
||||
|
||||
// Sort the keys
|
||||
|
|
|
@ -127,7 +127,7 @@ func TestStateShow_noState(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestStateShow_emptyState(t *testing.T) {
|
||||
state := &terraform.State{}
|
||||
state := terraform.NewState()
|
||||
|
||||
statePath := testStateFile(t, state)
|
||||
|
||||
|
@ -149,6 +149,34 @@ func TestStateShow_emptyState(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestStateShow_emptyStateWithModule(t *testing.T) {
|
||||
// empty state with empty module
|
||||
state := terraform.NewState()
|
||||
|
||||
mod := &terraform.ModuleState{
|
||||
Path: []string{"root", "mod"},
|
||||
}
|
||||
state.Modules = append(state.Modules, mod)
|
||||
|
||||
statePath := testStateFile(t, state)
|
||||
|
||||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateShowCommand{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"-state", statePath,
|
||||
}
|
||||
if code := c.Run(args); code != 0 {
|
||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||
}
|
||||
}
|
||||
|
||||
const testStateShowOutput = `
|
||||
id = bar
|
||||
bar = value
|
||||
|
|
Loading…
Reference in New Issue