command/show: enable printing of remote state
This commit is contained in:
parent
5f35c7852f
commit
cce881aadd
|
@ -36,30 +36,19 @@ func (c *ShowCommand) Run(args []string) int {
|
|||
return 1
|
||||
}
|
||||
|
||||
var err, planErr, stateErr error
|
||||
var path string
|
||||
if len(args) > 0 {
|
||||
path = args[0]
|
||||
} else {
|
||||
// We should use the default state if it exists.
|
||||
path = DefaultStateFilename
|
||||
if _, err := os.Stat(DefaultStateFilename); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
c.Ui.Output("No state.")
|
||||
return 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var plan *terraform.Plan
|
||||
var state *terraform.State
|
||||
|
||||
if len(args) > 0 {
|
||||
path = args[0]
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error loading file: %s", err))
|
||||
return 1
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
var planErr, stateErr error
|
||||
plan, err = terraform.ReadPlan(f)
|
||||
if err != nil {
|
||||
if _, err := f.Seek(0, 0); err != nil {
|
||||
|
@ -76,6 +65,21 @@ func (c *ShowCommand) Run(args []string) int {
|
|||
stateErr = err
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// We should use the default state if it exists.
|
||||
c.Meta.statePath = DefaultStateFilename
|
||||
state, err = c.Meta.loadState()
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error reading state: %s", err))
|
||||
return 1
|
||||
}
|
||||
if state == nil {
|
||||
c.Ui.Output("No state.")
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
if plan == nil && state == nil {
|
||||
c.Ui.Error(fmt.Sprintf(
|
||||
"Terraform couldn't read the given file as a state or plan file.\n"+
|
||||
|
|
Loading…
Reference in New Issue