-
Has anyone run into a problem with CDK when it comes to tagging existing resources? I'm trying to add a new tag to an existing VPC or subnet, or even change an existing tag, but it's not working. I can pass the details of the existing VPC and the data generated in the cdk.context.json identifies the VPC and its subnets correctly
I then utilise
and
I am working with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I think only tags of resources created in the current CDK application can be set in this way. The tags are added to the resource declarations in the stack template where they are defined. Tagging resources outside of the application would be unstable in cases since the resource could be recreated by the code that manages that resource (in case of IaC). The tags would no longer be on the resource. Tagging this way could be achieved with a custom resource, but the ownership of a Tag cannot be determined, so could lead to unstable situations too. However I think that both: cdk.Aspects.of(vpc).add(new cdk.Tag('TestTag', 'test')); could throw an exception that explains the situation. That would be better than silently ignoring :-) |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
I think only tags of resources created in the current CDK application can be set in this way. The tags are added to the resource declarations in the stack template where they are defined.
Tagging resources outside of the application would be unstable in cases since the resource could be recreated by the code that manages that resource (in case of IaC). The tags would no longer be on the resource. Tagging this way could be achieved with a custom resource, but the ownership of a Tag cannot be determined, so could lead to unstable situations too.
However I think that both:
cdk.Aspects.of(vpc).add(new cdk.Tag('TestTag', 'test'));
cdk.Tags.of(vpc).add('TestTag', 'test');
could throw an excepti…