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