Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cloudformation-include): can't use CFN intrinsics in Tags #30515

Merged
merged 9 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"Conditions": {
"ShouldIncludeTag": {
"Fn::Equals": [ 2, 2 ]
}
},
"Resources": {
"Bucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": "bucket2",
"Tags": [
{
"Fn::If": [
"ShouldIncludeTag",
{
"Key": "TagName",
"Value": "TagValue"
},
{
"Ref": "AWS::NoValue"
}
]
}
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,14 @@ describe('CDK Include', () => {
loadTestFileToJsObject('fn-select-with-novalue.json'),
);
});

test('Fn::If can be used in Tags', () => {
includeTestTemplate(stack, 'tags-with-fn-if.json');

Template.fromStack(stack).templateMatches(
loadTestFileToJsObject('tags-with-fn-if.json'),
);
});
});

interface IncludeTestTemplateProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ export class FromCloudFormation {
};
}

public static getCfnTag(tag: any): FromCloudFormationResult<CfnTag> {
public static getCfnTag(tag: any): FromCloudFormationResult<CfnTag | IResolvable> {
if (isResolvableObject(tag)) { return new FromCloudFormationResult(tag); }
return tag == null
? new FromCloudFormationResult({ } as any) // break the type system - this should be detected at runtime by a tag validator
: new FromCloudFormationResult({
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/core/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function pad(x: number) {
* Turn a tag object into the proper CloudFormation representation
*/
export function cfnTagToCloudFormation(x: any): any {
if (!canInspect(x)) { return x; }
return {
Key: x.key,
Value: x.value,
Expand Down
Loading