From 46c43031c7451ccfb8edd59bd7143f581273841b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20F=C3=BCrstenberg?= Date: Sun, 22 Nov 2026 11:59:52 +0100 Subject: [PATCH] fix(toolkit-lib): report termination protection changes during deploy When a deployment changes only the stack's termination protection, the change set is empty and the deploy reports "(no changes)", while the termination protection update itself was only logged at debug level. Report the update at info level so the user can see what changed. Refs aws/aws-cdk#32043 Co-Authored-By: Claude Opus 5.5 --- .../lib/api/deployments/deploy-stack.ts | 3 +- .../test/api/deployments/deploy-stack.test.ts | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/toolkit-lib/lib/api/deployments/deploy-stack.ts b/packages/@aws-cdk/toolkit-lib/lib/api/deployments/deploy-stack.ts index aef1adec8..9a8ced3e3 100644 --- a/packages/@aws-cdk/toolkit-lib/lib/api/deployments/deploy-stack.ts +++ b/packages/@aws-cdk/toolkit-lib/lib/api/deployments/deploy-stack.ts @@ -701,7 +701,8 @@ class FullCloudFormationDeployment { StackName: this.stackName, EnableTerminationProtection: terminationProtection, }); - await this.ioHelper.defaults.debug(format('Termination protection updated to %s for stack %s', terminationProtection, this.stackName)); + // Report this at info level: if the change set turns out to be empty, this is the only change the deployment makes + await this.ioHelper.defaults.info(format('%s: termination protection %s', chalk.bold(this.stackName), terminationProtection ? 'enabled' : 'disabled')); } } diff --git a/packages/@aws-cdk/toolkit-lib/test/api/deployments/deploy-stack.test.ts b/packages/@aws-cdk/toolkit-lib/test/api/deployments/deploy-stack.test.ts index c64746aed..02bc8c3c2 100644 --- a/packages/@aws-cdk/toolkit-lib/test/api/deployments/deploy-stack.test.ts +++ b/packages/@aws-cdk/toolkit-lib/test/api/deployments/deploy-stack.test.ts @@ -1391,6 +1391,51 @@ test('updateTerminationProtection called when termination protection is undefine }); }); +test.each([ + ['change-set' as const], + ['direct' as const], +])('termination protection change is reported when it is the only change (method=%s)', async (method) => { + // GIVEN + givenStackExists({ EnableTerminationProtection: true }); + givenTemplateIs(defaultTargetTemplate()); + givenCurrentChangeSetIsEmpty(); + if (method === 'direct') { + mockCloudFormationClient.on(UpdateStackCommand).rejects(new Error('No updates are to be performed.')); + } + + // WHEN + const ret = await testDeployStack({ + ...standardDeployStackArguments(), + deploymentMethod: { method }, + }); + + // THEN + expect(mockCloudFormationClient).toHaveReceivedCommandWith(UpdateTerminationProtectionCommand, { + StackName: 'withouterrors', + EnableTerminationProtection: false, + }); + expect(ret).toEqual(expect.objectContaining({ noOp: true })); + ioHost.expectMessage({ containing: 'termination protection disabled', level: 'info' }); +}); + +test('termination protection is not reported when it does not change', async () => { + // GIVEN + givenStackExists(); + givenCurrentChangeSetIsEmpty(); + + // WHEN + await testDeployStack({ + ...standardDeployStackArguments(), + forceDeployment: true, + }); + + // THEN + expect(mockCloudFormationClient).not.toHaveReceivedCommand(UpdateTerminationProtectionCommand); + expect(ioHost.notifySpy).not.toHaveBeenCalledWith(expect.objectContaining({ + message: expect.stringContaining('termination protection'), + })); +}); + describe('disable rollback', () => { test('by default, we do not disable rollback (and also do not pass the flag)', async () => { // WHEN