]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/hashicorp/terraform/terraform/transform_config_flat.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / terraform / transform_config_flat.go
1 package terraform
2
3 import (
4 "github.com/hashicorp/terraform/configs"
5 "github.com/hashicorp/terraform/dag"
6 )
7
8 // FlatConfigTransformer is a GraphTransformer that adds the configuration
9 // to the graph. The module used to configure this transformer must be
10 // the root module.
11 //
12 // This transform adds the nodes but doesn't connect any of the references.
13 // The ReferenceTransformer should be used for that.
14 //
15 // NOTE: In relation to ConfigTransformer: this is a newer generation config
16 // transformer. It puts the _entire_ config into the graph (there is no
17 // "flattening" step as before).
18 type FlatConfigTransformer struct {
19 Concrete ConcreteResourceNodeFunc // What to turn resources into
20
21 Config *configs.Config
22 }
23
24 func (t *FlatConfigTransformer) Transform(g *Graph) error {
25 // We have nothing to do if there is no configuration.
26 if t.Config == nil {
27 return nil
28 }
29
30 return t.transform(g, t.Config)
31 }
32
33 func (t *FlatConfigTransformer) transform(g *Graph, config *configs.Config) error {
34 // If we have no configuration then there's nothing to do.
35 if config == nil {
36 return nil
37 }
38
39 // Transform all the children.
40 for _, c := range config.Children {
41 if err := t.transform(g, c); err != nil {
42 return err
43 }
44 }
45
46 module := config.Module
47 // For now we assume that each module call produces only one module
48 // instance with no key, since we don't yet support "count" and "for_each"
49 // on modules.
50 // FIXME: As part of supporting "count" and "for_each" on modules, rework
51 // this so that we'll "expand" the module call first and then create graph
52 // nodes for each module instance separately.
53 instPath := config.Path.UnkeyedInstanceShim()
54
55 for _, r := range module.ManagedResources {
56 addr := r.Addr().Absolute(instPath)
57 abstract := &NodeAbstractResource{
58 Addr: addr,
59 Config: r,
60 }
61 // Grab the address for this resource
62 var node dag.Vertex = abstract
63 if f := t.Concrete; f != nil {
64 node = f(abstract)
65 }
66
67 g.Add(node)
68 }
69
70 return nil
71 }