]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/hashicorp/hcl2/hcldec/variables.go
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / hcl2 / hcldec / variables.go
1 package hcldec
2
3 import (
4 "github.com/hashicorp/hcl2/hcl"
5 )
6
7 // Variables processes the given body with the given spec and returns a
8 // list of the variable traversals that would be required to decode
9 // the same pairing of body and spec.
10 //
11 // This can be used to conditionally populate the variables in the EvalContext
12 // passed to Decode, for applications where a static scope is insufficient.
13 //
14 // If the given body is not compliant with the given schema, the result may
15 // be incomplete, but that's assumed to be okay because the eventual call
16 // to Decode will produce error diagnostics anyway.
17 func Variables(body hcl.Body, spec Spec) []hcl.Traversal {
18 schema := ImpliedSchema(spec)
19
20 content, _, _ := body.PartialContent(schema)
21
22 var vars []hcl.Traversal
23
24 if vs, ok := spec.(specNeedingVariables); ok {
25 vars = append(vars, vs.variablesNeeded(content)...)
26 }
27 spec.visitSameBodyChildren(func(s Spec) {
28 if vs, ok := s.(specNeedingVariables); ok {
29 vars = append(vars, vs.variablesNeeded(content)...)
30 }
31 })
32
33 return vars
34 }