Skip to content

fix(cli): gen2-migration lock --rollback reports false drift#14862

Open
iliapolo wants to merge 17 commits intodevfrom
epolon/e2e-rollback
Open

fix(cli): gen2-migration lock --rollback reports false drift#14862
iliapolo wants to merge 17 commits intodevfrom
epolon/e2e-rollback

Conversation

@iliapolo
Copy link
Copy Markdown
Contributor

@iliapolo iliapolo commented May 6, 2026

Description of changes

The lock --rollback command was failing because template drift detection reported false positives. For example, the RoleName property of an AWS::Cognito::UserPoolGroup resource changes during refactor, switching from the Gen1 role to the Gen2 role. Running drift detection after a successful rollback of refactor would still report this drift, even though it is expected and harmless.

This PR replaces the drift-based validation with a simpler, more reliable approach: per-resource stack integrity checks that verify expected resources still exist in the deployed stacks. If resources are missing, it means refactor --rollback wasn't run first. Here is an example of a failed validation report if lock --rollback is executed before refactor --rollback:

⚠️  WARNING: AWS Amplify Gen 1 CLI is in maintenance mode and will reach end of life on May 1, 2027.
During maintenance mode, only critical bug fixes and security patches will be provided.
Migrate to Amplify Gen 2: https://docs.amplify.aws/react/start/migrate-to-gen2/


→ Planning complete
→ Validating complete

Failed Validations Report

✘ Stack Integrity: amplify-storelocat2605052001-txuuzhyxdw-70d3e-authuserPoolGroups-1SJ18NH8VYGRJ

Following resources are missing. Did you forget to run 'amplify gen2-migration refactor --rollback'?

┌────────────────────────┬─────────────────────────────┐
│ Logical ID             │ Type                        │
├────────────────────────┼─────────────────────────────┤
│ storeLocatorAdminGroup │ AWS::Cognito::UserPoolGroup │
└────────────────────────┴─────────────────────────────┘

✘ Stack Integrity: amplify-storelocat2605052001-txuuzhyxdw-70d3e-authstorelocator41a9495f41a9495f-1M8SYEQAC0F2S

Following resources are missing. Did you forget to run 'amplify gen2-migration refactor --rollback'?

┌─────────────────────┬──────────────────────────────────────────┐
│ Logical ID          │ Type                                     │
├─────────────────────┼──────────────────────────────────────────┤
│ UserPool            │ AWS::Cognito::UserPool                   │
├─────────────────────┼──────────────────────────────────────────┤
│ UserPoolClientWeb   │ AWS::Cognito::UserPoolClient             │
├─────────────────────┼──────────────────────────────────────────┤
│ UserPoolClient      │ AWS::Cognito::UserPoolClient             │
├─────────────────────┼──────────────────────────────────────────┤
│ IdentityPool        │ AWS::Cognito::IdentityPool               │
├─────────────────────┼──────────────────────────────────────────┤
│ IdentityPoolRoleMap │ AWS::Cognito::IdentityPoolRoleAttachment │
└─────────────────────┴──────────────────────────────────────────┘

Validations Summary

┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────┬──────────┐
│ Validation                                                                                                    │ Status   │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────────┤
│ Stack Integrity: amplify-storelocat2605052001-txuuzhyxdw-70d3e-authuserPoolGroups-1SJ18NH8VYGRJ               │ ✘ Failed │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────────┤
│ Stack Integrity: amplify-storelocat2605052001-txuuzhyxdw-70d3e-authstorelocator41a9495f41a9495f-1M8SYEQAC0F2S │ ✘ Failed │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────┴──────────┘

🛑 Validations failed

E2E rollback flow

Extended the e2e migration flow to exercise the full round-trip: after the forward migration completes and gen2 tests pass, the flow now runs refactor --rollbacklock --rollbackpush → gen1 tests. This validates that rollback actually works end-to-end.

userAttributes in defineAuth

In #14841, we started rendering attributes returned from the SDK description of the user pool schema. This turned out to be wrong because the response contains all possible attributes, not only the ones that were actually configured. This means that post-refactor the user pool is trying to undergo an illegal update and fails.

This PR reverts the logic back to only render required attributes, which is what userAttributes seems to be dedicated for and is the Gen1 user actually set.

Issue #, if available

N/A

Description of how you validated changes

  • Unit tests updated and passing (lock.test.ts reduced from 26 to 11 focused tests)
  • E2E validation pending via yarn cloud-e2e

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Pull request labels are added

iliapolo added 2 commits May 5, 2026 21:45
…integrity checks

Template drift detection was reporting false positives during lock
--rollback, blocking the rollback from completing. Replace it with
per-resource stack integrity validation that checks whether expected
resources still exist in the deployed stacks.

Also renames config keys from lock/refactor to lockForward/refactorForward
to distinguish forward and rollback directions, adds rollback steps to
the e2e migration flow, and extends cfn-output-resolver to fall back to
physical resource ID when resolving Ref.
---
Prompt: commit my changes. no tests. just commit.
Restore the original curated resource type list for DeletionPolicy
instead of applying Retain to all non-stack resources. Update lock
rollback tests and post-refactor snapshots accordingly.
---
Prompt: made more changes. commit.
@iliapolo iliapolo changed the title Epolon/e2e rollback fix(cli): gen2-migration lock --rollback reports false drift May 6, 2026
@iliapolo iliapolo marked this pull request as ready for review May 6, 2026 17:23
@iliapolo iliapolo requested a review from a team as a code owner May 6, 2026 17:23
iliapolo added 13 commits May 6, 2026 17:19
…pping

The gen2 userAttributes property only maps to required attributes.
Optional attributes were incorrectly included, causing mismatches
with the gen2 auth construct type definition.

Also inlines the placeholder app name in cleanup-codebuild-resources
to remove the import dependency on amplify-e2e-core.
---
Prompt: commit my changes. no tests. no build. just commit.

expect(typeof board.id).toBe('string');
expect(board.id.length).toBeGreaterThan(0);
expect(board.name).toMatch(new RegExp(`^[🌅☀️🌙] ${name} \\(new!\\)$`));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just wrong and was failing the test - this query doesn't return these emojies.

const found = items.find((b: any) => b.id === created.id);
expect(found).toBeDefined();
expect(found.name).toBe(`📌 ${name}`);
expect(found.name).toBe(`(new!) ${name}`);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I changed the custom resolver to return a new string instead of an emoji.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant