@@ -17,6 +17,7 @@ export type AllowedDestructiveChange = {
1717 PhysicalResourceId : string ;
1818 ResourceType : string ;
1919 ExpiryDate : string | Date ;
20+ StackName : string ;
2021 AllowedReason : string ;
2122}
2223
@@ -38,6 +39,12 @@ const toDate = (value: Date | string | number | undefined | null): Date | undefi
3839 return Number . isNaN ( date . getTime ( ) ) ? undefined : date
3940}
4041
42+ /**
43+ * Extracts the subset of CloudFormation changes that either require replacement or remove resources.
44+ *
45+ * @param changeSet - Raw change-set details returned from `DescribeChangeSet`.
46+ * @returns Array of changes that need operator attention.
47+ */
4148export function checkDestructiveChanges (
4249 changeSet : DescribeChangeSetCommandOutput | undefined | null
4350) : Array < ChangeRequiringAttention > {
@@ -75,6 +82,14 @@ export function checkDestructiveChanges(
7582 . filter ( ( change ) : change is ChangeRequiringAttention => Boolean ( change ) )
7683}
7784
85+ /**
86+ * Describes a CloudFormation change set, applies waiver logic, and throws if destructive changes remain.
87+ *
88+ * @param changeSetName - Name or ARN of the change set.
89+ * @param stackName - Name or ARN of the stack that owns the change set.
90+ * @param region - AWS region where the stack resides.
91+ * @param allowedChanges - Optional waivers that temporarily allow specific destructive changes.
92+ */
7893export async function checkDestructiveChangeSet (
7994 changeSetName : string ,
8095 stackName : string ,
@@ -93,6 +108,7 @@ export async function checkDestructiveChangeSet(
93108 const response : DescribeChangeSetCommandOutput = await client . send ( command )
94109 const destructiveChanges = checkDestructiveChanges ( response )
95110 const creationTime = toDate ( response . CreationTime )
111+ const changeSetStackName = response . StackName
96112
97113 const remainingChanges = destructiveChanges . filter ( change => {
98114 const waiver = allowedChanges . find ( allowed =>
@@ -101,7 +117,7 @@ export async function checkDestructiveChangeSet(
101117 allowed . ResourceType === change . resourceType
102118 )
103119
104- if ( ! waiver || ! creationTime ) {
120+ if ( ! waiver || ! creationTime || ! changeSetStackName || waiver . StackName !== changeSetStackName ) {
105121 return true
106122 }
107123
0 commit comments