diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/config/interpolate.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/config/interpolate.go | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/vendor/github.com/hashicorp/terraform/config/interpolate.go b/vendor/github.com/hashicorp/terraform/config/interpolate.go index bbb3555..599e5ec 100644 --- a/vendor/github.com/hashicorp/terraform/config/interpolate.go +++ b/vendor/github.com/hashicorp/terraform/config/interpolate.go | |||
@@ -5,6 +5,8 @@ import ( | |||
5 | "strconv" | 5 | "strconv" |
6 | "strings" | 6 | "strings" |
7 | 7 | ||
8 | "github.com/hashicorp/terraform/tfdiags" | ||
9 | |||
8 | "github.com/hashicorp/hil/ast" | 10 | "github.com/hashicorp/hil/ast" |
9 | ) | 11 | ) |
10 | 12 | ||
@@ -14,6 +16,21 @@ import ( | |||
14 | // variables can come from: user variables, resources, etc. | 16 | // variables can come from: user variables, resources, etc. |
15 | type InterpolatedVariable interface { | 17 | type InterpolatedVariable interface { |
16 | FullKey() string | 18 | FullKey() string |
19 | SourceRange() tfdiags.SourceRange | ||
20 | } | ||
21 | |||
22 | // varRange can be embedded into an InterpolatedVariable implementation to | ||
23 | // implement the SourceRange method. | ||
24 | type varRange struct { | ||
25 | rng tfdiags.SourceRange | ||
26 | } | ||
27 | |||
28 | func (r varRange) SourceRange() tfdiags.SourceRange { | ||
29 | return r.rng | ||
30 | } | ||
31 | |||
32 | func makeVarRange(rng tfdiags.SourceRange) varRange { | ||
33 | return varRange{rng} | ||
17 | } | 34 | } |
18 | 35 | ||
19 | // CountVariable is a variable for referencing information about | 36 | // CountVariable is a variable for referencing information about |
@@ -21,6 +38,7 @@ type InterpolatedVariable interface { | |||
21 | type CountVariable struct { | 38 | type CountVariable struct { |
22 | Type CountValueType | 39 | Type CountValueType |
23 | key string | 40 | key string |
41 | varRange | ||
24 | } | 42 | } |
25 | 43 | ||
26 | // CountValueType is the type of the count variable that is referenced. | 44 | // CountValueType is the type of the count variable that is referenced. |
@@ -37,6 +55,7 @@ type ModuleVariable struct { | |||
37 | Name string | 55 | Name string |
38 | Field string | 56 | Field string |
39 | key string | 57 | key string |
58 | varRange | ||
40 | } | 59 | } |
41 | 60 | ||
42 | // A PathVariable is a variable that references path information about the | 61 | // A PathVariable is a variable that references path information about the |
@@ -44,6 +63,7 @@ type ModuleVariable struct { | |||
44 | type PathVariable struct { | 63 | type PathVariable struct { |
45 | Type PathValueType | 64 | Type PathValueType |
46 | key string | 65 | key string |
66 | varRange | ||
47 | } | 67 | } |
48 | 68 | ||
49 | type PathValueType byte | 69 | type PathValueType byte |
@@ -67,6 +87,7 @@ type ResourceVariable struct { | |||
67 | Index int // Index for multi-variable: aws_instance.foo.1.id == 1 | 87 | Index int // Index for multi-variable: aws_instance.foo.1.id == 1 |
68 | 88 | ||
69 | key string | 89 | key string |
90 | varRange | ||
70 | } | 91 | } |
71 | 92 | ||
72 | // SelfVariable is a variable that is referencing the same resource | 93 | // SelfVariable is a variable that is referencing the same resource |
@@ -75,6 +96,7 @@ type SelfVariable struct { | |||
75 | Field string | 96 | Field string |
76 | 97 | ||
77 | key string | 98 | key string |
99 | varRange | ||
78 | } | 100 | } |
79 | 101 | ||
80 | // SimpleVariable is an unprefixed variable, which can show up when users have | 102 | // SimpleVariable is an unprefixed variable, which can show up when users have |
@@ -82,6 +104,7 @@ type SelfVariable struct { | |||
82 | // internally. The template_file resource is an example of this. | 104 | // internally. The template_file resource is an example of this. |
83 | type SimpleVariable struct { | 105 | type SimpleVariable struct { |
84 | Key string | 106 | Key string |
107 | varRange | ||
85 | } | 108 | } |
86 | 109 | ||
87 | // TerraformVariable is a "terraform."-prefixed variable used to access | 110 | // TerraformVariable is a "terraform."-prefixed variable used to access |
@@ -89,6 +112,7 @@ type SimpleVariable struct { | |||
89 | type TerraformVariable struct { | 112 | type TerraformVariable struct { |
90 | Field string | 113 | Field string |
91 | key string | 114 | key string |
115 | varRange | ||
92 | } | 116 | } |
93 | 117 | ||
94 | // A UserVariable is a variable that is referencing a user variable | 118 | // A UserVariable is a variable that is referencing a user variable |
@@ -99,6 +123,14 @@ type UserVariable struct { | |||
99 | Elem string | 123 | Elem string |
100 | 124 | ||
101 | key string | 125 | key string |
126 | varRange | ||
127 | } | ||
128 | |||
129 | // A LocalVariable is a variable that references a local value defined within | ||
130 | // the current module, via a "locals" block. This looks like "${local.foo}". | ||
131 | type LocalVariable struct { | ||
132 | Name string | ||
133 | varRange | ||
102 | } | 134 | } |
103 | 135 | ||
104 | func NewInterpolatedVariable(v string) (InterpolatedVariable, error) { | 136 | func NewInterpolatedVariable(v string) (InterpolatedVariable, error) { |
@@ -112,6 +144,8 @@ func NewInterpolatedVariable(v string) (InterpolatedVariable, error) { | |||
112 | return NewTerraformVariable(v) | 144 | return NewTerraformVariable(v) |
113 | } else if strings.HasPrefix(v, "var.") { | 145 | } else if strings.HasPrefix(v, "var.") { |
114 | return NewUserVariable(v) | 146 | return NewUserVariable(v) |
147 | } else if strings.HasPrefix(v, "local.") { | ||
148 | return NewLocalVariable(v) | ||
115 | } else if strings.HasPrefix(v, "module.") { | 149 | } else if strings.HasPrefix(v, "module.") { |
116 | return NewModuleVariable(v) | 150 | return NewModuleVariable(v) |
117 | } else if !strings.ContainsRune(v, '.') { | 151 | } else if !strings.ContainsRune(v, '.') { |
@@ -276,7 +310,7 @@ func (v *SelfVariable) GoString() string { | |||
276 | } | 310 | } |
277 | 311 | ||
278 | func NewSimpleVariable(key string) (*SimpleVariable, error) { | 312 | func NewSimpleVariable(key string) (*SimpleVariable, error) { |
279 | return &SimpleVariable{key}, nil | 313 | return &SimpleVariable{Key: key}, nil |
280 | } | 314 | } |
281 | 315 | ||
282 | func (v *SimpleVariable) FullKey() string { | 316 | func (v *SimpleVariable) FullKey() string { |
@@ -331,6 +365,25 @@ func (v *UserVariable) GoString() string { | |||
331 | return fmt.Sprintf("*%#v", *v) | 365 | return fmt.Sprintf("*%#v", *v) |
332 | } | 366 | } |
333 | 367 | ||
368 | func NewLocalVariable(key string) (*LocalVariable, error) { | ||
369 | name := key[len("local."):] | ||
370 | if idx := strings.Index(name, "."); idx > -1 { | ||
371 | return nil, fmt.Errorf("Can't use dot (.) attribute access in local.%s; use square bracket indexing", name) | ||
372 | } | ||
373 | |||
374 | return &LocalVariable{ | ||
375 | Name: name, | ||
376 | }, nil | ||
377 | } | ||
378 | |||
379 | func (v *LocalVariable) FullKey() string { | ||
380 | return fmt.Sprintf("local.%s", v.Name) | ||
381 | } | ||
382 | |||
383 | func (v *LocalVariable) GoString() string { | ||
384 | return fmt.Sprintf("*%#v", *v) | ||
385 | } | ||
386 | |||
334 | // DetectVariables takes an AST root and returns all the interpolated | 387 | // DetectVariables takes an AST root and returns all the interpolated |
335 | // variables that are detected in the AST tree. | 388 | // variables that are detected in the AST tree. |
336 | func DetectVariables(root ast.Node) ([]InterpolatedVariable, error) { | 389 | func DetectVariables(root ast.Node) ([]InterpolatedVariable, error) { |