-
Notifications
You must be signed in to change notification settings - Fork 4.5k
cdk cli: Deploy of empty non-toplevel stack does not get deleted #20822
Description
Describe the bug
After deploying a stack that uses a stage as it's scope (and not the App), so that it is not defined at the top level of the construct tree, a subsequent deploy of that same stack with all resources removed (including analytics_reporting=False) will recognize the stack as empty and existing, but does not delete it.
Expected Behavior
A previously existing stack deployed with no resources should delete the stack.
Current Behavior
The previously existing stack is not deleted.
Reproduction Steps
#app.py
from aws_cdk import App, Stage, Stack
app = App()
stage = Stage(app, 'Stage')
stack = Stack(stage, 'Stack')
cdk deploy '**'
#changed app.py
from aws_cdk import App, Stage, Stack
app = App()
stage = Stage(app, 'Stage')
stack = Stack(stage, 'Stack', analytics_reporting=False)
cdk deploy '**'
Possible Solution
I suspect the stack.stackName reference during the deploy of an existing empty stack should be stack.node.path instead.
aws-cdk/packages/aws-cdk/lib/cdk-toolkit.ts
Line 173 in fb5ebdd
| selector: { patterns: [stack.stackName] }, |
>>> app = App()
>>> top_level_stack = Stack(app, 'TopLevelStack')
>>> stage = Stage(app, 'Stage')
>>> staged_level_stack = Stack(stage, 'StagedLevelStack')
>>> top_level_stack.stack_name; top_level_stack.node.path
'TopLevelStack'
'TopLevelStack'
>>> staged_level_stack.stack_name; staged_level_stack.node.path
'Stage-StagedLevelStack'
'Stage/StagedLevelStack'
Additional Information/Context
No response
CDK CLI Version
2.28.1 (build d035432)
Framework Version
2.28.1
Node.js Version
14.16.0
OS
AL2
Language
Python
Language Version
Python 3.8
Other information
No response