@@ -235,6 +235,17 @@ export async function deployStack(options: DeployStackOptions): Promise<DeploySt
235
235
debug ( 'Initiated creation of changeset: %s; waiting for it to finish creating...' , changeSet . Id ) ;
236
236
const changeSetDescription = await waitForChangeSet ( cfn , deployName , changeSetName ) ;
237
237
238
+ // Update termination protection only if it has changed.
239
+ const terminationProtection = stackArtifact . terminationProtection ?? false ;
240
+ if ( ! ! cloudFormationStack . terminationProtection !== terminationProtection ) {
241
+ debug ( 'Updating termination protection from %s to %s for stack %s' , cloudFormationStack . terminationProtection , terminationProtection , deployName ) ;
242
+ await cfn . updateTerminationProtection ( {
243
+ StackName : deployName ,
244
+ EnableTerminationProtection : terminationProtection ,
245
+ } ) . promise ( ) ;
246
+ debug ( 'Termination protection updated to %s for stack %s' , terminationProtection , deployName ) ;
247
+ }
248
+
238
249
if ( changeSetHasNoChanges ( changeSetDescription ) ) {
239
250
debug ( 'No changes are to be performed on %s.' , deployName ) ;
240
251
await cfn . deleteChangeSet ( { StackName : deployName , ChangeSetName : changeSetName } ) . promise ( ) ;
@@ -262,17 +273,6 @@ export async function deployStack(options: DeployStackOptions): Promise<DeploySt
262
273
print ( 'Changeset %s created and waiting in review for manual execution (--no-execute)' , changeSetName ) ;
263
274
}
264
275
265
- // Update termination protection only if it has changed.
266
- const terminationProtection = stackArtifact . terminationProtection ?? false ;
267
- if ( cloudFormationStack . terminationProtection !== terminationProtection ) {
268
- debug ( 'Updating termination protection from %s to %s for stack %s' , cloudFormationStack . terminationProtection , terminationProtection , deployName ) ;
269
- await cfn . updateTerminationProtection ( {
270
- StackName : deployName ,
271
- EnableTerminationProtection : terminationProtection ,
272
- } ) . promise ( ) ;
273
- debug ( 'Termination protection updated to %s for stack %s' , terminationProtection , deployName ) ;
274
- }
275
-
276
276
return { noOp : false , outputs : cloudFormationStack . outputs , stackArn : changeSet . StackId ! , stackArtifact } ;
277
277
}
278
278
@@ -399,8 +399,7 @@ async function canSkipDeploy(deployStackOptions: DeployStackOptions, cloudFormat
399
399
}
400
400
401
401
// Termination protection has been updated
402
- const terminationProtection = deployStackOptions . stack . terminationProtection ?? false ; // cast to boolean for comparison
403
- if ( terminationProtection !== cloudFormationStack . terminationProtection ) {
402
+ if ( ! ! deployStackOptions . stack . terminationProtection !== ! ! cloudFormationStack . terminationProtection ) {
404
403
debug ( `${ deployName } : termination protection has been updated` ) ;
405
404
return false ;
406
405
}
0 commit comments