diff --git a/command/apply.go b/command/apply.go index 1864d0593..0276d9847 100644 --- a/command/apply.go +++ b/command/apply.go @@ -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 } diff --git a/command/hook_ui.go b/command/hook_ui.go index 3f4d9bf5f..eba23c6e3 100644 --- a/command/hook_ui.go +++ b/command/hook_ui.go @@ -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 }