hcl/json: detect variable references in string values

This commit is contained in:
Martin Atkins 2018-01-12 23:35:58 -08:00
parent 77c855c5ed
commit 76b0988d90

View File

@ -330,8 +330,26 @@ func (e *expression) Variables() []hcl.Traversal {
switch v := e.src.(type) { switch v := e.src.(type) {
case *stringVal: case *stringVal:
// FIXME: Once the native zcl template language parser is implemented, templateSrc := v.Value
// parse with that and look for variables in there too, expr, diags := hclsyntax.ParseTemplate(
[]byte(templateSrc),
v.SrcRange.Filename,
// This won't produce _exactly_ the right result, since
// the zclsyntax parser can't "see" any escapes we removed
// while parsing JSON, but it's better than nothing.
hcl.Pos{
Line: v.SrcRange.Start.Line,
// skip over the opening quote mark
Byte: v.SrcRange.Start.Byte + 1,
Column: v.SrcRange.Start.Column + 1,
},
)
if diags.HasErrors() {
return vars
}
return expr.Variables()
case *arrayVal: case *arrayVal:
for _, jsonVal := range v.Values { for _, jsonVal := range v.Values {