github.com/opentofu/opentofu@v1.7.1/internal/tofu/reduce_plan.go (about) 1 // Copyright (c) The OpenTofu Authors 2 // SPDX-License-Identifier: MPL-2.0 3 // Copyright (c) 2023 HashiCorp, Inc. 4 // SPDX-License-Identifier: MPL-2.0 5 6 package tofu 7 8 import ( 9 "log" 10 11 "github.com/opentofu/opentofu/internal/addrs" 12 "github.com/opentofu/opentofu/internal/plans" 13 ) 14 15 // reducePlan takes a planned resource instance change as might be produced by 16 // Plan or PlanDestroy and "simplifies" it to a single atomic action to be 17 // performed by a specific graph node. 18 // 19 // Callers must specify whether they are a destroy node or a regular apply node. 20 // If the result is NoOp then the given change requires no action for the 21 // specific graph node calling this and so evaluation of the that graph node 22 // should exit early and take no action. 23 // 24 // The returned object may either be identical to the input change or a new 25 // change object derived from the input. Because of the former case, the caller 26 // must not mutate the object returned in OutChange. 27 func reducePlan(addr addrs.ResourceInstance, in *plans.ResourceInstanceChange, destroy bool) *plans.ResourceInstanceChange { 28 out := in.Simplify(destroy) 29 if out.Action != in.Action { 30 if destroy { 31 log.Printf("[TRACE] reducePlan: %s change simplified from %s to %s for destroy node", addr, in.Action, out.Action) 32 } else { 33 log.Printf("[TRACE] reducePlan: %s change simplified from %s to %s for apply node", addr, in.Action, out.Action) 34 } 35 } 36 return out 37 }