configs: Handle object constructor keys when shimming traversals

This is important in particular for shimming the "providers" map in module
blocks:

    providers = {
        "aws" = "aws.foo"
    }

We call this shim for both the key and the value here, and the value would
previously have worked. However, the key is wrapped up by the parser in
an ObjectConsKeyExpr container, which deals with the fact that in normal
use an object constructor key that is just a bare identifier is actually
interpreted as a string. We don't care about that interpretation for our
shimming purposes, and so we can just unwrap it here.
This commit is contained in:
Martin Atkins 2018-05-25 16:03:23 -07:00
parent 687830a5d5
commit 1f859ba8d4
1 changed files with 10 additions and 0 deletions

View File

@ -32,6 +32,16 @@ import (
// the caller remains responsible for checking that the result is indeed
// a keyword, e.g. using hcl.ExprAsKeyword.
func shimTraversalInString(expr hcl.Expression, wantKeyword bool) (hcl.Expression, hcl.Diagnostics) {
// ObjectConsKeyExpr is a special wrapper type used for keys on object
// constructors to deal with the fact that naked identifiers are normally
// handled as "bareword" strings rather than as variable references. Since
// we know we're interpreting as a traversal anyway (and thus it won't
// matter whether it's a string or an identifier) we can safely just unwrap
// here and then process whatever we find inside as normal.
if ocke, ok := expr.(*hclsyntax.ObjectConsKeyExpr); ok {
expr = ocke.Wrapped
}
if !exprIsNativeQuotedString(expr) {
return expr, nil
}