Skip to content

Commit

Permalink
lookup(): only treat map as unknown if it is wholly unknown
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OwenTuz committed Oct 2, 2020
1 parent a78d75c commit 28cb0ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lang/funcs/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ var LookupFunc = function.New(&function.Spec{
mapVar := args[0]
lookupKey := args[1].AsString()

if !mapVar.IsWhollyKnown() {
if !mapVar.IsKnown() {
return cty.UnknownVal(retType), nil
}

Expand Down
8 changes: 8 additions & 0 deletions lang/funcs/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,14 @@ func TestLookup(t *testing.T) {
cty.UnknownVal(cty.String),
false,
},
{
[]cty.Value{
mapWithUnknowns,
cty.StringVal("foo"),
},
cty.StringVal("bar"),
false,
},
{
[]cty.Value{
simpleMap,
Expand Down

0 comments on commit 28cb0ab

Please sign in to comment.