]>
Commit | Line | Data |
---|---|---|
bae9f6d2 JC |
1 | package terraform |
2 | ||
3 | import ( | |
107c1cdb ND |
4 | "github.com/hashicorp/terraform/addrs" |
5 | "github.com/hashicorp/terraform/configs" | |
bae9f6d2 | 6 | "github.com/hashicorp/terraform/dag" |
107c1cdb ND |
7 | "github.com/hashicorp/terraform/states" |
8 | "github.com/hashicorp/terraform/tfdiags" | |
bae9f6d2 JC |
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. | |
16 | type DestroyPlanGraphBuilder struct { | |
107c1cdb ND |
17 | // Config is the configuration tree to build the plan from. |
18 | Config *configs.Config | |
bae9f6d2 JC |
19 | |
20 | // State is the current state | |
107c1cdb ND |
21 | State *states.State |
22 | ||
23 | // Components is a factory for the plug-in components (providers and | |
24 | // provisioners) available for use. | |
25 | Components contextComponentFactory | |
26 | ||
27 | // Schemas is the repository of schemas we will draw from to analyse | |
28 | // the configuration. | |
29 | Schemas *Schemas | |
bae9f6d2 JC |
30 | |
31 | // Targets are resources to target | |
107c1cdb | 32 | Targets []addrs.Targetable |
bae9f6d2 JC |
33 | |
34 | // Validate will do structural validation of the graph. | |
35 | Validate bool | |
36 | } | |
37 | ||
38 | // See GraphBuilder | |
107c1cdb | 39 | func (b *DestroyPlanGraphBuilder) Build(path addrs.ModuleInstance) (*Graph, tfdiags.Diagnostics) { |
bae9f6d2 JC |
40 | return (&BasicGraphBuilder{ |
41 | Steps: b.Steps(), | |
42 | Validate: b.Validate, | |
43 | Name: "DestroyPlanGraphBuilder", | |
44 | }).Build(path) | |
45 | } | |
46 | ||
47 | // See GraphBuilder | |
48 | func (b *DestroyPlanGraphBuilder) Steps() []GraphTransformer { | |
107c1cdb ND |
49 | concreteResourceInstance := func(a *NodeAbstractResourceInstance) dag.Vertex { |
50 | return &NodePlanDestroyableResourceInstance{ | |
51 | NodeAbstractResourceInstance: a, | |
52 | } | |
53 | } | |
54 | concreteResourceInstanceDeposed := func(a *NodeAbstractResourceInstance, key states.DeposedKey) dag.Vertex { | |
55 | return &NodePlanDeposedResourceInstanceObject{ | |
56 | NodeAbstractResourceInstance: a, | |
57 | DeposedKey: key, | |
58 | } | |
59 | } | |
60 | ||
61 | concreteProvider := func(a *NodeAbstractProvider) dag.Vertex { | |
62 | return &NodeApplyableProvider{ | |
63 | NodeAbstractProvider: a, | |
bae9f6d2 JC |
64 | } |
65 | } | |
66 | ||
67 | steps := []GraphTransformer{ | |
107c1cdb | 68 | // Creates nodes for the resource instances tracked in the state. |
bae9f6d2 | 69 | &StateTransformer{ |
107c1cdb ND |
70 | ConcreteCurrent: concreteResourceInstance, |
71 | ConcreteDeposed: concreteResourceInstanceDeposed, | |
72 | State: b.State, | |
bae9f6d2 JC |
73 | }, |
74 | ||
75 | // Attach the configuration to any resources | |
107c1cdb ND |
76 | &AttachResourceConfigTransformer{Config: b.Config}, |
77 | ||
78 | TransformProviders(b.Components.ResourceProviders(), concreteProvider, b.Config), | |
bae9f6d2 JC |
79 | |
80 | // Destruction ordering. We require this only so that | |
81 | // targeting below will prune the correct things. | |
107c1cdb ND |
82 | &DestroyEdgeTransformer{ |
83 | Config: b.Config, | |
84 | State: b.State, | |
85 | Schemas: b.Schemas, | |
86 | }, | |
bae9f6d2 JC |
87 | |
88 | // Target. Note we don't set "Destroy: true" here since we already | |
89 | // created proper destroy ordering. | |
90 | &TargetsTransformer{Targets: b.Targets}, | |
91 | ||
92 | // Single root | |
93 | &RootTransformer{}, | |
94 | } | |
95 | ||
96 | return steps | |
97 | } |