diff --git a/command/hook_ui.go b/command/hook_ui.go index 5b0b8d0d1..43b27fb99 100644 --- a/command/hook_ui.go +++ b/command/hook_ui.go @@ -2,6 +2,7 @@ package command import ( "fmt" + "sync" "github.com/hashicorp/terraform/terraform" "github.com/mitchellh/cli" @@ -11,16 +12,29 @@ type UiHook struct { terraform.NilHook Ui cli.Ui + + once sync.Once + ui cli.Ui } func (h *UiHook) PreDiff( id string, s *terraform.ResourceState) (terraform.HookAction, error) { - h.Ui.Output(fmt.Sprintf("Calculating diff for %s", id)) + h.once.Do(h.init) + + h.ui.Output(fmt.Sprintf("%s: Calculating diff", id)) return terraform.HookActionContinue, nil } func (h *UiHook) PreRefresh( id string, s *terraform.ResourceState) (terraform.HookAction, error) { - h.Ui.Output(fmt.Sprintf("Refreshing state for %s (ID: %s)", id, s.ID)) + h.once.Do(h.init) + + h.ui.Output(fmt.Sprintf("%s: Refreshing state (ID: %s)", id, s.ID)) return terraform.HookActionContinue, nil } + +func (h *UiHook) init() { + // Wrap the ui so that it is safe for concurrency regardless of the + // underlying reader/writer that is in place. + h.ui = &cli.ConcurrentUi{Ui: h.Ui} +}