aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(core): stack tags don't work on all resource types

Open phuctm97 opened this issue 4 years ago • 8 comments

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

phuctm97 avatar Apr 13 '21 04:04 phuctm97

My guess is this would be because CloudFormation doesn't know UserPools are taggable...

rix0rrr avatar Apr 13 '21 13:04 rix0rrr

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

phuctm97 avatar Apr 14 '21 01:04 phuctm97

Look like this issue still not working.

phuctm97 avatar Jul 05 '21 09:07 phuctm97

@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.

corymhall avatar Jan 27 '22 15:01 corymhall

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.

github-actions[bot] avatar Jan 27 '23 16:01 github-actions[bot]

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 avatar Jan 27 '23 16:01 rgoltz

@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.

chriswilty avatar Feb 22 '24 10:02 chriswilty