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
(Tags): Tagging within custom construct does not apply tag to the AWS resource #19390
Comments
@abramcav using the example that you provided I can't reproduce the issue. I've tried with a couple different resource types and the tags are added fine. Is it specific resource types that you are having issues with that are not referenced here? |
The constructs in question create ECS cluster, services, tasks, autoscaling group, target groups, IAM roles all of which fail to add tags (for me). |
Can you post code that reproduces the problem? |
The code I posted above is what reproduces the problem for me with the exclusion of the app entry point:
The constructs live in a different app, and are installed via npm as a
Not sure if that matters, but trying to help repro my environment as much as possible. As a side note, I originally developed these constructs as user defined functions that I imported into the stack; this is when I realized the tagging issue and refactored the functions into custom constructs thinking it had to do with scope. |
This looks to be related to #18778 & #18921. There is a known issue when working with aspects and symlinks, but I'm not sure why this would be the case with the |
Stumbled upon this issue during investigating an issue I have with subnets tags you need to use the albController subnet auto discovery. We have a custom construct wrapped around the aws-cdk-lib/aws-eks/cluster construct. aws-cdk/packages/@aws-cdk/aws-eks/lib/cluster.ts Line 1330 in 90bc197
If I locally develop the library and have to npm link it to my stack repo, the tagging usually happened within the lib doesn't work at all. Not even if I use the Tags.of function.To test I build the npm package and used it in a normal way in my stack. cdk diff showed me all the missing tags.Working with:
|
When construct libraries are purposely symlinked (as opposed of collectively `npm install`ed), depending on how this is done they may end up with multiple copies of `aws-cdk-lib`. If that happens, Aspects from a different `aws-cdk-lib` copy than the one providing `App` will not be applied. The reason is the use of `Symbol('...')` instead of `Symbol.for('...')` to keep the list of aspects on the construct object. - The first version creates a unique symbol per library, while adding a naming hint. - The second version deduplicates: all symbols with the same naming hint will receive the same symbol. The second version is necessary to make sure that different copies of the `aws-cdk-lib` library store their aspects under the same key. Fixes #18921, #18778, #19390.
When construct libraries are purposely symlinked (as opposed of collectively `npm install`ed), depending on how this is done they may end up with multiple copies of `aws-cdk-lib`. If that happens, Aspects from a different `aws-cdk-lib` copy than the one providing `App` will not be applied. The reason is the use of `Symbol('...')` instead of `Symbol.for('...')` to keep the list of aspects on the construct object. - The first version creates a unique symbol per library, while adding a naming hint. - The second version deduplicates: all symbols with the same naming hint will receive the same symbol. The second version is necessary to make sure that different copies of the `aws-cdk-lib` library store their aspects under the same key. Fixes #18921, #18778, #19390, #18914
The fix for this should have been released in v1.150.0 & v2.18.0. Let us know if you are still |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
What is the problem?
When inside a custom construct I call
Tags.of(asg).add("Name", "my-asg-name");
, the resource (asg in this case) does not get the tag set in AWS during a deploy. The resources are created properly, and inherited tags are set, but not tags added using theTags.of(...).add(...)
method inside the construct.Reproduction Steps
create custom construct:
Create a stack that instantiates the construct:
What did you expect to happen?
When you run
cdk deploy
on this stack it should create an ECS cluster with a tag key of "Name" and value of "my-ecs-cluster"What actually happened?
It created the ECS cluster, but did not add the tag
CDK CLI Version
2.16.0 (build 4c77925)
Framework Version
aws-cdk-lib: 2.16.0, constructs: 10.0.87
Node.js Version
v14.18.0
OS
macOS Catalina v10.15.7
Language
Typescript
Language Version
TypeScript 4.6.2
Other information
Current workaround is to use escape hatch to directly add tags within the construct:
The text was updated successfully, but these errors were encountered: