Skip to content

fix: Skip E1029 where CloudFormation doesn't evaluate Fn::Sub - #4759

Merged
kddejong merged 1 commit into
aws-cloudformation:mainfrom
Thanatos9404:fix/e1029-sections-without-sub
Oct 21, 2026
Merged

kddejong merged 1 commit into
aws-cloudformation:mainfrom
Thanatos9404:fix/e1029-sections-without-sub

Conversation

@Thanatos9404

Copy link
Copy Markdown
Contributor

Issue #, if available:

Fixes #4758

Description of changes:

E1029 reported ${...} text in places where CloudFormation never evaluates intrinsic functions, so the Fn::Sub it asks for can't be added:

Following the advice doesn't work either: wrapping the first three in !Sub makes cfn-lint report E1004, E2001 and E7001.

It also reported a TemplateBody wrapped in Fn::If. The TemplateBody exception from #2057 only looked at the key right above the string, which for TemplateBody: !If [...] is the branch index.

Changes in SubNeeded:

  • Skip strings under the top-level Description, Parameters and Mappings sections, and macro parameters under Fn::Transform (not the AWS::Include Location).
  • Find the key that holds the string by stepping over Fn::If branches (nested ones too) before checking it against the TemplateBody exception.

Resource properties are checked as before: a bare ${AWS::Region} in a property, and one inside an Fn::If that isn't under TemplateBody, are still reported.

Tests: the template from the issue is a new good fixture, with an extra nested Fn::If TemplateBody. On main it gets 11 E1029 findings (the 8 from the issue plus 3 from the nested case); with this change it gets none. The bad fixture gains the two cases above that must still be reported, plus a bare ${...} in an AWS::Include Location and in a resource Description (11 findings, was 7). The full test suite passes (2972 passed, Python 3.13), pre-commit run on the changed files passes, and no snapshot under test/fixtures/results contains E1029, so none change.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

CloudFormation doesn't evaluate intrinsic functions in the template
Description, Parameters or Mappings, or in the parameters it passes to
a macro through Fn::Transform, so a "${...}" there is plain text and
the Fn::Sub that E1029 asks for can't be added. Skip those places, but
keep checking the AWS::Include Location, which can use Fn::Sub.
Parameters were skipped before (aws-cloudformation#1256) until the aws-cloudformation#2031 rework.

The TemplateBody exception (aws-cloudformation#2057) only looked at the key directly
above the string, so a TemplateBody wrapped in Fn::If was still
reported. Step over Fn::If branches, nested ones too, before checking
the exception.

Fixes aws-cloudformation#4758
@kddejong
kddejong force-pushed the fix/e1029-sections-without-sub branch from c083de1 to b5f50b4 Compare October 21, 2026 17:42
@codecov

codecov Bot commented Oct 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.67%. Comparing base (7fbb68c) to head (b5f50b4).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/cfnlint/rules/functions/SubNeeded.py 83.33% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4759      +/-   ##
==========================================
- Coverage   94.68%   94.67%   -0.02%     
==========================================
  Files         439      439              
  Lines       15910    15934      +24     
  Branches     3079     3085       +6     
==========================================
+ Hits        15065    15086      +21     
- Misses        463      466       +3     
  Partials      382      382              
Flag Coverage Δ
unittests 94.67% <83.33%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kddejong
kddejong merged commit 7e4b262 into aws-cloudformation:main Oct 21, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E1029 fires in sections where Fn::Sub is not allowed, and on TemplateBody under Fn::If

2 participants