mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
|
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
|
||
|
}
|
||
|
|
||
|
// See GraphBuilder
|
||
|
func (b *DestroyPlanGraphBuilder) Build(path []string) (*Graph, error) {
|
||
|
return (&BasicGraphBuilder{
|
||
|
Steps: b.Steps(),
|
||
|
Validate: true,
|
||
|
}).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,
|
||
|
},
|
||
|
|
||
|
// Single root
|
||
|
&RootTransformer{},
|
||
|
}
|
||
|
|
||
|
return steps
|
||
|
}
|