]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/hashicorp/terraform/terraform/transform_local.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / terraform / transform_local.go
1 package terraform
2
3 import (
4 "github.com/hashicorp/terraform/configs"
5 )
6
7 // LocalTransformer is a GraphTransformer that adds all the local values
8 // from the configuration to the graph.
9 type LocalTransformer struct {
10 Config *configs.Config
11 }
12
13 func (t *LocalTransformer) Transform(g *Graph) error {
14 return t.transformModule(g, t.Config)
15 }
16
17 func (t *LocalTransformer) transformModule(g *Graph, c *configs.Config) error {
18 if c == nil {
19 // Can't have any locals if there's no config
20 return nil
21 }
22
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)
33 node := &NodeLocal{
34 Addr: addr,
35 Config: local,
36 }
37 g.Add(node)
38 }
39
40 // Also populate locals for child modules
41 for _, cc := range c.Children {
42 if err := t.transformModule(g, cc); err != nil {
43 return err
44 }
45 }
46
47 return nil
48 }