aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.33k stars 3.76k forks source link

aws-cdk: Add --except flag in CDK CLI #27554

Open badaldavda8 opened 8 months ago

badaldavda8 commented 8 months ago

Describe the feature

cdk diff, cdk synth, cdk deploy all have option either to deploy all or deploy specific stack.

There must be an option where I do a cdk diff --except abc-stack where it does a diff for all the stacks except abc-stack.

Use Case

When you create cdk during ci/cd pipeline, there might be situations where you will first create 4 stacks and 1 stack will be dependent on the output of those 4 stacks created which we might reference resources.

Example, in my case -

  1. I create VPC, Elastic Beanstalk.
  2. This elastic beanstalk creates an internal ALB.
  3. I need a privatelink connectivity to this internal ALB so I create an NLB in another stack.
  4. To reference the ALB created, we need to get information like VPC of the ALB etc to create NLB in.
  5. We use fromLookup with Beanstalk Env name/tag to do that (since Beanstalk does not provide output for Load Balancer properties).
  6. We also add ALB to NLBs Target Group which Requires ALB Construct.

In this case, if I do a diff during my first run, it will fail since my ALB with Beanstalk has not been created to populate the Context using fromLookup.

Proposed Solution

cdk diff --except abc-stack cdk deploy --except abc-stack cdk synth --except abc-stack

So either I create 2 stages where I do cdk diff --except nlb-stack and cdk deploy --except nlb-stack in 1st stage and cdk diff nlb-stack and cdk deploy nlb-stack in 2nd stage in my ci cd pipeline.

Other Information

No response

Acknowledgements

CDK version used

2.99.1

Environment details (OS name and version, etc.)

MacOS

pahud commented 8 months ago

Thank you. Please help us prioritize with the upvotes 👍

blade2005 commented 5 months ago

Similar use case.

I have resources like sagemaker which are consumed by some lambda functions in a different stack, if i want to disable those sagemaker model endpoints, i need to first explicitly deploy all stacks which consume that sagemaker stack, then i can deploy the sagemaker stack to get rid of it. many other similar use cases due to how the import value/export value system works.

nkhandelwal1 commented 1 month ago

+1