Merge pull request #2458 from TimeIncOSS/f-plan-resource-counts
Add resource sums to terraform plan
This commit is contained in:
commit
8c866a4510
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue