lang/funcs: lookup() will only treat map as unknown if it is wholly unknown (#26427)

Fix for issue #26320 - this allows us to derive known values from
partially known maps where we can, and may prevent unnecessary
destroy/rebuild cycles during apply in some cases.
This commit is contained in:
OwenTuz 2020-10-05 13:48:49 +01:00 committed by GitHub
parent 3933cbd491
commit bb39fafbe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -315,7 +315,7 @@ var LookupFunc = function.New(&function.Spec{
mapVar := args[0] mapVar := args[0]
lookupKey := args[1].AsString() lookupKey := args[1].AsString()
if !mapVar.IsWhollyKnown() { if !mapVar.IsKnown() {
return cty.UnknownVal(retType), nil return cty.UnknownVal(retType), nil
} }

View File

@ -720,6 +720,14 @@ func TestLookup(t *testing.T) {
cty.UnknownVal(cty.String), cty.UnknownVal(cty.String),
false, false,
}, },
{
[]cty.Value{
mapWithUnknowns,
cty.StringVal("foo"),
},
cty.StringVal("bar"),
false,
},
{ {
[]cty.Value{ []cty.Value{
simpleMap, simpleMap,