diff --git a/command/hook_count.go b/command/hook_count.go index 21e1ea160..3d3d534dd 100644 --- a/command/hook_count.go +++ b/command/hook_count.go @@ -13,6 +13,11 @@ type CountHook struct { Changed int Removed int + ToAdd int + ToChange int + ToRemove int + ToRemoveAndAdd int + pending map[string]countHookAction sync.Mutex @@ -86,3 +91,23 @@ func (h *CountHook) PostApply( return terraform.HookActionContinue, nil } + +func (h *CountHook) PostDiff( + n *terraform.InstanceInfo, d *terraform.InstanceDiff) ( + terraform.HookAction, error) { + h.Lock() + defer h.Unlock() + + switch d.ChangeType() { + case terraform.DiffDestroyCreate: + h.ToRemoveAndAdd += 1 + case terraform.DiffCreate: + h.ToAdd += 1 + case terraform.DiffDestroy: + h.ToRemove += 1 + default: + h.ToChange += 1 + } + + return terraform.HookActionContinue, nil +} diff --git a/command/plan.go b/command/plan.go index 283beba49..f5a478873 100644 --- a/command/plan.go +++ b/command/plan.go @@ -53,6 +53,9 @@ func (c *PlanCommand) Run(args []string) int { } } + countHook := new(CountHook) + c.Meta.extraHooks = []terraform.Hook{countHook} + ctx, _, err := c.Context(contextOpts{ Destroy: destroy, Path: path, @@ -130,6 +133,13 @@ func (c *PlanCommand) Run(args []string) int { ModuleDepth: moduleDepth, })) + c.Ui.Output(c.Colorize().Color(fmt.Sprintf( + "[reset][bold]Plan:[reset] "+ + "%d to add, %d to change, %d to destroy.", + countHook.ToAdd, + (countHook.ToChange + countHook.ToRemoveAndAdd), + countHook.ToRemove))) + if detailed { return 2 }