aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.4k stars 3.79k forks source link

(aws-cdk-lib.Fn): Support Fn::ForEach #27211

Open alFReD-NSH opened 10 months ago

alFReD-NSH commented 10 months ago

Describe the feature

Fn::ForEach is a new function that is added to cloudformation.

Use Case

Creating multiple resources based on Cloudformation template parameter. I'm deploying CDK generated templates to Service Cataloge.

Proposed Solution

ForEach function in aws-cdk-lib.Fn

Other Information

No response

Acknowledgements

CDK version used

v2.96.2

Environment details (OS name and version, etc.)

Any

pahud commented 10 months ago

Thank you for the feature request and PR! This is an awesome feature!

alFReD-NSH commented 10 months ago

Giving this more thoughts, we'll have to think off how the interface would be. This could be applied to resources, conditions and outputs.

alFReD-NSH commented 9 months ago

Here's two different possibilities, we could create resources for it:

  1. Inside a callback function, which makes it somewhat functional programming looking:
    new ForEach(this, 'Queues', queueNames, (scope: Construct, variable: string)  => {
        new sqs.Queue(scope, 'Test', {
            queueName: Token.asString(variable)
        })
    });
  1. Or use the class properties:
    const forEach = new ForEach(this, 'Queues', queueNames);
    new sqs.Queue(forEach.childrenScope, 'Test', {
      queueName: Token.asString(forEach.identifier)
    });

It would be nice to gather more input from CDK core members.

matheushent commented 7 months ago

This feature request is open for quite a while... any prevision on when it is coming?