aws-cdk: cdk diff does not work with nested stacks

Running cdk diff only lists the S3 templates of the root stack as changed.

Reproduction Steps

Create a nested stack with some resources in a nested stack. Deploy the nested stack. Add more resources to nested stack.

cdk diff should report the changes in the nested stack.

Error Log

N/A

Environment

  • CLI Version : 1.19.0
  • Framework Version: 1.19.0
  • OS : macOS
  • Language : TypeScript

This is 🐛 Bug Report

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 56
  • Comments: 19 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Hi everyone!

Sorry for not providing an update for a while. This is not currently being worked on, and currently not planed. The label p1 means it is something we want to add to the AWS CDK, and it will get a higher priority in our planing. As for the “when”, I don’t have an answer, we are currently focused on v2 and it is unlikely we will get to this before v2 release.

@cmckni3 It does! I will look into what is required to add this to the cdk. Thanks!

Hate to needlessly bump this, but it is a pretty big problem and it is now among the top 2% most upvoted issues.

We recently completed a refactoring of some stacks and moved them into nested stacks, not knowing about this issue which turns out to be pretty blocking. What was meant to be a refactoring made us lose most of the usefulness of the cdk.

Is there any update here? Is this hard to implement? Any guidance into how it might be implemented would be helpful, perhaps I can take a look at the implementation myself.

/cc @NetaNir, @rix0rrr

In the interim, could you pass IncludeNestedStacks: true to createChangeSet and then we can see the diffs in the CFN console (using cdk deploy --no-execute)? https://github.com/aws/aws-cdk/blob/master/packages/aws-cdk/lib/api/deploy-stack.ts#L249

It could at least be documented, this must be a very common problem for people building non-trivial infrastructure - AFAIK it is the “recommended” way of working around the 500-resource limit. I too have implemented an architecture based around the nested stack pattern only to be surprised it does not work with core CDK functionality.

Specifically, these links seem like they should mention the limitation in a big red warning block:

We are having same issue with our CDK app. Is there any update on this one, please. It will improve our dev workflow with nested stacks

any updates on this?

Using this shell script, for example, it is possible to check simple diffs.

Diff

...

 export class CdkWorkshopStack extends cdk.Stack {
   constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
     super(scope, id, props);

     new SqsStack(this, "CdkWorkshopSqsStack");
     new SnsStack(this, "CdkWorkshopSnsStack");
   }
 }

 class SqsStack extends cdk.NestedStack {
   constructor(scope: cdk.Construct, id: string, props?: cdk.NestedStackProps) {
     super(scope, id, props);

     new sqs.Queue(this, "CdkWorkshopQueue", {
-      visibilityTimeout: cdk.Duration.seconds(300),
+      visibilityTimeout: cdk.Duration.seconds(100),
     });
   }
 }

...

Check

 $ YOUR_PARENT_STACK_NAMES='CdkWorkshopStack' ./nested-stack-diff.sh
 ------------------------------------------------------------------
 CdkWorkshopSqsStack...
 ------------------------------------------------------------------
 {
   Resources: {
     CdkWorkshopQueue50D9D426: {
       Properties: {
-        VisibilityTimeout: 300
+        VisibilityTimeout: 100
       }
     }
   }
 }

https://gist.github.com/yukiarrr/ca846d599d166c750bff5e8c8ac986f8

However, this is only a simplified version, so it is desirable to be able to check it with “cdk diff”.

This issue, #4489, #4490 and #5974 make working with Nested Stacks in CDK much more troublesome than it should be. Is there any update on this?