Open jiem-ying opened 1 year ago
I think this is a limit from cloudformation. When the export value of stack1 is used by stack2 and stack3, cloudformation does not allow you to delete stack1 first. However, having stack2 and stack3 depend on stack1 means stack1 should be deleted first, which causes a dilemma here.
However, having stack2 and stack3 depend on stack1 means stack1 should be deleted first, which causes a dilemma here.
If stack 2 and stack 3 depend on stack 1, then they need to be deleted 1st.
Hi team, this issue is commonly impacting complex CDK project's destroy. A number of skip delete and manually removal required from CloudFormation side. Hope this FR can get higher priority for a better user experience.
Describe the feature
If users claim stacks' variables in an order that is different from Stack Dependencies via addDependency/add_dependency, "cdk destroy --all" will incur dependency-related "Delete_failed" stacks.
Use Case
Code examples in Python
app.py:
Additional restriction to trigger error if order wrong. In stack1 I am exporting an output
In stack2 and stack3, I am importing the stack1-export to create CFN-side explicit dependency
As you can see app.py stack variables are claimed in order:
Whereas, the Stack Dependency is created as
During the
cdk deploy --all
, the stack1 always to be created first then following stack2/3.However, during the
cdk destroy --all
, the only order destroy process is following is reverse order of the variables:it appears to be expected given current public
async destroy function
is coded here as:Which gives rise to error:
Proposed Solution
Update the the destroy function, to reverse the stacks order that deploy function used based on Stack Dependencies:
Other Information
Maybe also consider update the Stack Dependencies documentation with a highlighted text states that currently the "destroy" is not following the dependency but merely reverse var-declaration order in code.
Acknowledgements
CDK version used
2.88.0
Environment details (OS name and version, etc.)
Cloud9 latest