Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/cdkConstructs/src/changesets/checkDestructiveChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import {
Change as CloudFormationChange
} from "@aws-sdk/client-cloudformation"

const isConditionalCdkMetadataChange = (resourceChange: CloudFormationChange["ResourceChange"]): boolean => {
if (!resourceChange) {
return false
}

return resourceChange.LogicalResourceId === "CDKMetadata" &&
resourceChange.ResourceType === "AWS::CDK::Metadata" &&
String(resourceChange.Replacement ?? "") === "Conditional"
}

export type ChangeRequiringAttention = {
logicalId: string;
physicalId: string;
Expand Down Expand Up @@ -66,6 +76,10 @@ export function checkDestructiveChanges(
const action = resourceChange.Action
const isRemoval = action === "Remove"

if (replacementNeeded && isConditionalCdkMetadataChange(resourceChange)) {
return undefined
}

if (!replacementNeeded && !isRemoval) {
return undefined
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ describe("checkDestructiveChanges", () => {
}
])
})

test("ignores conditional CDK metadata replacements", () => {
const changeSet = {
Changes: [
{
ResourceChange: {
LogicalResourceId: "CDKMetadata",
PhysicalResourceId: "metadata-id",
ResourceType: "AWS::CDK::Metadata",
Replacement: "Conditional"
}
}
]
}

const replacements = checkDestructiveChanges(changeSet)

expect(replacements).toEqual([])
})
})

describe("checkDestructiveChangeSet", () => {
Expand Down