diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/terraform/graph_builder.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/terraform/graph_builder.go | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/vendor/github.com/hashicorp/terraform/terraform/graph_builder.go b/vendor/github.com/hashicorp/terraform/terraform/graph_builder.go index 6374bb9..66b21f3 100644 --- a/vendor/github.com/hashicorp/terraform/terraform/graph_builder.go +++ b/vendor/github.com/hashicorp/terraform/terraform/graph_builder.go | |||
@@ -4,6 +4,10 @@ import ( | |||
4 | "fmt" | 4 | "fmt" |
5 | "log" | 5 | "log" |
6 | "strings" | 6 | "strings" |
7 | |||
8 | "github.com/hashicorp/terraform/tfdiags" | ||
9 | |||
10 | "github.com/hashicorp/terraform/addrs" | ||
7 | ) | 11 | ) |
8 | 12 | ||
9 | // GraphBuilder is an interface that can be implemented and used with | 13 | // GraphBuilder is an interface that can be implemented and used with |
@@ -12,7 +16,7 @@ type GraphBuilder interface { | |||
12 | // Build builds the graph for the given module path. It is up to | 16 | // Build builds the graph for the given module path. It is up to |
13 | // the interface implementation whether this build should expand | 17 | // the interface implementation whether this build should expand |
14 | // the graph or not. | 18 | // the graph or not. |
15 | Build(path []string) (*Graph, error) | 19 | Build(addrs.ModuleInstance) (*Graph, tfdiags.Diagnostics) |
16 | } | 20 | } |
17 | 21 | ||
18 | // BasicGraphBuilder is a GraphBuilder that builds a graph out of a | 22 | // BasicGraphBuilder is a GraphBuilder that builds a graph out of a |
@@ -25,21 +29,16 @@ type BasicGraphBuilder struct { | |||
25 | Name string | 29 | Name string |
26 | } | 30 | } |
27 | 31 | ||
28 | func (b *BasicGraphBuilder) Build(path []string) (*Graph, error) { | 32 | func (b *BasicGraphBuilder) Build(path addrs.ModuleInstance) (*Graph, tfdiags.Diagnostics) { |
33 | var diags tfdiags.Diagnostics | ||
29 | g := &Graph{Path: path} | 34 | g := &Graph{Path: path} |
30 | 35 | ||
31 | debugName := "graph.json" | 36 | var lastStepStr string |
32 | if b.Name != "" { | ||
33 | debugName = b.Name + "-" + debugName | ||
34 | } | ||
35 | debugBuf := dbug.NewFileWriter(debugName) | ||
36 | g.SetDebugWriter(debugBuf) | ||
37 | defer debugBuf.Close() | ||
38 | |||
39 | for _, step := range b.Steps { | 37 | for _, step := range b.Steps { |
40 | if step == nil { | 38 | if step == nil { |
41 | continue | 39 | continue |
42 | } | 40 | } |
41 | log.Printf("[TRACE] Executing graph transform %T", step) | ||
43 | 42 | ||
44 | stepName := fmt.Sprintf("%T", step) | 43 | stepName := fmt.Sprintf("%T", step) |
45 | dot := strings.LastIndex(stepName, ".") | 44 | dot := strings.LastIndex(stepName, ".") |
@@ -56,12 +55,20 @@ func (b *BasicGraphBuilder) Build(path []string) (*Graph, error) { | |||
56 | } | 55 | } |
57 | debugOp.End(errMsg) | 56 | debugOp.End(errMsg) |
58 | 57 | ||
59 | log.Printf( | 58 | if thisStepStr := g.StringWithNodeTypes(); thisStepStr != lastStepStr { |
60 | "[TRACE] Graph after step %T:\n\n%s", | 59 | log.Printf("[TRACE] Completed graph transform %T with new graph:\n%s------", step, thisStepStr) |
61 | step, g.StringWithNodeTypes()) | 60 | lastStepStr = thisStepStr |
61 | } else { | ||
62 | log.Printf("[TRACE] Completed graph transform %T (no changes)", step) | ||
63 | } | ||
62 | 64 | ||
63 | if err != nil { | 65 | if err != nil { |
64 | return g, err | 66 | if nf, isNF := err.(tfdiags.NonFatalError); isNF { |
67 | diags = diags.Append(nf.Diagnostics) | ||
68 | } else { | ||
69 | diags = diags.Append(err) | ||
70 | return g, diags | ||
71 | } | ||
65 | } | 72 | } |
66 | } | 73 | } |
67 | 74 | ||
@@ -69,9 +76,10 @@ func (b *BasicGraphBuilder) Build(path []string) (*Graph, error) { | |||
69 | if b.Validate { | 76 | if b.Validate { |
70 | if err := g.Validate(); err != nil { | 77 | if err := g.Validate(); err != nil { |
71 | log.Printf("[ERROR] Graph validation failed. Graph:\n\n%s", g.String()) | 78 | log.Printf("[ERROR] Graph validation failed. Graph:\n\n%s", g.String()) |
72 | return nil, err | 79 | diags = diags.Append(err) |
80 | return nil, diags | ||
73 | } | 81 | } |
74 | } | 82 | } |
75 | 83 | ||
76 | return g, nil | 84 | return g, diags |
77 | } | 85 | } |