]>
Commit | Line | Data |
---|---|---|
15c0b25d AP |
1 | package terraform |
2 | ||
3 | import ( | |
107c1cdb | 4 | "github.com/hashicorp/terraform/configs" |
15c0b25d AP |
5 | ) |
6 | ||
7 | // LocalTransformer is a GraphTransformer that adds all the local values | |
8 | // from the configuration to the graph. | |
9 | type LocalTransformer struct { | |
107c1cdb | 10 | Config *configs.Config |
15c0b25d AP |
11 | } |
12 | ||
13 | func (t *LocalTransformer) Transform(g *Graph) error { | |
107c1cdb | 14 | return t.transformModule(g, t.Config) |
15c0b25d AP |
15 | } |
16 | ||
107c1cdb ND |
17 | func (t *LocalTransformer) transformModule(g *Graph, c *configs.Config) error { |
18 | if c == nil { | |
15c0b25d AP |
19 | // Can't have any locals if there's no config |
20 | return nil | |
21 | } | |
22 | ||
107c1cdb ND |
23 | // Our addressing system distinguishes between modules and module instances, |
24 | // but we're not yet ready to make that distinction here (since we don't | |
25 | // support "count"/"for_each" on modules) and so we just do a naive | |
26 | // transform of the module path into a module instance path, assuming that | |
27 | // no keys are in use. This should be removed when "count" and "for_each" | |
28 | // are implemented for modules. | |
29 | path := c.Path.UnkeyedInstanceShim() | |
30 | ||
31 | for _, local := range c.Module.Locals { | |
32 | addr := path.LocalValue(local.Name) | |
15c0b25d | 33 | node := &NodeLocal{ |
107c1cdb ND |
34 | Addr: addr, |
35 | Config: local, | |
15c0b25d | 36 | } |
15c0b25d AP |
37 | g.Add(node) |
38 | } | |
39 | ||
40 | // Also populate locals for child modules | |
107c1cdb ND |
41 | for _, cc := range c.Children { |
42 | if err := t.transformModule(g, cc); err != nil { | |
15c0b25d AP |
43 | return err |
44 | } | |
45 | } | |
46 | ||
47 | return nil | |
48 | } |