cloudformation-include: CfnInclude drops properties if Fn::Transform is present
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 74
Description
### Describe the bug
Using CfnInclude on a template with a resource that uses Fn::Transform as a key in the resource's properties elides other properties specified.
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Library Version
_No response_
### Expected Behavior
I expect the other properties besides `Fn::Transform` to be preserved.
### Current Behavior
Only `Fn::Transform` is being parsed and put into the synthesized template.
### Reproduction Steps
```ts
// cfn-include-transform-bug-stack.ts
import { CfnInclude } from 'aws-cdk-lib/cloudformation-include';
import * as cdk from 'aws-cdk-lib/core';
import { Construct } from 'constructs';
export class CfnIncludeTransformBugStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new CfnInclude(this, "CfnInclude", {
templateFile: "./template.yml",
})
}
}
```
```yaml
// template.yml
Resources:
Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: buckety
Fn::Transform:
Name: BucketTransform
Params:
Do: Things
```
This is the synthesized stack resource, observe BucketName is missing.
```json
"Resources": {
"Bucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"Fn::Transform": {
"Name": "BucketTransform",
"Params": {
"Do": "Things"
}
}
}
},
```
### Possible Solution
I think the bug stems from this assumption
https://github.com/aws/aws-cdk/blob/d8c324ae31db5997f9511e3f43affceea57d86c3/packages/aws-cdk-lib/core/lib/helpers-internal/cfn-parse.ts#L523
In this case, the object is _both_ an actual object and a CFN intrinsic.
Although, this line makes me believe that every property would just be preserved... need to step through with the debugger
https://github.com/aws/aws-cdk/blob/d8c324ae31db5997f9511e3f43affceea57d86c3/packages/aws-cdk-lib/core/lib/helpers-internal/cfn-parse.ts#L712
### Additional Information/Context
_No response_
### AWS CDK Library version (aws-cdk-lib)
2.215.0
### AWS CDK CLI version
2.1033.0 (build 1ec3310)
### Node.js Version
v20.19.2
### OS
MacOS 15.6.1
### Language
TypeScript
### Language Version
5.9.3
### Other information
_No response_
Contributor guide
Research direction
Start in packages/aws-cdk-lib/core/lib/helpers-internal/cfn-parse.ts at the referenced lines around 523 and 712, then reproduce the issue with the provided CfnInclude stack and template.yml. Trace how a resource Properties object containing Fn::Transform is parsed. Done means the synthesized Bucket resource preserves BucketName alongside Fn::Transform.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100