fix: preserve Fn::FindInMap with unresolved Ref keys in PARTIAL mode#9006
Open
polyomino24 wants to merge 1 commit into
Open
fix: preserve Fn::FindInMap with unresolved Ref keys in PARTIAL mode#9006polyomino24 wants to merge 1 commit into
polyomino24 wants to merge 1 commit into
Conversation
FnFindInMapResolver was unconditionally raising "Fn::FindInMap layout
is incorrect" when a key arrived as an unresolved {"Ref": ...} dict in
PARTIAL mode, breaking `sam build` for any AWS::LanguageExtensions
template using !Ref to a parameter as a FindInMap key when no value
was supplied. Mirror FnRefResolver's pattern: preserve the expression
in PARTIAL mode and let CloudFormation resolve at deploy time. Real
layout errors (non-dict, non-string keys) still raise.
Fixes aws#9004
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue(s) does this change fix?
#9004
Why is this change necessary?
sam build(1.160.0) fails withFn::FindInMap layout is incorrectfor anyAWS::LanguageExtensionstemplate that usesFn::FindInMapwith a!Ref Paramas one of the keys, when no value is supplied for that parameter at build time (no--parameter-overrides, noDefault). The same template built successfully with 1.159.1 — this is a regression introduced together with the newcfn_language_extensionsmodule.Root cause:
FnRefResolvercorrectly preserves an unresolved{"Ref": "ENV"}dict inResolutionMode.PARTIAL(the default for SAM CLI integration), butFnFindInMapResolverthen validated the resolved keys withisinstance(..., str)and raisedInvalidTemplateExceptionunconditionally, regardless of resolution mode.How does it address the issue?
In
samcli/lib/cfn_language_extensions/resolvers/fn_find_in_map.py, mirror theFnRefResolverPARTIAL-mode pattern: when any resolved FindInMap key arrives as adict(an unresolved nested intrinsic) andresolution_mode == PARTIAL, return the originalFn::FindInMapexpression so CloudFormation can resolve it at deploy time. Non-dict, non-strkeys (e.g. anintliteral) remain a layout error in either mode, preserving existing behavior for genuine template mistakes.What side effects does this change have?
test_kotlin_compatibility.pypreviously asserted thatFn::FindInMapwithRef/GetAttto a resource raises in default (PARTIAL) mode. That assertion captured the Kotlin reference's strict semantics, which conflict with SAM CLI's documented PARTIAL intent ("preserve unresolvable references in the output"). Those templates were moved to a newERROR_TEMPLATES_FULL_MODE_ONLYlist and are now asserted underResolutionMode.FULL, keeping Kotlin parity for the strict callers while letting PARTIAL mode pass the expression through to CloudFormation. The remainingfnFindInMapWithUnsupportedFunctionFnSubtemplate is unaffected (it already errored via a different code path).FULLmode behavior.Mandatory Checklist
PRs will only be reviewed after checklist is complete
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.