aws-cdk
aws-cdk copied to clipboard
aws_core: NestedStack tags cannot override parent stack tags in constructor
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