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