github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/terraform/transform_output.go (about) 1 package terraform 2 3 import ( 4 "log" 5 6 "github.com/hashicorp/terraform/internal/addrs" 7 "github.com/hashicorp/terraform/internal/configs" 8 ) 9 10 // OutputTransformer is a GraphTransformer that adds all the outputs 11 // in the configuration to the graph. 12 // 13 // This is done for the apply graph builder even if dependent nodes 14 // aren't changing since there is no downside: the state will be available 15 // even if the dependent items aren't changing. 16 type OutputTransformer struct { 17 Config *configs.Config 18 19 // Refresh-only mode means that any failing output preconditions are 20 // reported as warnings rather than errors 21 RefreshOnly bool 22 23 // Planning must be set to true only when we're building a planning graph. 24 // It must be set to false whenever we're building an apply graph. 25 Planning bool 26 27 // If this is a planned destroy, root outputs are still in the configuration 28 // so we need to record that we wish to remove them 29 PlanDestroy bool 30 31 // ApplyDestroy indicates that this is being added to an apply graph, which 32 // is the result of a destroy plan. 33 ApplyDestroy bool 34 } 35 36 func (t *OutputTransformer) Transform(g *Graph) error { 37 return t.transform(g, t.Config) 38 } 39 40 func (t *OutputTransformer) transform(g *Graph, c *configs.Config) error { 41 // If we have no config then there can be no outputs. 42 if c == nil { 43 return nil 44 } 45 46 // Transform all the children. We must do this first because 47 // we can reference module outputs and they must show up in the 48 // reference map. 49 for _, cc := range c.Children { 50 if err := t.transform(g, cc); err != nil { 51 return err 52 } 53 } 54 55 for _, o := range c.Module.Outputs { 56 addr := addrs.OutputValue{Name: o.Name} 57 58 node := &nodeExpandOutput{ 59 Addr: addr, 60 Module: c.Path, 61 Config: o, 62 PlanDestroy: t.PlanDestroy, 63 ApplyDestroy: t.ApplyDestroy, 64 RefreshOnly: t.RefreshOnly, 65 Planning: t.Planning, 66 } 67 68 log.Printf("[TRACE] OutputTransformer: adding %s as %T", o.Name, node) 69 g.Add(node) 70 } 71 72 return nil 73 }