From 7f7f09a8a758686e65518ea95f9cf085f4a7a32c Mon Sep 17 00:00:00 2001 From: Calvin Combs Date: Thu, 17 Aug 2023 13:34:40 -0700 Subject: [PATCH 1/4] tmp --- packages/aws-cdk/lib/cdk-toolkit.ts | 2 +- packages/aws-cdk/test/diff.test.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk/lib/cdk-toolkit.ts b/packages/aws-cdk/lib/cdk-toolkit.ts index 1117271325e69..2a716c6096346 100644 --- a/packages/aws-cdk/lib/cdk-toolkit.ts +++ b/packages/aws-cdk/lib/cdk-toolkit.ts @@ -143,7 +143,7 @@ export class CdkToolkit { const currentTemplate = await this.props.deployments.readCurrentTemplateWithNestedStacks(stack, options.compareAgainstProcessedTemplate); diffs += options.securityOnly ? numberFromBool(printSecurityDiff(currentTemplate, stack, RequireApproval.Broadening)) - : printStackDiff(currentTemplate, stack, strict, contextLines, quiet, stream); + : printStackDiff(currentTemplate, stack, strict, contextLines, quiet, stream) > 0 ? 1 : 0; } } diff --git a/packages/aws-cdk/test/diff.test.ts b/packages/aws-cdk/test/diff.test.ts index 789c80c9a1e06..2779ab1feb37d 100644 --- a/packages/aws-cdk/test/diff.test.ts +++ b/packages/aws-cdk/test/diff.test.ts @@ -85,6 +85,8 @@ describe('non-nested stacks', () => { expect(exitCode).toBe(0); }); + test('diff reports correct number of stack diffs') + test('exits with 1 with diffs and fail set to true', async () => { // GIVEN const buffer = new StringWritable(); From 3a04dfd59e6a3680daaa23f0042ce74d9097ba28 Mon Sep 17 00:00:00 2001 From: Calvin Combs Date: Fri, 18 Aug 2023 09:42:56 -0700 Subject: [PATCH 2/4] testing + correct nested stack counting --- packages/aws-cdk/lib/api/deployments.ts | 10 +- .../aws-cdk/lib/api/nested-stack-helpers.ts | 28 +++++ packages/aws-cdk/lib/cdk-toolkit.ts | 16 ++- .../api/cloudformation-deployments.test.ts | 16 ++- packages/aws-cdk/test/diff.test.ts | 103 +++++++++++++----- 5 files changed, 134 insertions(+), 39 deletions(-) diff --git a/packages/aws-cdk/lib/api/deployments.ts b/packages/aws-cdk/lib/api/deployments.ts index a375bf25c4f65..cab9eb922a66d 100644 --- a/packages/aws-cdk/lib/api/deployments.ts +++ b/packages/aws-cdk/lib/api/deployments.ts @@ -6,7 +6,7 @@ import { ISDK } from './aws-auth/sdk'; import { CredentialsOptions, SdkForEnvironment, SdkProvider } from './aws-auth/sdk-provider'; import { deployStack, DeployStackResult, destroyStack, makeBodyParameterAndUpload, DeploymentMethod } from './deploy-stack'; import { HotswapMode } from './hotswap/common'; -import { loadCurrentTemplateWithNestedStacks, loadCurrentTemplate } from './nested-stack-helpers'; +import { loadCurrentTemplateWithNestedStacks, loadCurrentTemplate, flattenNestedStackNames, TemplateWithNestedStackCount } from './nested-stack-helpers'; import { ToolkitInfo } from './toolkit-info'; import { CloudFormationStack, Template, ResourcesToImport, ResourceIdentifierSummaries } from './util/cloudformation'; import { StackActivityProgress } from './util/cloudformation/stack-activity-monitor'; @@ -300,9 +300,13 @@ export class Deployments { public async readCurrentTemplateWithNestedStacks( rootStackArtifact: cxapi.CloudFormationStackArtifact, retrieveProcessedTemplate: boolean = false, - ): Promise