(core): stack tags don't work on all resource types
Stack tags don't get assigned on user pool resources.
Reproduction Steps
export class ExampleStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new cognito.UserPool(this, "UserPool");
}
}
const app = new cdk.App();
new ExampleStack(app, "Example", {
tags: {
"app:project": "Example",
"app:environment": "Development",
},
});
Run
cdk deploy
What did you expect to happen?
The created user pool tags include "app:project", "app:environment" and their values.
What actually happened?
No tags found in created user pool
Environment
- CDK CLI Version : 1.97.0
- Framework Version: 1.97.0
- Node.js Version: 14
- OS : macOS Catalina
- Language (Version): TypeScript
Other
I currently have to workaround like this:
if (props?.tags) {
for (const [key, value] of Object.entries(props.tags))
cdk.Tags.of(userPool).add(key, value);
}
This is :bug: Bug Report
My guess is this would be because CloudFormation doesn't know UserPools are taggable...
My guess is this would be because CloudFormation doesn't know UserPools are taggable...
That is also unexpected because cdk.Tag.of(userPool).add worked.
There was also another issue + PR for this, but it is not working now: https://github.com/aws/aws-cdk/issues/3882
Look like this issue still not working.
@phuctm97 it looks like this is a CloudFormation limitation. stack tags only work on resources that have the Tags property. It looks like there is an open issue in the CloudFormation coverage roadmap to support stack tags on all resources.
Until that functionality is added in CloudFormation the only way to work around this is to use the Tags.of(scope).add() method.
This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.
Hi @phuctm97 - Did you try to add tags to Cognito UserPool using the UserPoolTags CFN-property? - e.g. by adding this using "CDK escape hatches" to push such key-values to the CloudFormation output of CDK?
@rgoltz could you please explain to me what is this CDK escape hatches? i need the tags for Cognito user pool but its not working
@andreprawira LMGTFY: https://docs.aws.amazon.com/cdk/v2/guide/cfn_layer.html
For this issue, the workaround described in the "Other" section of the issue description works just fine.