fix(toolkit-lib): cdk import fails on a stack that contains non-ASCII characters - #1988
HuzaifaChaudary wants to merge 2 commits into
Conversation
… characters
`cdk import` builds the IMPORT change set from the deployed template as returned
by `GetTemplate`, which flattens every codepoint above \u007f to a literal '?'.
The change set therefore carries a '?' where the deployed resource really holds
the original character, and CloudFormation rejects the import naming a resource
that is not part of it:
You have modified resources [<LogicalId>] in your template that are not
being imported.
`cdk diff` has compensated for the same mangling since aws/aws-cdk#25912, but
that lives in the diff formatter, so the import path never saw it. The import's
own pre-flight diff even prints "Omitted 1 changes because they are likely
mangled non-ASCII characters" and then submits the mangled template anyway.
The deployed template is now walked against the local one, and a deployed string
is replaced by the local one only when the local one mangles to exactly it. A
real modification does not match and is still submitted as a modification.
fixes aws#1915
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
mrgrain
left a comment
There was a problem hiding this comment.
Nice, thank you! This needs an integration test though.
mrgrain
left a comment
There was a problem hiding this comment.
Nice, thank you! This needs an integration test though.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1988 +/- ##
=======================================
Coverage 91.47% 91.47%
=======================================
Files 80 80
Lines 12675 12675
Branches 1792 1792
=======================================
Hits 11595 11595
Misses 1042 1042
Partials 38 38
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:
|
the importable stack can now carry a managed policy whose description has an em dash . the new test deploys it with a retained queue , drops the queue , then imports it back and expects IMPORT_COMPLETE .
Head branch was pushed to by a user without write access
|
added one in i could not run it against an account , i do not have one set up for the integ suite . what i did check is that it compiles with the package build , eslint is clean , and the app synths the policy with the em dash intact . the push will likely need the workflows approved again . |
Closes #1915
Reason for this change
cdk importbuilds the IMPORT change set from the deployed template as returned byGetTemplate, and that API flattens every codepoint above\u007fto a literal?. The submitted template then carries a?where the deployed resource really holds the original character, so CloudFormation rejects the import and names a resource the user never touched:cdk diffhas compensated for the same mangling since aws/aws-cdk#25912, but that lives in the diff formatter, so the import path never saw it. As @pahud noted on the issue, the import's own pre-flight diff printsOmitted 1 changes because they are likely mangled non-ASCII charactersand then submits the mangled template anyway.Description of changes
The deployed template is walked against the local one before the additions go in, and a deployed string is replaced by the local one only when
mangleLikeCloudFormation(local)equals it. Anything else is left as deployed, so a real modification is still submitted as a modification and still fails loudly. This is the first of the two approaches @pahud suggested; rebuilding from the synthesized template would also work but changes more than the mangling case.Two things worth flagging:
importer.tsbeside the existingaddDefaultDeletionPolicy. if you would rather have it incloudformation-diffnext tomangleLikeCloudFormation, say so and i will move it .Describe any new or updated permissions being added
None.
Description of how you validated changes
Two unit tests in
test/api/resource-import/import.test.ts: one asserts the submitted change set keeps the em dash whereGetTemplatereturned?, and one asserts a genuinely changed non-ASCII string is still submitted as deployed, so the healing cannot swallow a real edit. The first fails without the change.jeston the package is 1986 passed of 2049. The 62 failures are inbootstrap,sdk-providerandnotices/cached-data-sourceand are identical on an unmodified tree here, so they are this machine, not this change.eslintis clean on both changed files; the one error it reports for the package is inlib/api/aws-auth/base-credentials.ts, which this branch does not touch. I could not run thecli-integsuite, it needs a real AWS account.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license