github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/not-internal/terraform/node_resource_plan_destroy.go (about) 1 package terraform 2 3 import ( 4 "github.com/muratcelep/terraform/not-internal/addrs" 5 "github.com/muratcelep/terraform/not-internal/plans" 6 "github.com/muratcelep/terraform/not-internal/states" 7 "github.com/muratcelep/terraform/not-internal/tfdiags" 8 ) 9 10 // NodePlanDestroyableResourceInstance represents a resource that is ready 11 // to be planned for destruction. 12 type NodePlanDestroyableResourceInstance struct { 13 *NodeAbstractResourceInstance 14 15 // skipRefresh indicates that we should skip refreshing 16 skipRefresh bool 17 } 18 19 var ( 20 _ GraphNodeModuleInstance = (*NodePlanDestroyableResourceInstance)(nil) 21 _ GraphNodeReferenceable = (*NodePlanDestroyableResourceInstance)(nil) 22 _ GraphNodeReferencer = (*NodePlanDestroyableResourceInstance)(nil) 23 _ GraphNodeDestroyer = (*NodePlanDestroyableResourceInstance)(nil) 24 _ GraphNodeConfigResource = (*NodePlanDestroyableResourceInstance)(nil) 25 _ GraphNodeResourceInstance = (*NodePlanDestroyableResourceInstance)(nil) 26 _ GraphNodeAttachResourceConfig = (*NodePlanDestroyableResourceInstance)(nil) 27 _ GraphNodeAttachResourceState = (*NodePlanDestroyableResourceInstance)(nil) 28 _ GraphNodeExecutable = (*NodePlanDestroyableResourceInstance)(nil) 29 _ GraphNodeProviderConsumer = (*NodePlanDestroyableResourceInstance)(nil) 30 ) 31 32 // GraphNodeDestroyer 33 func (n *NodePlanDestroyableResourceInstance) DestroyAddr() *addrs.AbsResourceInstance { 34 addr := n.ResourceInstanceAddr() 35 return &addr 36 } 37 38 // GraphNodeEvalable 39 func (n *NodePlanDestroyableResourceInstance) Execute(ctx EvalContext, op walkOperation) (diags tfdiags.Diagnostics) { 40 addr := n.ResourceInstanceAddr() 41 42 // Declare a bunch of variables that are used for state during 43 // evaluation. These are written to by address in the EvalNodes we 44 // declare below. 45 var change *plans.ResourceInstanceChange 46 var state *states.ResourceInstanceObject 47 48 state, err := n.readResourceInstanceState(ctx, addr) 49 diags = diags.Append(err) 50 if diags.HasErrors() { 51 return diags 52 } 53 54 // If we are in the "skip refresh" mode then we will have skipped over our 55 // usual opportunity to update the previous run state and refresh state 56 // with the result of any provider schema upgrades, so we'll compensate 57 // by doing that here. 58 // 59 // NOTE: this is coupled with logic in Context.destroyPlan which skips 60 // running a normal plan walk when refresh is enabled. These two 61 // conditionals must agree (be exactly opposite) in order to get the 62 // correct behavior in both cases. 63 if n.skipRefresh { 64 diags = diags.Append(n.writeResourceInstanceState(ctx, state, prevRunState)) 65 if diags.HasErrors() { 66 return diags 67 } 68 diags = diags.Append(n.writeResourceInstanceState(ctx, state, refreshState)) 69 if diags.HasErrors() { 70 return diags 71 } 72 } 73 74 change, destroyPlanDiags := n.planDestroy(ctx, state, "") 75 diags = diags.Append(destroyPlanDiags) 76 if diags.HasErrors() { 77 return diags 78 } 79 80 diags = diags.Append(n.checkPreventDestroy(change)) 81 if diags.HasErrors() { 82 return diags 83 } 84 85 diags = diags.Append(n.writeChange(ctx, change, "")) 86 return diags 87 }