mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-13 09:32:24 -06:00
797a1b339d
Implement debugInfo and the DebugGraph DebugInfo will be a global variable through which graph debug information can we written to a compressed archive. The DebugInfo methods are all safe for concurrent use, and noop with a nil receiver. The API outside of the terraform package will be to call SetDebugInfo to create the archive, and CloseDebugInfo() to properly close the file. Each write to the archive will be flushed and sync'ed individually, so in the event of a crash or a missing call to Close, the archive can still be recovered. The DebugGraph is a representation of a terraform Graph to be written to the debug archive, currently in dot format. The DebugGraph also contains an internal buffer with Printf and Write methods to add to this buffer. The buffer will be written to an accompanying file in the debug archive along with the graph. This also adds a GraphNodeDebugger interface. Any node implementing `NodeDebug() string` can output information to annotate the debug graph node, and add the data to the log. This interface may change or be removed to provide richer options for debugging graph nodes. The new graph builders all delegate the build to the BasicGraphBuilder. Having a Name field lets us differentiate the actual builder implementation in the debug graphs.
60 lines
1.3 KiB
Go
60 lines
1.3 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
|
|
|
|
// Targets are resources to target
|
|
Targets []string
|
|
}
|
|
|
|
// See GraphBuilder
|
|
func (b *DestroyPlanGraphBuilder) Build(path []string) (*Graph, error) {
|
|
return (&BasicGraphBuilder{
|
|
Steps: b.Steps(),
|
|
Validate: true,
|
|
Name: "destroy",
|
|
}).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,
|
|
},
|
|
|
|
// Target
|
|
&TargetsTransformer{Targets: b.Targets},
|
|
|
|
// Attach the configuration to any resources
|
|
&AttachResourceConfigTransformer{Module: b.Module},
|
|
|
|
// Single root
|
|
&RootTransformer{},
|
|
}
|
|
|
|
return steps
|
|
}
|