Repository navigation
fix(E1011): skip FindInMap key errors when map name comes from a parameter Default - #4810
Conversation
|
Hi, the [CI] Test PR run on this PR is parked waiting for a maintainer approval (first-time-contributor gate). Could someone approve it when you get a chance? Thanks. |
|
Hi @kddejong, the [CI] Test PR run on this PR is parked waiting for a maintainer approval (first-time-contributor gate). Could someone approve it when you get a chance? Thanks. |
|
Hi team, the [CI] Test PR workflow run on the current head is still parked waiting for a first-time-contributor approval (action_required). Could a maintainer approve the run so CI can proceed? Thanks. |
|
Hi @kddejong, friendly follow up: the CI runs on this PR are still parked at the first-time-contributor approval gate (action_required), so the checks cannot start until a maintainer approves the run. Could you approve it when you have a moment? Thanks! |
cabb979 to
c8ff0c6
Compare
…meter Default Since v1.53.1 (aws-cloudformation#4580), a Fn::FindInMap lookup that fails only because a key came from a parameter's Default is not reported, because the deployer can override the Default. The same lookup was still reported when the value taken from the Default was the map name: find_in_map resolved the map name on a validator carrying the resolved-from-parameters flag but yielded the key errors from the outer validator, so the aws-cloudformation#4580 skip in BaseFn.resolve never saw the flag. Carry the flag onto the validators yielded with key errors when the map name resolved from parameters. Hardcoded map names are unaffected and still validate. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
c8ff0c6 to
865dce0
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4810 +/- ##
=======================================
Coverage 94.73% 94.73%
=======================================
Files 442 442
Lines 16088 16092 +4
Branches 3121 3122 +1
=======================================
+ Hits 15241 15245 +4
Misses 467 467
Partials 380 380
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
fixes #4802
Problem
Since v1.53.1 (#4580), a
Fn::FindInMaplookup that fails only because a key came from a parameter'sDefaultis not reported, because the deployer can override theDefaultat deployment time. The same lookup was still reported when the value taken from theDefaultwas the map name (the first argument).Repro (from #4802) reported two spurious E1011 findings:
while the equivalent
#4580shape (TopKeyFromDefault) stayed silent.Root cause
In
find_in_map(src/cfnlint/jsonschema/_resolvers_cfn.py), the map name is resolved viavalidator.resolve_value(instance[0]), which yields a validator (map_v) carrying theis_resolved_from_parametersflag when the map name comes from a parameter'sDefault. However, the key errors for that map name were yielded with the outer key validators (top_v,second_v, or the plain outervalidatorin theRef: AWS::Regionbranch), which do not carry the flag. The #4580 skip inBaseFn.resolvechecks the flag on the validator yielded with the error, so it never fired for the map-name-from-Defaultshape.Fix
Added a small per-map-name helper inside
find_in_mapthat carries the resolved-from-parameters flag onto the validators yielded with key errors (both the literal-key branch and theRefpseudo-parameter branch) whenever the map name resolved from parameters. The map-name-not-found error already usedmap_v, so it needed no change, and hardcoded map names keep their existing behavior (missing keys still reported).Testing
Fn::FindInMapreported when only the map name comes from a parameterDefault#4802 on the unmodified tree; after the fix, all three resources in the repro template are silent (cfn-lint --regions us-east-1exits 0).Ref: AWS::Regiontop key, unknown map name, all still fire; a valid lookup stays silent.test_resolve_map_name_from_parameter_default(7 cases) totest/unit/rules/functions/test_find_in_map.py: the 3 parameter-Defaultmap-name cases fail on the pre-fix tree and pass after; the 4 hardcoded-map-name cases pass on both.test/unit/rulessuite: 1949 passed.test/unit/module: 988 passed; 6 failures plus one collection error are pre-existing on the base commit and unrelated (config CLI args, pricing specs, getatts, formatters).ruff checkandruff format --checkclean on both changed files.