diff options
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/ext/dynblock/variables_hcldec.go')
-rw-r--r-- | vendor/github.com/hashicorp/hcl2/ext/dynblock/variables_hcldec.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/ext/dynblock/variables_hcldec.go b/vendor/github.com/hashicorp/hcl2/ext/dynblock/variables_hcldec.go new file mode 100644 index 0000000..a078d91 --- /dev/null +++ b/vendor/github.com/hashicorp/hcl2/ext/dynblock/variables_hcldec.go | |||
@@ -0,0 +1,43 @@ | |||
1 | package dynblock | ||
2 | |||
3 | import ( | ||
4 | "github.com/hashicorp/hcl2/hcl" | ||
5 | "github.com/hashicorp/hcl2/hcldec" | ||
6 | ) | ||
7 | |||
8 | // VariablesHCLDec is a wrapper around WalkVariables that uses the given hcldec | ||
9 | // specification to automatically drive the recursive walk through nested | ||
10 | // blocks in the given body. | ||
11 | // | ||
12 | // This is a drop-in replacement for hcldec.Variables which is able to treat | ||
13 | // blocks of type "dynamic" in the same special way that dynblock.Expand would, | ||
14 | // exposing both the variables referenced in the "for_each" and "labels" | ||
15 | // arguments and variables used in the nested "content" block. | ||
16 | func VariablesHCLDec(body hcl.Body, spec hcldec.Spec) []hcl.Traversal { | ||
17 | rootNode := WalkVariables(body) | ||
18 | return walkVariablesWithHCLDec(rootNode, spec) | ||
19 | } | ||
20 | |||
21 | // ExpandVariablesHCLDec is like VariablesHCLDec but it includes only the | ||
22 | // minimal set of variables required to call Expand, ignoring variables that | ||
23 | // are referenced only inside normal block contents. See WalkExpandVariables | ||
24 | // for more information. | ||
25 | func ExpandVariablesHCLDec(body hcl.Body, spec hcldec.Spec) []hcl.Traversal { | ||
26 | rootNode := WalkExpandVariables(body) | ||
27 | return walkVariablesWithHCLDec(rootNode, spec) | ||
28 | } | ||
29 | |||
30 | func walkVariablesWithHCLDec(node WalkVariablesNode, spec hcldec.Spec) []hcl.Traversal { | ||
31 | vars, children := node.Visit(hcldec.ImpliedSchema(spec)) | ||
32 | |||
33 | if len(children) > 0 { | ||
34 | childSpecs := hcldec.ChildBlockTypes(spec) | ||
35 | for _, child := range children { | ||
36 | if childSpec, exists := childSpecs[child.BlockTypeName]; exists { | ||
37 | vars = append(vars, walkVariablesWithHCLDec(child.Node, childSpec)...) | ||
38 | } | ||
39 | } | ||
40 | } | ||
41 | |||
42 | return vars | ||
43 | } | ||