]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blame - 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
CommitLineData
bae9f6d2
JC
1package terraform
2
3import (
107c1cdb 4 "github.com/hashicorp/terraform/configs"
bae9f6d2
JC
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).
18type FlatConfigTransformer struct {
19 Concrete ConcreteResourceNodeFunc // What to turn resources into
20
107c1cdb 21 Config *configs.Config
bae9f6d2
JC
22}
23
24func (t *FlatConfigTransformer) Transform(g *Graph) error {
107c1cdb
ND
25 // We have nothing to do if there is no configuration.
26 if t.Config == nil {
bae9f6d2
JC
27 return nil
28 }
29
107c1cdb 30 return t.transform(g, t.Config)
bae9f6d2
JC
31}
32
107c1cdb
ND
33func (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 {
bae9f6d2
JC
36 return nil
37 }
38
39 // Transform all the children.
107c1cdb 40 for _, c := range config.Children {
bae9f6d2
JC
41 if err := t.transform(g, c); err != nil {
42 return err
43 }
44 }
45
107c1cdb
ND
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()
bae9f6d2 54
107c1cdb
ND
55 for _, r := range module.ManagedResources {
56 addr := r.Addr().Absolute(instPath)
bae9f6d2
JC
57 abstract := &NodeAbstractResource{
58 Addr: addr,
59 Config: r,
60 }
107c1cdb 61 // Grab the address for this resource
bae9f6d2
JC
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}