Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(core): improve decoupling dependent stacks (currently can cause deploy failure) #19032

Open
mikaelstaldal opened this issue Feb 18, 2022 · 7 comments
Labels
@aws-cdk/core Related to core CDK functionality effort/medium Medium work item – several days of effort feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. feature-request A feature should be added or improved. p1

Comments

@mikaelstaldal
Copy link

What is the problem?

I have a dependency between two stacks (stack A imports X which stack B exports). When I try to remove this dependency (stack A no longer imports X), it break if CDK decides to deploy stack B before stack A.

Reproduction Steps

N/A

What did you expect to happen?

CDK is clever enough to deploy stack A before stack B, and thus removing the import before removing the export.

What actually happened?

CDK deployed stack B before stack A, and deployment failed:

StackB | 0/2 | 8:34:25 AM | UPDATE_ROLLBACK_IN_P | AWS::CloudFormation::Stack                      | Stack B Export StackB:X cannot be deleted as it is in use by StackA

CDK CLI Version

2.12.0 (build c9786db)

Framework Version

No response

Node.js Version

v16.13.0

OS

Linux

Language

Java

Language Version

11

Other information

A workaround is to force a specific deployment order by adding an explicit dependency:

stackB.addDependency(stackA);
@mikaelstaldal mikaelstaldal added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 18, 2022
@github-actions github-actions bot added the @aws-cdk/core Related to core CDK functionality label Feb 18, 2022
@NGL321 NGL321 added p2 and removed needs-triage This issue or PR still needs to be triaged. labels Feb 21, 2022
@NGL321 NGL321 self-assigned this Feb 21, 2022
@NGL321
Copy link
Contributor

NGL321 commented Feb 21, 2022

Hey @mikaelstaldal,

Thank you for reporting this issue. It is however hard to determine what the cause of this behavior is from just the information provided.

Could you please clarify with all the steps that resulted in this result as well as indicate why there is a problem arising if "Stack B" is deployed before "Stack A".
When working in the CDK, stack ordering is assumed to be insignificant unless there is a dependency created between stacks (either via imports or explicitly declared). If resources in the former stack depend on resources in the latter, as outlined in our docs you must declare a dependency between those stacks even if no resources are passed between them.

While the Cloudformation and the CDK can intelligently detect most of these dependencies, there are cases where you must explicitly set it:

stackB.node.addDependency(stackA);

Additionally, if you are simply trying to update the stacks from when they had a dependency to not, you may run into trouble that can be resolved by deleting the existing stacks in dependent order, and then redeploying from scratch.

Please let me know if this resolves your problem.

@NGL321 NGL321 added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 21, 2022
@mikaelstaldal
Copy link
Author

mikaelstaldal commented Feb 22, 2022

OK, maybe it is working as documented. Then this is not a bug, but consider it a feature request, since I believe that it is unreasonably complicated to remove a dependency between stacks.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 22, 2022
@NGL321
Copy link
Contributor

NGL321 commented Feb 23, 2022

That is a fair point. I actually think this is a higher-priority if a request for simplification, so I am converting the issue to a feature-request and bumping its priority for now.

@NGL321 NGL321 added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. p1 and removed bug This issue is a bug. p2 labels Feb 23, 2022
@NGL321 NGL321 changed the title (core): cannot remove dependency between stacks (core): improve decoupling dependent stacks (currently can cause deploy failure) Feb 23, 2022
@NGL321 NGL321 removed their assignment Feb 23, 2022
@comcalvi
Copy link
Contributor

This will be resolved by weak references: aws/aws-cdk-rfcs#449

@peterwoodworth
Copy link
Contributor

This is a very well known and documented issue, I don't think we need to track it here anymore

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@peterwoodworth
Copy link
Contributor

Nevermind, this is a feature request to improve the experience. Reopening

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality effort/medium Medium work item – several days of effort feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. feature-request A feature should be added or improved. p1
Projects
None yet
Development

No branches or pull requests

5 participants