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.
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package terraform
|
|
|
|
import "github.com/hashicorp/terraform/dot"
|
|
|
|
// GraphNodeDotter can be implemented by a node to cause it to be included
|
|
// in the dot graph. The Dot method will be called which is expected to
|
|
// return a representation of this node.
|
|
type GraphNodeDotter interface {
|
|
// Dot is called to return the dot formatting for the node.
|
|
// The first parameter is the title of the node.
|
|
// The second parameter includes user-specified options that affect the dot
|
|
// graph. See GraphDotOpts below for details.
|
|
DotNode(string, *GraphDotOpts) *dot.Node
|
|
}
|
|
|
|
// GraphDotOpts are the options for generating a dot formatted Graph.
|
|
type GraphDotOpts struct {
|
|
// Allows some nodes to decide to only show themselves when the user has
|
|
// requested the "verbose" graph.
|
|
Verbose bool
|
|
|
|
// Highlight Cycles
|
|
DrawCycles bool
|
|
|
|
// How many levels to expand modules as we draw
|
|
MaxDepth int
|
|
}
|
|
|
|
// GraphDot returns the dot formatting of a visual representation of
|
|
// the given Terraform graph.
|
|
func GraphDot(g *Graph, opts *GraphDotOpts) (string, error) {
|
|
dg, err := NewDebugGraph("root", g, opts)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return dg.Dot.String(), nil
|
|
}
|