From b335918c3c49c24455904328c0c59251a919a796 Mon Sep 17 00:00:00 2001 From: Alisdair McDiarmid Date: Mon, 2 Nov 2020 10:22:37 -0500 Subject: [PATCH] backend: Only show root module output changes When rendering planned output changes, we need to filter the plan's output changes to ensure that only root module outputs which have changed are rendered. Otherwise we will render changes for submodule outputs, and (with concise diff disabled) render unchanged outputs also. --- backend/local/backend_plan.go | 14 ++++++++++++-- .../local/testdata/plan-outputs-changed/main.tf | 4 ++++ .../plan-outputs-changed/submodule/main.tf | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 backend/local/testdata/plan-outputs-changed/submodule/main.tf diff --git a/backend/local/backend_plan.go b/backend/local/backend_plan.go index 0fbb0b58a..a5733473c 100644 --- a/backend/local/backend_plan.go +++ b/backend/local/backend_plan.go @@ -314,8 +314,18 @@ func RenderPlan(plan *plans.Plan, baseState *states.State, schemas *terraform.Sc // If there is at least one planned change to the root module outputs // then we'll render a summary of those too. - if len(plan.Changes.Outputs) > 0 { - ui.Output(colorize.Color("[reset]\n[bold]Changes to Outputs:[reset]" + format.OutputChanges(plan.Changes.Outputs, colorize))) + var changedRootModuleOutputs []*plans.OutputChangeSrc + for _, output := range plan.Changes.Outputs { + if !output.Addr.Module.IsRoot() { + continue + } + if output.ChangeSrc.Action == plans.NoOp { + continue + } + changedRootModuleOutputs = append(changedRootModuleOutputs, output) + } + if len(changedRootModuleOutputs) > 0 { + ui.Output(colorize.Color("[reset]\n[bold]Changes to Outputs:[reset]" + format.OutputChanges(changedRootModuleOutputs, colorize))) } } diff --git a/backend/local/testdata/plan-outputs-changed/main.tf b/backend/local/testdata/plan-outputs-changed/main.tf index c1686a89e..1df236ff4 100644 --- a/backend/local/testdata/plan-outputs-changed/main.tf +++ b/backend/local/testdata/plan-outputs-changed/main.tf @@ -1,3 +1,7 @@ +module "submodule" { + source = "./submodule" +} + output "changed" { value = "after" } diff --git a/backend/local/testdata/plan-outputs-changed/submodule/main.tf b/backend/local/testdata/plan-outputs-changed/submodule/main.tf new file mode 100644 index 000000000..ae32f8aa1 --- /dev/null +++ b/backend/local/testdata/plan-outputs-changed/submodule/main.tf @@ -0,0 +1,3 @@ +output "foo" { + value = "bar" +}