-
Notifications
You must be signed in to change notification settings - Fork 4k
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
aws-cdk: stack difference count on diff is incorrect #27238
Comments
Thank you for the report. |
@jchli I can partially recreate this. Do you have a minimal example that reliably reproduces this for you? When you pass |
@indrora I generated a sample app with // cdk-test-stack.ts
import { NestedStack, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class CdkTestStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
new TestNestedStack(this, 'CdkTestNestedStack');
}
}
class TestNestedStack extends NestedStack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
}
} Testing: $ cdk deploy CdkTestStack # Succeeds, creating both stacks
$ cdk diff --fail
Stack CdkTestStack
There were no differences
✨ Number of stacks with differences: 1
$ echo $?
1 |
I have the same issue, which can be reproduced with the steps described by @ChaseWagoner. One minor fix to the reproduction steps: you need to modify the import at the I'm (also) quite certain it is directly related to issue #26818 with PR #26796 , as I have successfully tested with version |
hey @SankyRed - any movement on this? |
|
@SankyRed Out of curiosity, which version of the CDK packages did you use for testing? The minimal test from before still shows an incorrect diff stack count. (I also reproduced the incorrect diff count with a realistic stack containing various resources and nested stacks.) I still see the suspect line in aws-cdk/packages/aws-cdk/lib/cdk-toolkit.ts Line 180 in 8562c17
Setup
Test 2.92.0npm i aws-cdk@2.92.0
npm i -D aws-cdk-lib@2.92.0
npm run cdk synth
npm run cdk deploy
npm run cdk diff -- --fail
echo $? Output shows no diff, as expected: > cdk-test@0.1.0 cdk
> cdk diff --fail
Stack CdkTestStack
There were no differences
✨ Number of stacks with differences: 0
0 # exit code Test 2.118.0npm i aws-cdk@latest
npm i -D aws-cdk-lib@latest
npm ls aws-cdk aws-cdk-lib
# cdk-test@0.1.0
# ├── aws-cdk-lib@2.118.0
# └── aws-cdk@2.118.0
npm run cdk synth
npm run cdk deploy
npm run cdk diff -- --fail
echo $? Output shows an incorrect diff, including every nested stack in the diff count (even those without diffs): > cdk-test@0.1.0 cdk
> cdk diff --fail
Stack CdkTestStack
There were no differences
✨ Number of stacks with differences: 1
1 # exit code |
@ChaseWagoner Apologies on that, tested the dependent stack instead of nested stack earlier. When run |
@SankyRed +1 on feeling the pain on this. Impact is that it makes it difficult to detect a clean diff in CI/CD (e.g. by inspecting the exit code) if there is a nested stack. |
I still facing this issue, did anybody manage to fix/bypass it? Running on latest version (2.127.0). |
Hey @SankyRed - any news on this? This blocks us from upgrading to a newer version since we use the diff count as part of our release process. |
The latest version(v2.133.0) fixes the issue. Please upgrade onto the latest version to apply the necessary fix. Adding a Test 2.132.0npm i aws-cdk@2.132.0
npm i aws-cdk-lib@2.132.0
npm ls aws-cdk aws-cdk-lib
# cdk_test@0.1.0
# |----- aws-cdk-lib@2.132.0
# |----- aws-cdk@2.132.0
npm run cdk synth
npm run cdk deploy
npm run cdk diff Test 2.133.0npm i aws-cdk@latest
npm i aws-cdk-lib@latest
npm ls aws-cdk aws-cdk-lib
# cdk_test@0.1.0
# |----- aws-cdk-lib@2.133.0
# |----- aws-cdk@2.133.0
npm run cdk synth
npm run cdk deploy
npm run cdk diff |
Describe the bug
The reported number of stack differences on
cdk diff
is incorrectExpected Behavior
A stack with no diffs (e.g. just deployed cleanly) should report 0 differences
Current Behavior
Reproduction Steps
We're running aws-cdk and aws-cdk-lib on 2.96.2
Our
my-app
stack includes nested stacks such as aurora postgres, ECR, s3, ECS fargate. I can provide more detailed/redacted CDK code if you aren't able to reproducePossible Solution
It seems like this might be related to this: #26796, which was seemingly fixed in 2.93.0.
More precisely, likely something to do with this line which adds up stacks and nested stacks: https://github.com/aws/aws-cdk/pull/26796/files#diff-8cff125f4b53b025add8740ab74f39ee6c20221c0d3ac5ab7db184a6bb077398R154
Additional Information/Context
I just ran into this bug on 2.96.2 but also tested 2.93.0 with the same results.
CDK CLI Version
2.96.2
Framework Version
No response
Node.js Version
18.17.1
OS
Darwin jasonliu macbook 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64 x86_64
Language
Typescript
Language Version
typescript 5.1.6
Other information
No response
The text was updated successfully, but these errors were encountered: