From c5c7045a8955c7892ebd4e3c4d5030d12268cb17 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 2 Feb 2022 09:30:41 -0500 Subject: [PATCH] filter out non-relevant drift changes Only show drift changes which may have affected the plan output. --- internal/command/views/plan.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/command/views/plan.go b/internal/command/views/plan.go index 50b6977c1..b70a2bd58 100644 --- a/internal/command/views/plan.go +++ b/internal/command/views/plan.go @@ -331,6 +331,13 @@ func renderPlan(plan *plans.Plan, schemas *terraform.Schemas, view *View) { // line of output, and guarantees to always produce whole lines terminated // by newline characters. func renderChangesDetectedByRefresh(plan *plans.Plan, schemas *terraform.Schemas, view *View) (rendered bool) { + // If this is not a refresh-only plan, we will need to filter out any + // non-relevant changes to reduce plan output. + relevant := make(map[string]bool) + for _, r := range plan.RelevantResources { + relevant[r.String()] = true + } + // In refresh-only mode, we show all resources marked as drifted, // including those which have moved without other changes. In other plan // modes, move-only changes will be rendered in the planned changes, so @@ -340,7 +347,7 @@ func renderChangesDetectedByRefresh(plan *plans.Plan, schemas *terraform.Schemas drs = plan.DriftedResources } else { for _, dr := range plan.DriftedResources { - if dr.Action != plans.NoOp { + if dr.Action != plans.NoOp && relevant[dr.Addr.ContainingResource().String()] { drs = append(drs, dr) } }