fix(aws-cdk): cdk migrate deduplication drops resources with compound identifiers - #1879
Open
Adityaj0 wants to merge 1 commit into
Open
fix(aws-cdk): cdk migrate deduplication drops resources with compound identifiers#1879Adityaj0 wants to merge 1 commit into
Adityaj0 wants to merge 1 commit into
Conversation
… identifiers deduplicateResources() in lib/commands/migrate.ts built its uniqueness key from only the FIRST key of a resource's ResourceIdentifier map. Several CloudFormation resource types (e.g. AWS::Route53::KeySigningKey, identified by the pair HostedZoneId + Name) have compound identifiers with more than one key. Two genuinely distinct resources sharing just the first key's value collided on the same synthetic identifier string and silently overwrote each other in the dedup map, so `cdk migrate --from-scan` could drop real resources from the generated template with no warning. Fix hashes on the full sorted set of ResourceIdentifier entries instead of just the first one. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adityaj0
requested a deployment
to
integ-approval
August 22, 2026 06:59 — with
GitHub Actions
Waiting
aws-cdk-automation
enabled auto-merge
August 22, 2026 06:59
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1879 +/- ##
==========================================
+ Coverage 91.10% 91.31% +0.21%
==========================================
Files 80 80
Lines 12205 12207 +2
Branches 1742 1750 +8
==========================================
+ Hits 11119 11147 +28
+ Misses 1050 1024 -26
Partials 36 36
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reason for this change
cdk migrate --from-scancan silently drop real, distinct resources from the generated CDK app/template.deduplicateResources()inpackages/aws-cdk/lib/commands/migrate.tscomputed its uniqueness key using only the first key of a resource'sResourceIdentifiermap:Some CloudFormation resource types have compound identifiers with more than one key (e.g.
AWS::Route53::KeySigningKeyis identified by the pairHostedZoneId+Name, as already documented elsewhere in this codebase inpackages/@aws-cdk/toolkit-lib/lib/api/resource-import/importer.ts). Two distinct resources that merely share the value of their first identifier key collided on the same dedup key and one silently overwrote the other, with no warning to the user.Description of changes
Changed
deduplicateResources()to build its uniqueness key from the full, sorted set ofResourceIdentifierentries instead of just the first one, so resources are only considered duplicates when their entire identifier matches.Description of how you validated changes
Added a regression test in
packages/aws-cdk/test/commands/migrate.test.tsthat scans two resources of typeAWS::Route53::KeySigningKeysharing the sameHostedZoneIdbut differentNamevalues, and asserts both are still sent toCreateGeneratedTemplateCommand. Verified the test fails against the pre-fix code (both resources collapse into one) and passes after the fix. Ran the fullmigrate.test.tssuite — all tests pass.Checklist
Closes #1878
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license