Skip to content

Commit 169ad00

Browse files
actions: add number of invoked actions to plan summary
1 parent 2236ecd commit 169ad00

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

internal/command/jsonformat/plan.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ func (plan Plan) renderHuman(renderer Renderer, mode plans.Mode, opts ...plans.Q
9494
// Precompute the outputs and actions early, so we can make a decision about whether we
9595
// display the "there are no changes messages".
9696
outputs := renderHumanDiffOutputs(renderer, diffs.outputs)
97-
actions, actionCount := renderHumanActionInvocations(renderer, diffs.actions)
97+
actions := renderHumanActionInvocations(renderer, diffs.actions)
98+
actionCount := len(plan.ActionInvocations) // diffs.actions is just the CLI-invoked actions
9899

99100
if len(changes) == 0 && len(outputs) == 0 && actionCount == 0 {
100101
// If we didn't find any changes to report at all then this is a
@@ -224,7 +225,7 @@ func (plan Plan) renderHuman(renderer Renderer, mode plans.Mode, opts ...plans.Q
224225
}
225226
}
226227

227-
if len(changes) > 0 {
228+
if len(changes) > 0 || actionCount > 0 {
228229
if checkOpts(plans.Errored) {
229230
renderer.Streams.Printf("\nTerraform planned the following actions, but then encountered a problem:\n")
230231
} else {
@@ -239,20 +240,23 @@ func (plan Plan) renderHuman(renderer Renderer, mode plans.Mode, opts ...plans.Q
239240
}
240241
}
241242

243+
var buf strings.Builder
244+
buf.WriteString(renderer.Colorize.Color("\n[bold]Plan:[reset] "))
242245
if importingCount > 0 {
243-
renderer.Streams.Printf(
244-
renderer.Colorize.Color("\n[bold]Plan:[reset] %d to import, %d to add, %d to change, %d to destroy.\n"),
245-
importingCount,
246-
counts[plans.Create]+counts[plans.DeleteThenCreate]+counts[plans.CreateThenDelete],
247-
counts[plans.Update],
248-
counts[plans.Delete]+counts[plans.DeleteThenCreate]+counts[plans.CreateThenDelete])
249-
} else {
250-
renderer.Streams.Printf(
251-
renderer.Colorize.Color("\n[bold]Plan:[reset] %d to add, %d to change, %d to destroy.\n"),
252-
counts[plans.Create]+counts[plans.DeleteThenCreate]+counts[plans.CreateThenDelete],
253-
counts[plans.Update],
254-
counts[plans.Delete]+counts[plans.DeleteThenCreate]+counts[plans.CreateThenDelete])
246+
buf.WriteString(fmt.Sprintf("%d to import, ", importingCount))
247+
}
248+
buf.WriteString(fmt.Sprintf("%d to add, %d to change, %d to destroy.",
249+
counts[plans.Create]+counts[plans.DeleteThenCreate]+counts[plans.CreateThenDelete],
250+
counts[plans.Update],
251+
counts[plans.Delete]+counts[plans.DeleteThenCreate]+counts[plans.CreateThenDelete]),
252+
)
253+
254+
if actionCount > 0 {
255+
buf.WriteString(fmt.Sprintf(" Actions: %d to invoke.", actionCount))
255256
}
257+
buf.WriteString("\n")
258+
259+
renderer.Streams.Print(buf.String())
256260
}
257261

258262
if len(actions) > 0 {
@@ -502,13 +506,13 @@ func renderHumanDeferredDiff(renderer Renderer, deferred deferredDiff) (string,
502506

503507
// All actions that run based on the resource lifecycle should be rendered as part of the resource
504508
// changes, therefore this function only renders actions that are invoked by the CLI
505-
func renderHumanActionInvocations(renderer Renderer, actionInvocations []actionInvocation) (string, int) {
509+
func renderHumanActionInvocations(renderer Renderer, actionInvocations []actionInvocation) string {
506510
var invocations []string
507511
for _, invocation := range actionInvocations {
508512
header := fmt.Sprintf(renderer.Colorize.Color(" [bold]# %s[reset] will be invoked"), invocation.invocation.Address)
509513
invocations = append(invocations, fmt.Sprintf("%s\n%s", header, renderActionInvocation(renderer, invocation)))
510514
}
511-
return strings.Join(invocations, "\n"), len(invocations)
515+
return strings.Join(invocations, "\n")
512516
}
513517

514518
func resourceChangeComment(resource jsonplan.ResourceChange, action plans.Action, changeCause string) string {

0 commit comments

Comments
 (0)