Skip to content

Don't fail migration if clean up actions fail - #6772

Open
denik wants to merge 8 commits into
mainfrom
denik/migration-backup-fix
Open

denik wants to merge 8 commits into
mainfrom
denik/migration-backup-fix

Conversation

@denik

@denik denik commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Once resources.json lands on the workspace (serial tf+1), any leftover terraform state files cannot affect engine selection because they carry a lower serial. The terraform backup/delete steps are cleanup, not commit.

Simplify: pushDirectState only uploads resources.json. Reuse BackupRemoteTerraformState (already fail-open) for the remote terraform cleanup, and make the local renames fail-open too. Remove rollbackRemoteMigration — there is nothing to roll back.

denik and others added 2 commits September 21, 2026 15:43
…ommit

When commitMigration fails after resources.json is pushed but before the
remote terraform.tfstate is deleted (e.g. on a 403 from DELETE), the
workspace was left with both state files. The next deploy found the stray
resources.json and never re-migrated cleanly.

Add rollbackRemoteMigration: on commit failure, delete remote resources.json
(ignore ErrNotExist) and, if the remote terraform.tfstate is gone (its DELETE
can succeed even when the response is lost), restore it from the .backup
pushDirectState wrote. The workspace is left terraform-authoritative so the
next deploy retries the migration from scratch.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Integration test report

Commit: e00ad7b

Run: 35614035505

Env ✅​pass 🙈​skip Time
✅​ aws linux 276 16 6:11
✅​ aws windows 278 14 5:50
✅​ azure linux 275 16 5:47
✅​ azure windows 277 14 3:45
✅​ gcp linux 276 16 6:12
✅​ gcp windows 278 14 5:10
Top 3 slowest tests (at least 2 minutes):
duration env testname
5:49 aws windows TestAccept
5:07 gcp windows TestAccept
3:43 azure windows TestAccept

denik and others added 3 commits September 21, 2026 16:15
Splitting commitMigration into pushMigrationToRemote (remote-only) and
finalizeLocalMigration (local-only) so rollback fires only on a remote-push
failure. Rolling back after the remote push already succeeded but a local
rename failed would revert the workspace to terraform while this checkout's
local direct state (higher serial) still wins on the next deploy, diverging
from the workspace. A local-finalize failure is instead left to converge on
retry, since the workspace is already direct-authoritative.

Co-authored-by: Isaac <no-reply@databricks.com>
Once resources.json lands on the workspace (serial tf+1), any leftover
terraform state files cannot affect engine selection because they carry a
lower serial. The terraform backup/delete steps are cleanup, not commit.

Simplify the commit path: pushDirectState only uploads resources.json.
Reuse BackupRemoteTerraformState (already fail-open with log.Warnf) for
the remote terraform cleanup, and make the local renames fail-open too.
Remove rollbackRemoteMigration — there is nothing to roll back.

Co-authored-by: Isaac <no-reply@databricks.com>
…esources.json committed

Co-authored-by: Isaac <no-reply@databricks.com>
@denik denik changed the title bundle: roll back remote state on failed terraform→direct migration commit Don't fail migration if clean up actions fail Sep 21, 2026
denik and others added 3 commits September 21, 2026 16:39
denik added a commit that referenced this pull request Sep 21, 2026
Adopt the approach from #6772: pushing resources.json (serial tf+1) is the hard
commit — once it lands, leftover terraform state carries a lower serial and can
no longer win engine selection, so backing up/deleting the terraform state
(remote and local) is best-effort cleanup, not part of the commit.

pushDirectState now only uploads resources.json. finalizeLocalMigration places
the converted state locally (still required — the deploy reads it) and then
best-effort cleans up the terraform state via BackupRemoteTerraformState and a
warn-on-failure local rename. Remove rollbackRemoteMigration — there is nothing
to roll back once resources.json has committed. Only a resources.json push
failure aborts the migration (fall back to terraform); a cleanup failure lets
the migration succeed with a warning.

auto-migrate-tfbackup-failure now asserts the migration succeeds with a warning
and keeps the .backup, instead of falling back.

Co-authored-by: Isaac <no-reply@databricks.com>
denik added a commit that referenced this pull request Sep 21, 2026
PR #6772 makes the terraform state cleanup after a migration commit fail-open on
main's post-deploy path. This branch already adopts the same approach in the
before-deploy path, so keep this branch's direct_migration.go (which supersedes
the post-deploy MigrateToDirect that #6772 edits) and take #6772's changelog
fragment. Stacking on #6772 so it lands first.

Co-authored-by: Isaac <no-reply@databricks.com>
@denik
denik enabled auto-merge September 21, 2026 15:16

This branch has not been deployed

No deployments
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.

3 participants