aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/hcl2/ext/dynblock/variables_hcldec.go
diff options
context:
space:
mode:
authorNathan Dench <ndenc2@gmail.com>2019-05-24 15:16:44 +1000
committerNathan Dench <ndenc2@gmail.com>2019-05-24 15:16:44 +1000
commit107c1cdb09c575aa2f61d97f48d8587eb6bada4c (patch)
treeca7d008643efc555c388baeaf1d986e0b6b3e28c /vendor/github.com/hashicorp/hcl2/ext/dynblock/variables_hcldec.go
parent844b5a68d8af4791755b8f0ad293cc99f5959183 (diff)
downloadterraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.gz
terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.zst
terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.zip
Upgrade to 0.12
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.go43
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 @@
1package dynblock
2
3import (
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.
16func 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.
25func ExpandVariablesHCLDec(body hcl.Body, spec hcldec.Spec) []hcl.Traversal {
26 rootNode := WalkExpandVariables(body)
27 return walkVariablesWithHCLDec(rootNode, spec)
28}
29
30func 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}