Skip to content

fix(E3006): decide Fn::Equals on AWS::Partition from the region - #4982

Merged
kddejong merged 1 commit into
aws-cloudformation:mainfrom
hoganbr-amzn:fix/e3006-partition-conditions
Nov 3, 2026
Merged

kddejong merged 1 commit into
aws-cloudformation:mainfrom
hoganbr-amzn:fix/e3006-partition-conditions

Conversation

@hoganbr-amzn

Copy link
Copy Markdown
Contributor

Issue #, if available: Fixes #4981

Description of changes:

This PR is stacked on #4980 (and through it on #4976 and #4978) and shows their commits until they merge; the change here is the last commit. It needs get_partition from #4980.

Conditions.build_scenerios_on_region decides an Fn::Equals between Ref AWS::Region and a literal for the region being linted. An Fn::Equals against Ref AWS::Partition stays [True, False], even though the region fixes the partition. So E3006 reports a resource as missing from a region where its condition can never be true:

Conditions:
  IsCommercial: !Equals [!Ref AWS::Partition, aws]
Resources:
  Accelerator:
    Type: AWS::GlobalAccelerator::Accelerator
    Condition: IsCommercial
    Properties:
      Name: example

cfn-lint --regions us-east-1 cn-north-1 us-gov-west-1 on main:

E3006 Resource type 'AWS::GlobalAccelerator::Accelerator' does not exist in 'cn-north-1'
E3006 Resource type 'AWS::GlobalAccelerator::Accelerator' does not exist in 'us-gov-west-1'

With this change neither is reported. The same resource gated on !Equals [aws-cn, !Ref AWS::Partition] still gets E3006 for cn-north-1.

Equal gains an is_partition property, computed by the same helper as is_region. build_scenerios_on_region decides those equals from get_partition(region) (added in #4980). Only literal comparisons are decided: !Equals [!Ref AWS::Partition, !Ref SomeParameter] stays undecided.

Reach. build_scenerios_on_region is called by E3006 and by Conditions.build_scenarios when it is given a region. No other bundled rule passes a region, so E3006 is the only rule whose output changes. It can only drop findings, in regions where a partition condition is false. The context-path conditions (cfnlint.context.conditions) are unchanged; their is_region has no caller outside that package, so Fn::If resolution is not affected.

Verification.

  • test_equals.py: Equal recognises Ref AWS::Partition on either side and leaves region and parameter equals alone.
  • test_conditions.py: the region decides the partition equals, including under Fn::Not, Fn::And and Fn::Or and combined with a region equals, while parameter conditions stay undecided.
  • test_type.py: E3006 run on a decoded template (not a mocked conditions) with a partition condition reports only the region where the condition holds.
  • All three fail without this change.
  • Good fixtures linted one region at a time in all eight partitions (same command as fix(iam): accept IAM principal ARNs from every partition #4976): same output as without this change in every region.
  • pytest test and pre-commit run --all-files pass.

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

@kddejong
kddejong force-pushed the fix/e3006-partition-conditions branch from f18aded to 6a4dad0 Compare November 3, 2026 21:59
build_scenerios_on_region already fixes Equals against Ref AWS::Region.
The partition is a function of the region, so the same Equals against
Ref AWS::Partition can be fixed at the same time instead of being left as
[True, False]. E3006 reads it, so a resource gated on a partition
condition is no longer reported as missing from regions where the
condition is false.

Signed-off-by: Brenden Hogan <hoganbr@amazon.com>
@kddejong
kddejong force-pushed the fix/e3006-partition-conditions branch from 6a4dad0 to 069935c Compare November 3, 2026 22:56
@kddejong
kddejong merged commit 6241ef7 into aws-cloudformation:main Nov 3, 2026
22 checks passed
@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.80%. Comparing base (dbb3da3) to head (069935c).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/cfnlint/conditions/_equals.py 86.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4982   +/-   ##
=======================================
  Coverage   94.80%   94.80%           
=======================================
  Files         441      441           
  Lines       16128    16144   +16     
  Branches     3130     3132    +2     
=======================================
+ Hits        15290    15306   +16     
  Misses        463      463           
  Partials      375      375           
Flag Coverage Δ
unittests 94.80% <92.30%> (+<0.01%) ⬆️

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.

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.

E3006: resource type availability ignores conditions on AWS::Partition

2 participants