feat(cli): add retain command for gen2-migration#14843
Open
Conversation
retain command for gen2-migrationretain command for gen2-migration
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.
Fixes #14790
Description of changes
Adds a new
amplify gen2-migration retainstep and removes dead code left behind by the upstream decommission removal.retainsubcommandAfter migration, Gen1 CloudFormation stacks are defunct but still contain custom resources that may reference resources now owned by Gen2. Changes to those stacks can cause unintended impact on the Gen2 environment.
retainwalks every Gen1 stack below the root top-down and appliesDeletionPolicy: RetainandUpdateReplacePolicy: Retainto every resource exceptAWS::CloudFormation::Stackreferences. Once applied, the user can manually delete the Gen1 root stack and every underlying AWS resource survives as an orphan.Key design choices
Skip root
Updating the root post-refactor risks cascading
TemplateURLreconciliation through the entire tree. The user manually deletes the root afterretaincompletes; CloudFormation cascades through the already-retained children and every resource below root getsDELETE_SKIPPED.Skip
AWS::CloudFormation::StackreferencesAdding retain to a nested-stack reference would be a no-op for child protection — the child's own retain state is what matters when the cascade delete hits it. Leaving the reference entry untouched keeps the parent changeset strictly additive on non-stack attributes.
Per-operation changeset flow
Each stack's
fetchTemplate → createChangeSet → executeChangeSetround-trip happens inside the operation'sexecute()rather than at plan time. Creating all changesets up front would produceOBSOLETEchangesets on every parent execute.Strict whitelist
Every changeset is validated against a two-shape whitelist: direct
DeletionPolicy/UpdateReplacePolicyedits targetingRetain, or CloudFormation's own Automatic/Dynamic re-evaluations onAWS::CloudFormation::Stackreferences emitted on every parent update. Anything else (property edits,Add,Remove,Replacement: True) throwsMigrationError.One-way operation
--rollbackis rejected at the dispatcher andstep.rollback()throwsNotImplementedFault. To undo, the user edits the CloudFormation templates directly.Dead code removal
The upstream decommission removal left
validateStatefulResourcesand its private helpergetStatefulResourcesin_common/validations.tswith no remaining callers, plus 619 lines of tests, abottleneckdependency used only by those methods, and three unimplementedlogger.warn('Not implemented')stubs (validateDeploymentVersion,validateIsolatedEnvironment,validateIngressTraffic). All removed.Issue #, if available
#14790
Description of how you validated changes
mood-boardandproject-boardsinamplify-migration-apps/. After running the full migration workflow and invokingretain, the user-triggered manual root-stack delete completed successfully — all nested stack resources transitioned toDELETE_SKIPPEDand every underlying AWS resource (DynamoDB, Lambda, S3, Cognito, AppSync, Kinesis) survived as an orphan.test:gen1verified the retained resources are still reachable and the app continues to function.Checklist
yarn testpasses (for the changed packages)By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.