kubeform.dev/terraform-backend-sdk@v0.0.0-20220310143633-45f07fe731c5/terraform/graph_builder_destroy_plan.go (about) 1 package terraform 2 3 import ( 4 "kubeform.dev/terraform-backend-sdk/addrs" 5 "kubeform.dev/terraform-backend-sdk/configs" 6 "kubeform.dev/terraform-backend-sdk/dag" 7 "kubeform.dev/terraform-backend-sdk/states" 8 "kubeform.dev/terraform-backend-sdk/tfdiags" 9 ) 10 11 // DestroyPlanGraphBuilder implements GraphBuilder and is responsible for 12 // planning a pure-destroy. 13 // 14 // Planning a pure destroy operation is simple because we can ignore most 15 // ordering configuration and simply reverse the state. This graph mainly 16 // exists for targeting, because we need to walk the destroy dependencies to 17 // ensure we plan the required resources. Without the requirement for 18 // targeting, the plan could theoretically be created directly from the state. 19 type DestroyPlanGraphBuilder struct { 20 // Config is the configuration tree to build the plan from. 21 Config *configs.Config 22 23 // State is the current state 24 State *states.State 25 26 // Plugins is a library of plug-in components (providers and 27 // provisioners) available for use. 28 Plugins *contextPlugins 29 30 // Targets are resources to target 31 Targets []addrs.Targetable 32 33 // Validate will do structural validation of the graph. 34 Validate bool 35 36 // If set, skipRefresh will cause us stop skip refreshing any existing 37 // resource instances as part of our planning. This will cause us to fail 38 // to detect if an object has already been deleted outside of Terraform. 39 skipRefresh bool 40 } 41 42 // See GraphBuilder 43 func (b *DestroyPlanGraphBuilder) Build(path addrs.ModuleInstance) (*Graph, tfdiags.Diagnostics) { 44 return (&BasicGraphBuilder{ 45 Steps: b.Steps(), 46 Validate: b.Validate, 47 Name: "DestroyPlanGraphBuilder", 48 }).Build(path) 49 } 50 51 // See GraphBuilder 52 func (b *DestroyPlanGraphBuilder) Steps() []GraphTransformer { 53 concreteResourceInstance := func(a *NodeAbstractResourceInstance) dag.Vertex { 54 return &NodePlanDestroyableResourceInstance{ 55 NodeAbstractResourceInstance: a, 56 skipRefresh: b.skipRefresh, 57 } 58 } 59 concreteResourceInstanceDeposed := func(a *NodeAbstractResourceInstance, key states.DeposedKey) dag.Vertex { 60 return &NodePlanDeposedResourceInstanceObject{ 61 NodeAbstractResourceInstance: a, 62 DeposedKey: key, 63 skipRefresh: b.skipRefresh, 64 } 65 } 66 67 concreteProvider := func(a *NodeAbstractProvider) dag.Vertex { 68 return &NodeApplyableProvider{ 69 NodeAbstractProvider: a, 70 } 71 } 72 73 steps := []GraphTransformer{ 74 // Creates nodes for the resource instances tracked in the state. 75 &StateTransformer{ 76 ConcreteCurrent: concreteResourceInstance, 77 ConcreteDeposed: concreteResourceInstanceDeposed, 78 State: b.State, 79 }, 80 81 // Create the delete changes for root module outputs. 82 &OutputTransformer{ 83 Config: b.Config, 84 Destroy: true, 85 }, 86 87 // Attach the state 88 &AttachStateTransformer{State: b.State}, 89 90 // Attach the configuration to any resources 91 &AttachResourceConfigTransformer{Config: b.Config}, 92 93 transformProviders(concreteProvider, b.Config), 94 95 // Destruction ordering. We require this only so that 96 // targeting below will prune the correct things. 97 &DestroyEdgeTransformer{ 98 Config: b.Config, 99 State: b.State, 100 }, 101 102 &TargetsTransformer{Targets: b.Targets}, 103 104 // Close opened plugin connections 105 &CloseProviderTransformer{}, 106 107 // Close the root module 108 &CloseRootModuleTransformer{}, 109 110 &TransitiveReductionTransformer{}, 111 } 112 113 return steps 114 }