2016-10-19 02:59:56 -05:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/terraform/config/module"
|
|
|
|
"github.com/hashicorp/terraform/dag"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DestroyPlanGraphBuilder implements GraphBuilder and is responsible for
|
|
|
|
// planning a pure-destroy.
|
|
|
|
//
|
|
|
|
// Planning a pure destroy operation is simple because we can ignore most
|
|
|
|
// ordering configuration and simply reverse the state.
|
|
|
|
type DestroyPlanGraphBuilder struct {
|
|
|
|
// Module is the root module for the graph to build.
|
|
|
|
Module *module.Tree
|
|
|
|
|
|
|
|
// State is the current state
|
|
|
|
State *State
|
2016-10-20 20:59:02 -05:00
|
|
|
|
|
|
|
// Targets are resources to target
|
|
|
|
Targets []string
|
2016-10-19 02:59:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// See GraphBuilder
|
|
|
|
func (b *DestroyPlanGraphBuilder) Build(path []string) (*Graph, error) {
|
|
|
|
return (&BasicGraphBuilder{
|
|
|
|
Steps: b.Steps(),
|
|
|
|
Validate: true,
|
2016-11-04 10:30:51 -05:00
|
|
|
Name: "destroy",
|
2016-10-19 02:59:56 -05:00
|
|
|
}).Build(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
// See GraphBuilder
|
|
|
|
func (b *DestroyPlanGraphBuilder) Steps() []GraphTransformer {
|
|
|
|
concreteResource := func(a *NodeAbstractResource) dag.Vertex {
|
|
|
|
return &NodePlanDestroyableResource{
|
|
|
|
NodeAbstractResource: a,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
steps := []GraphTransformer{
|
|
|
|
// Creates all the nodes represented in the state.
|
|
|
|
&StateTransformer{
|
|
|
|
Concrete: concreteResource,
|
|
|
|
State: b.State,
|
|
|
|
},
|
|
|
|
|
2016-10-19 11:44:00 -05:00
|
|
|
// Attach the configuration to any resources
|
|
|
|
&AttachResourceConfigTransformer{Module: b.Module},
|
|
|
|
|
2016-11-10 23:14:44 -06:00
|
|
|
// Destruction ordering. We require this only so that
|
|
|
|
// targeting below will prune the correct things.
|
|
|
|
&DestroyEdgeTransformer{Module: b.Module, State: b.State},
|
|
|
|
|
|
|
|
// Target. Note we don't set "Destroy: true" here since we already
|
|
|
|
// created proper destroy ordering.
|
|
|
|
&TargetsTransformer{Targets: b.Targets},
|
|
|
|
|
2016-10-19 02:59:56 -05:00
|
|
|
// Single root
|
|
|
|
&RootTransformer{},
|
|
|
|
}
|
|
|
|
|
|
|
|
return steps
|
|
|
|
}
|