github.com/rhenning/terraform@v0.8.0-beta2/terraform/graph_builder_destroy_plan.go (about) 1 package terraform 2 3 import ( 4 "github.com/hashicorp/terraform/config/module" 5 "github.com/hashicorp/terraform/dag" 6 ) 7 8 // DestroyPlanGraphBuilder implements GraphBuilder and is responsible for 9 // planning a pure-destroy. 10 // 11 // Planning a pure destroy operation is simple because we can ignore most 12 // ordering configuration and simply reverse the state. 13 type DestroyPlanGraphBuilder struct { 14 // Module is the root module for the graph to build. 15 Module *module.Tree 16 17 // State is the current state 18 State *State 19 20 // Targets are resources to target 21 Targets []string 22 } 23 24 // See GraphBuilder 25 func (b *DestroyPlanGraphBuilder) Build(path []string) (*Graph, error) { 26 return (&BasicGraphBuilder{ 27 Steps: b.Steps(), 28 Validate: true, 29 Name: "destroy", 30 }).Build(path) 31 } 32 33 // See GraphBuilder 34 func (b *DestroyPlanGraphBuilder) Steps() []GraphTransformer { 35 concreteResource := func(a *NodeAbstractResource) dag.Vertex { 36 return &NodePlanDestroyableResource{ 37 NodeAbstractResource: a, 38 } 39 } 40 41 steps := []GraphTransformer{ 42 // Creates all the nodes represented in the state. 43 &StateTransformer{ 44 Concrete: concreteResource, 45 State: b.State, 46 }, 47 48 // Attach the configuration to any resources 49 &AttachResourceConfigTransformer{Module: b.Module}, 50 51 // Destruction ordering. We require this only so that 52 // targeting below will prune the correct things. 53 &DestroyEdgeTransformer{Module: b.Module, State: b.State}, 54 55 // Target. Note we don't set "Destroy: true" here since we already 56 // created proper destroy ordering. 57 &TargetsTransformer{Targets: b.Targets}, 58 59 // Single root 60 &RootTransformer{}, 61 } 62 63 return steps 64 }