I'm looking for a way to specify the deployment order of my stacks in my project. I know I could add dependencies, however, these stacks do not depend on each other and I might want to delete some at a later time.
I have a framework of services that are needed globally for every other stack (e.g. rds). These are being deployed at the very start.
- App-Networking
- App-GlobalResources
Now I want to add stacks for new customers, these stacks will depend on the 2 global stacks, and on each other, but not on any of the other customer's stacks.
E.g.
- App-Customer-A-EC2 (depends on App-Networking)
- App-Customer-A-Lambdas (depends on App-Customer-A-EC2)
- App-Customer-A-Settings (depends on App-GlobalResources, App-Customer-A-Lambdas)
and
- App-Customer-B-EC2 (depends on App-Networking)
- App-Customer-B-Lambdas (depends on App-Customer-B-EC2)
- App-Customer-B-Settings (depends on App-GlobalResources, App-Customer-B-Lambdas)
I would like all these stacks to be deployed in this order. First the global stacks, then all of customer a, then all of customer b.
However, this is what cdk is doing:
- App-Networking
- App-GlobalResources
- App-Customer-A-EC2
- App-Customer-B-EC2
- App-Customer-A-Lambdas
- App-Customer-B-Lambdas
- App-Customer-A-Settings
- App-Customer-B-Settings
Which means customer A has to wait until all other customer resources have been generated before he can use the system and so on. As there are no cross dependencies between the customer stacks, they don't have to be deployed in the order cdk does it.
So, what are my options here? Apart from adding dependencies? I thought initially it would be alphabetically ordered by stack name, or maybe by construct path, but it doesn't seem so.
Thank you!
Edit: I went through the code of the cdk app and found the sorting code. There currently is no way in my case. The type of sorting used by CDK will always result in the observed pattern.
I am now working around by adding dependencies. When deleting stacks that are "in the middle" and have dependencies, I have to destroy them with the -e
argument.