Add resource sums to terraform plan

- closes #2355
This commit is contained in:
Radek Simko 2015-06-24 11:32:15 +01:00
parent 134cf1ce82
commit b505d15e1e
2 changed files with 35 additions and 0 deletions

View File

@ -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
}

View File

@ -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
}