command/apply: outputs
This commit is contained in:
parent
00ebedb4fb
commit
52d29a6ecf
|
@ -1,9 +1,11 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
|
@ -130,6 +132,36 @@ func (c *ApplyCommand) Run(args []string) int {
|
|||
"State path: %s",
|
||||
stateOutPath)))
|
||||
|
||||
// If we have outputs, then output those at the end.
|
||||
if len(state.Outputs) > 0 {
|
||||
outputBuf := new(bytes.Buffer)
|
||||
outputBuf.WriteString("[reset][bold][green]\nOutputs:\n\n")
|
||||
|
||||
// Output the outputs in alphabetical order
|
||||
keyLen := 0
|
||||
keys := make([]string, 0, len(state.Outputs))
|
||||
for key, _ := range state.Outputs {
|
||||
keys = append(keys, key)
|
||||
if len(key) > keyLen {
|
||||
keyLen = len(key)
|
||||
}
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
for _, k := range keys {
|
||||
v := state.Outputs[k]
|
||||
|
||||
outputBuf.WriteString(fmt.Sprintf(
|
||||
" %s%s = %s\n",
|
||||
k,
|
||||
strings.Repeat(" ", keyLen-len(k)),
|
||||
v))
|
||||
}
|
||||
|
||||
c.Ui.Output(c.Colorize().Color(
|
||||
strings.TrimSpace(outputBuf.String())))
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
@ -71,11 +71,16 @@ func (h *UiHook) PreApply(
|
|||
v))
|
||||
}
|
||||
|
||||
attrString := strings.TrimSpace(attrBuf.String())
|
||||
if attrString != "" {
|
||||
attrString = "\n " + attrString
|
||||
}
|
||||
|
||||
h.ui.Output(h.Colorize.Color(fmt.Sprintf(
|
||||
"[reset][bold]%s: %s[reset_bold]\n %s",
|
||||
"[reset][bold]%s: %s[reset_bold]%s",
|
||||
id,
|
||||
operation,
|
||||
strings.TrimSpace(attrBuf.String()))))
|
||||
attrString)))
|
||||
|
||||
return terraform.HookActionContinue, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue