Repository navigation
fix(lib): keep falsy default values in Fn.lookup - #584
eduardomourar wants to merge 1 commit into
Conversation
010e213 to
3042d25
Compare
jsteinich
left a comment
There was a problem hiding this comment.
Thanks for picking this up! I checked the fix on Terraform 1.14.3 and OpenTofu 1.12.6, in both JSON and HCL synth. false, 0 and "" now render lookup() and return the default for a missing key. Keys that exist evaluate the same as before, and the JSII signature is unchanged.
One gap: null. It now passes the !== undefined guard, but _lookup's variadic listOf() drops null elements (functions/helpers.ts:76). So Fn.lookup(m, "k", null) renders lookup(m, "k"), which still errors on a missing key. Terraform and OpenTofu both accept lookup(m, "k", null) and return null. Could you pass an explicit null token and add a null case to the test.each?
if (defaultValue !== undefined)
return Fn._lookup(inputMap, key, [
defaultValue === null ? Token.nullValue() : defaultValue,
]);A nit: the inline snapshot in iterator.test.ts was re-indented by one space. Restoring the old indent keeps the diff to the boolean_map line.
For the release notes (no action needed here): a falsy default whose type differs from the map's element type (e.g. "" on a map(number)), or a list passed as inputMap, used to work by accident through the property-access path. These now fail at plan, as the same calls already do with a truthy default.
HCL synth has the same truthiness pattern for variable attributes and locals. That's out of scope here, so it's tracked separately in #589.
3042d25 to
b6d896c
Compare
|
All addressed now. |
Related issue
Fixes #416
Description
Test for an
undefineddefault instead of truthiness, sofalse,0and an empty string render alookup()call. Update the fqn tests to uselookupNestedand the edge integration expectations.Checklist