From 1f859ba8d4a1dd512a51474c883bdf4b7bccdda4 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 25 May 2018 16:03:23 -0700 Subject: [PATCH] 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. --- configs/compat_shim.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/configs/compat_shim.go b/configs/compat_shim.go index ed4f37d43..66037fcdc 100644 --- a/configs/compat_shim.go +++ b/configs/compat_shim.go @@ -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 }