2014-06-27 02:05:21 +02:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-06-27 07:01:05 +02:00
|
|
|
"sync"
|
2014-06-27 02:05:21 +02:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
type UiHook struct {
|
|
|
|
terraform.NilHook
|
|
|
|
|
|
|
|
Ui cli.Ui
|
2014-06-27 07:01:05 +02:00
|
|
|
|
|
|
|
once sync.Once
|
|
|
|
ui cli.Ui
|
2014-06-27 02:05:21 +02:00
|
|
|
}
|
|
|
|
|
2014-06-27 02:18:46 +02:00
|
|
|
func (h *UiHook) PreDiff(
|
|
|
|
id string, s *terraform.ResourceState) (terraform.HookAction, error) {
|
2014-06-27 07:01:05 +02:00
|
|
|
h.once.Do(h.init)
|
|
|
|
|
|
|
|
h.ui.Output(fmt.Sprintf("%s: Calculating diff", id))
|
2014-06-27 02:18:46 +02:00
|
|
|
return terraform.HookActionContinue, nil
|
|
|
|
}
|
|
|
|
|
2014-06-27 02:05:21 +02:00
|
|
|
func (h *UiHook) PreRefresh(
|
|
|
|
id string, s *terraform.ResourceState) (terraform.HookAction, error) {
|
2014-06-27 07:01:05 +02:00
|
|
|
h.once.Do(h.init)
|
|
|
|
|
|
|
|
h.ui.Output(fmt.Sprintf("%s: Refreshing state (ID: %s)", id, s.ID))
|
2014-06-27 02:05:21 +02:00
|
|
|
return terraform.HookActionContinue, nil
|
|
|
|
}
|
2014-06-27 07:01:05 +02:00
|
|
|
|
|
|
|
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}
|
|
|
|
}
|