Skip to content

Comments

feat: add Fn::ForEach support for CloudFormation deploy-time loops#36801

Open
awsmadi wants to merge 8 commits intoaws:mainfrom
awsmadi:feature/for-each-loops
Open

feat: add Fn::ForEach support for CloudFormation deploy-time loops#36801
awsmadi wants to merge 8 commits intoaws:mainfrom
awsmadi:feature/for-each-loops

Conversation

@awsmadi
Copy link

@awsmadi awsmadi commented Jan 26, 2026

Issue # (if applicable)

Closes #.

Reason for this change

Ensure ability to loop directly in CloudFormation for CDK-generated CloudFormation templates
Related: aws/aws-cdk-cli#1063

Description of changes

Core functionality:

  • Add Fn.forEach() intrinsic function with validation
  • Add Fn.forEachRef() for loop variable references
  • Add ForEachResource for creating multiple resources
  • Add ForEachOutput for creating multiple outputs
  • Add ForEachCondition for creating multiple conditions
  • Add CfnForEachFragment for template injection
  • Auto-add AWS::LanguageExtensions transform

API improvements:

  • Add static type guards (isForEachResource, isForEachOutput, isForEachCondition)
  • Add ref(), getAtt(), refFor(), getAttFor() methods on ForEachResource
  • Support parameter references in collections
  • Add comprehensive JSDoc documentation

Testing:

  • Add integration test for ForEach functionality
  • Add unit tests for all ForEach constructs
  • Add validation for alphanumeric loop names

Documentation:

  • Add README section with examples
  • Add Rosetta fixture declarations

Describe any new or updated permissions being added

N/A

Description of how you validated changes

Validated via tests

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Core functionality:
- Add Fn.forEach() and Fn.forEachRef() intrinsic functions
- Add FnForEach class implementing IResolvable
- Auto-add AWS::LanguageExtensions transform

High-level constructs:
- Add ForEachResource for creating multiple resources
- Add ForEachOutput for creating multiple outputs
- Add ForEachCondition for creating multiple conditions
- Add CfnForEachFragment for template section injection

Features:
- Virtual CfnResource template for Aspect support
- Loop variable validation (alphanumeric only)
- Lazy evaluation for proper resolution order
- Support for IResolvable collections
- Helper methods: ref(), refFor(), getAtt(), getAttFor()

Tests:
- Add comprehensive test coverage for all ForEach constructs
- Test transform auto-addition
- Test validation and error cases
Core functionality:
- Add Fn.forEach() intrinsic function with validation
- Add Fn.forEachRef() for loop variable references
- Add ForEachResource for creating multiple resources
- Add ForEachOutput for creating multiple outputs
- Add ForEachCondition for creating multiple conditions
- Add CfnForEachFragment for template injection
- Auto-add AWS::LanguageExtensions transform

API improvements:
- Add static type guards (isForEachResource, isForEachOutput, isForEachCondition)
- Add ref(), getAtt(), refFor(), getAttFor() methods on ForEachResource
- Support parameter references in collections
- Add comprehensive JSDoc documentation

Testing:
- Add integration test for ForEach functionality
- Add unit tests for all ForEach constructs
- Add validation for alphanumeric loop names

Documentation:
- Add README section with examples
- Add Rosetta fixture declarations
@awsmadi awsmadi requested a review from a team as a code owner January 26, 2026 21:36
@aws-cdk-automation aws-cdk-automation requested a review from a team January 26, 2026 21:36
@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 labels Jan 26, 2026
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

- Add Token import to integ test
- Wrap buckets.getAtt('Arn') with Token.asString() for type safety
@aws-cdk-automation aws-cdk-automation dismissed their stale review January 27, 2026 21:57

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 27, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results48 ran48 passed
TestResult
No test annotations available

@github-actions
Copy link
Contributor

github-actions bot commented Jan 27, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results with resolved templates48 ran48 passed
TestResult
No test annotations available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants