Skip to content

Commit c156b38

Browse files
committed
add stack
1 parent 2eef537 commit c156b38

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

packages/deploymentUtils/src/changesets/checkDestructiveChanges.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
*/
4148
export 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+
*/
7893
export 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

packages/deploymentUtils/tests/changesets/checkDestructiveChanges.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ describe("checkDestructiveChangeSet", () => {
144144
test("allows matching destructive changes when waiver is active", async () => {
145145
const changeSet = {
146146
CreationTime: "2026-02-20T11:54:17.083Z",
147+
StackName: "stack",
147148
Changes: [
148149
{
149150
ResourceChange: {
@@ -163,6 +164,7 @@ describe("checkDestructiveChangeSet", () => {
163164
PhysicalResourceId: "physical-id",
164165
ResourceType: "AWS::S3::Bucket",
165166
ExpiryDate: "2026-03-01T00:00:00Z",
167+
StackName: "stack",
166168
AllowedReason: "Pending migration"
167169
}
168170
]
@@ -187,6 +189,7 @@ describe("checkDestructiveChangeSet", () => {
187189
test("throws when waiver expired before change set creation", async () => {
188190
const changeSet = {
189191
CreationTime: "2026-02-20T11:54:17.083Z",
192+
StackName: "stack",
190193
Changes: [
191194
{
192195
ResourceChange: {
@@ -206,6 +209,7 @@ describe("checkDestructiveChangeSet", () => {
206209
PhysicalResourceId: "physical-id",
207210
ResourceType: "AWS::S3::Bucket",
208211
ExpiryDate: "2026-02-01T00:00:00Z",
212+
StackName: "stack",
209213
AllowedReason: "Expired waiver"
210214
}
211215
]

0 commit comments

Comments
 (0)