aws-cdk: Tag does not produce tags on the target resource
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
According to https://docs.aws.amazon.com/cdk/v2/guide/tagging.html there are 2 ways of adding tags, either to all resources in a scope or to a specific resource:
```
Tags.of(scope).add('key', 'value')
```
or
```
Tag('key', 'value').visit(scope)
```
In CDK 2.99 the latter version, using the Tag class, does not create a tag in the CloudFormation template.
### Expected Behavior
```
Tag('key', 'value').visit(scope)
```
Should add a tag of key: value to the specified scope or construct.
### Current Behavior
```
Tag('key', 'value').visit(scope)
```
Does not add a tag to the specified scope or construct
### Reproduction Steps
Create a CDK application and set ```app.py``` as follows and run ```cdk synth```:
```python
#!/usr/bin/env python3
import aws_cdk as cdk
from aws_cdk import (
Duration,
Stack,
Tag,
Tags,
aws_sqs as sqs,
)
from constructs import Construct
class CdkTagTestStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
queue = sqs.Queue(
self, "CdkTagTestQueue",
visibility_timeout=Duration.seconds(300),
)
Tag('TestKey', 'TestValue').visit(queue)
# Tags.of(queue).add('SomeKey', 'SomeValue')
app = cdk.App()
CdkTagTestStack(app, "CdkTagTestStack")
app.synth()
```
Inspect the .template file in cdk.out folder and note that the queue construct has no tag.
As a further test, comment line 23 and uncomment line 24. Run ```cdk synth``` again and on inspection of the .template file a tag will have been added to the queue resource.
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### CDK CLI Version
2.99
### Framework Version
_No response_
### Node.js Version
18.17.1
### OS
Windows and Linux
### Language
Python
### Language Version
3.10.2
### Other information
_No response_
Contributor guide
Research direction
Start with the Python reproduction in app.py and compare the synthesized cdk.out template when using Tag('TestKey', 'TestValue').visit(queue) versus Tags.of(queue).add(...). Trace the Tag and Tags entry points in the AWS CDK implementation and add coverage showing that Tag.visit produces the expected queue tag in the synthesized template.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100