diff --git a/lang/funcs/collection.go b/lang/funcs/collection.go index 742b84c9ebba..264ed122d836 100644 --- a/lang/funcs/collection.go +++ b/lang/funcs/collection.go @@ -512,9 +512,14 @@ var LookupFunc = function.New(&function.Spec{ } ty := args[0].Type() - key := args[1].AsString() + switch { case ty.IsObjectType(): + if !args[1].IsKnown() { + return args[2].Type(), nil + } + + key := args[1].AsString() if ty.HasAttribute(key) { return args[0].GetAttr(key).Type(), nil } else if len(args) == 3 { diff --git a/lang/funcs/collection_test.go b/lang/funcs/collection_test.go index b04d01d4325f..e0c3e33f8c0c 100644 --- a/lang/funcs/collection_test.go +++ b/lang/funcs/collection_test.go @@ -1255,6 +1255,25 @@ func TestLookup(t *testing.T) { cty.UnknownVal(cty.String), false, }, + { + []cty.Value{ + simpleMap, + cty.UnknownVal(cty.String), + }, + cty.UnknownVal(cty.String), + false, + }, + { + []cty.Value{ + cty.ObjectVal(map[string]cty.Value{ + "foo": cty.StringVal("a"), + "bar": cty.StringVal("b"), + }), + cty.UnknownVal(cty.String), + }, + cty.UnknownVal(cty.String), + false, + }, } for _, test := range tests {