aws / aws/aws-cdk

cloudformation-include: Support Fn::ForEach

Open
#27,315 2 comments 5 reactions 0 assignees View on GitHub
@aws-cdk/cloudformation-include effort/medium feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

cloudformation-include fails when a template with Fn::Foreach resource is passed as it tries to convert it to a CfnResource, but it's not exactly a resource so it doesn't have a type property:

```
jsii.errors.JavaScriptError:
Error: The `type` property is required
at new CfnResource (C:\Users\483413\AppData\Local\Temp\2\jsii-kernel-d3l9Pa\node_modules\aws-cdk-lib\core\lib\cfn-resource.js:1:1194)
at CfnInclude.getOrCreateResource (C:\Users\483413\AppData\Local\Temp\2\jsii-kernel-d3l9Pa\node_modules\aws-cdk-lib\cloudformation-include\lib\cfn-include.js:1:13061)
at new CfnInclude (C:\Users\483413\AppData\Local\Temp\2\jsii-kernel-d3l9Pa\node_modules\aws-cdk-lib\cloudformation-include\lib\cfn-include.js:1:2011)
at Kernel._Kernel_create (C:\Users\483413\AppData\Local\Temp\2\tmpdsxxbqtf\lib\program.js:10071:25)
at Kernel.create (C:\Users\483413\AppData\Local\Temp\2\tmpdsxxbqtf\lib\program.js:9742:93)
at KernelHost.processRequest (C:\Users\483413\AppData\Local\Temp\2\tmpdsxxbqtf\lib\program.js:11658:36)
at KernelHost.run (C:\Users\483413\AppData\Local\Temp\2\tmpdsxxbqtf\lib\program.js:11618:22)
at Immediate._onImmediate (C:\Users\483413\AppData\Local\Temp\2\tmpdsxxbqtf\lib\program.js:11619:46)
at processImmediate (node:internal/timers:466:21)
```

### Use Case

Trying to use Fn::ForEach in cloudformation to create multiple resources based on custom resource output and bring that to my CDK stack but cloudformation-include.CfnInclude doesn't support Fn::ForEach.

### Proposed Solution

_No response_

### Other Information

_No response_

### Acknowledgements

- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

v2.98.0

### Environment details (OS name and version, etc.)

any

Contributor guide

Open the contributing guide

Research direction

Start at cloudformation-include.CfnInclude, especially the getOrCreateResource path shown in the error, and reproduce the failure with a template containing Fn::ForEach. Confirm that including the template no longer attempts to construct an invalid CfnResource and that the resulting CDK stack preserves the Fn::ForEach construct.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.