9 // GraphBuilder is an interface that can be implemented and used with
10 // Terraform to build the graph that Terraform walks.
11 type GraphBuilder interface {
12 // Build builds the graph for the given module path. It is up to
13 // the interface implementation whether this build should expand
15 Build(path []string) (*Graph, error)
18 // BasicGraphBuilder is a GraphBuilder that builds a graph out of a
19 // series of transforms and (optionally) validates the graph is a valid
21 type BasicGraphBuilder struct {
22 Steps []GraphTransformer
24 // Optional name to add to the graph debug log
28 func (b *BasicGraphBuilder) Build(path []string) (*Graph, error) {
29 g := &Graph{Path: path}
31 debugName := "graph.json"
33 debugName = b.Name + "-" + debugName
35 debugBuf := dbug.NewFileWriter(debugName)
36 g.SetDebugWriter(debugBuf)
37 defer debugBuf.Close()
39 for _, step := range b.Steps {
44 stepName := fmt.Sprintf("%T", step)
45 dot := strings.LastIndex(stepName, ".")
47 stepName = stepName[dot+1:]
50 debugOp := g.DebugOperation(stepName, "")
51 err := step.Transform(g)
60 "[TRACE] Graph after step %T:\n\n%s",
61 step, g.StringWithNodeTypes())
68 // Validate the graph structure
70 if err := g.Validate(); err != nil {
71 log.Printf("[ERROR] Graph validation failed. Graph:\n\n%s", g.String())