aws / aws/aws-cdk

aws_core: NestedStack tags cannot override parent stack tags in constructor

Open
#30,996 7 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/core documentation effort/small feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

In this python code snippet:
```
app = aws_cdk.App()

stack1 = aws_cdk.Stack(app, "stack1")
tags = aws_cdk.Tags.of(stack1)
tags.add("foo", "bar")

stack2 = aws_cdk.NestedStack(stack1, "stack2")
tags = aws_cdk.Tags.of(stack2)
tags.add("foo", "zap", priority=2000)
```

The nested stack has tag `"foo": "bar"`.

### Expected Behavior

I expected `stack2` to have tag `"foo":"zap"` but it has tag `"foo":"bar"` inherited from the parent stack. Similarly, removing a tag that was added in the parent stack does not work, but adding a new ones does.

### Current Behavior

The inherited parent stack's tags cannot be modified by the nested stack.

### Reproduction Steps

```
import aws_cdk

app = aws_cdk.App()

stack1 = aws_cdk.Stack(app, "stack1")
tags = aws_cdk.Tags.of(stack1)
tags.add("foo", "bar")

stack2 = aws_cdk.NestedStack(stack1, "stack2")
tags = aws_cdk.Tags.of(stack2)
tags.add("foo", "zap", priority=2000)

app.synth()
```

Observe that `stack2` in the resulting cloudformation template has tag `"foo":"bar"`.

### Possible Solution

If this is expected behaviour I feel it should at least be documented (unless I missed that documentation somewhere).

### Additional Information/Context

_No response_

### CDK CLI Version

2.150.0 (build 3f93027)

### Framework Version

2.149.0

### Node.js Version

v20.12.1

### OS

Mac os X 14.5

### Language

Python

### Language Version

Python 3.10.11

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the Tags.of and NestedStack entry points and reproduce the behavior with app.synth() using the Python example. Trace how parent tags are inherited and how priority-based overrides or removals are handled, then add a regression test showing the synthesized nested-stack tags match the expected result.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python, typescript
Domain
infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.