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.
This commit is contained in:
Alisdair McDiarmid 2020-11-02 10:22:37 -05:00
parent a413fa7425
commit b335918c3c
3 changed files with 19 additions and 2 deletions

View File

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

View File

@ -1,3 +1,7 @@
module "submodule" {
source = "./submodule"
}
output "changed" {
value = "after"
}

View File

@ -0,0 +1,3 @@
output "foo" {
value = "bar"
}