Ignoring ancestor stacks on deploy
:rocket: Feature Request
General Information
- [ ] :wave: I may be able to implement this feature request
- [ ] :warning: This feature might incur a breaking change
Description
I have a multi-stack, ECS-based application. One stack creates an ECR for the service. There are then two service stacks, one for test and one for production. A final stack creates a CodePipeline that will build/push to ECR, then deploy the test/prod service stacks with the updated image.
All of these stacks are currently defined in the same cdk application. The Pipeline, Test, and Prod stacks all get the repositoryUri via an exposed property from the lower level ECR stack. CDK then creates a dependency between these, and adds export/import connections between them.
All of the above is fine. The issue comes in when I want to limit a deploy event to only affect the test service stack. Even though I specify the test stack name when deploying, ex: cdk deploy service-test, cdk will still traverse the graph and determine that the Test stack depends on the ECR stack, so it will attempt to update the ECR stack before updating the Test stack. I really only want the pipeline to change the specific service stacks for the corresponding test/prod deploy stages, otherwise deploying to test can change something that prod depends on.
The only way that I can see to get around this is by hand crafting the export/import between the stacks so that CDK is unaware of the dependency. This is less desirable since we lose the abstraction that allows us to treat these things as objects with properties, without having to worry about how these values are passed around in AWS.
Proposed Solution
Add a cli switch, such as --ignore-ancestors, that limits deployment to only the stack(s) specified in the cdk deploy command. Ex, if you have the following:
$ cdk list
pipeline
service-prod
service-test
shared
Performing a cdk deploy service-test --ignore-ancestors will only affect the service-test stack, even when it depends on shared
Environment
- CDK CLI Version: 1.4.0 (build 175471f)
- Module Version: 1.6.0
- OS: OSX Mojave
- Language: TypeScript
Other information
Aside from the general risk of changing something a production stack depends on before testing, this can also create race conditions on deployments. Ex: If you approve an execution and it begins deploying to production, it will attempt to update the ECR stack. If another execution was waiting in the pipeline, it will immediately start the next Test deployment, which will also try to update the same ECR stack. Whichever one began first wins, the other will fail because the stack update will still be in progress.
It is especially problematic when using version-reporting on your stacks, since every execution will perform a change to all stacks, even if no resources actually changed.
The description above is specific to deployment pipelines, but I can see this also being applicable to environments where a user/role will only be given permissions to update specific stacks that are defined in an application.
You should be able to use the -e switch to only deploy the specified stacks without its dependencies.
Closing for now. Reopen if this is not what you are after.
That does it, thanks! Perhaps this is more of a documentation issue, since I wasn't aware of that option. Added https://github.com/awsdocs/aws-cdk-guide/issues/123.