Skip to content

Migrate terraform state to direct before deploy - #6749

Draft
denik wants to merge 13 commits into
mainfrom
denik/migration-before-deploy
Draft

denik wants to merge 13 commits into
mainfrom
denik/migration-before-deploy

Conversation

@denik

@denik denik commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Moves the terraform→direct state migration to run in memory before plan/deploy instead of after a terraform deploy. This makes the terraform engine unnecessary for the default path (it is still used for an explicit engine: terraform opt-in). The terraform-engine removal is stacked on top of this PR.

WIP: migrate-test golden regeneration pending.

This pull request and its description were written by Isaac.

denik and others added 2 commits September 18, 2026 12:28
When the direct engine is requested (the default) and the existing state uses
terraform, convert it to a direct-engine state in memory before planning
(OpenMigratedTerraformState) and deploy on direct. The deploy's normal Finalize
commits resources.json only if it records changes; terraform.tfstate (local +
remote) is backed up only then. The terraform engine is unchanged and still used
for an explicit "engine: terraform" opt-in; the post-deploy dry-run migration is
removed. Golden regeneration for the migrate tests is pending.

Co-authored-by: Isaac <no-reply@databricks.com>
…gelog

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

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

Copy link
Copy Markdown
Collaborator

Integration test report

Commit: 47ab384

Run: 35339590823

Env ✅​pass 🙈​skip Time
✅​ aws linux 276 29 5:20
✅​ aws windows 278 27 6:02
✅​ azure linux 275 29 4:39
✅​ azure windows 277 27 5:58
✅​ gcp linux 276 29 5:35
✅​ gcp windows 278 27 6:00
Top 3 slowest tests (at least 2 minutes):
duration env testname
5:58 aws windows TestAccept
5:56 azure windows TestAccept
5:55 gcp windows TestAccept

denik and others added 11 commits September 18, 2026 13:25
Plan-check the converted state before committing; on failure, warn and deploy on
terraform this time (no commit). Update the auto-migrate-direct-only titles to the
new behavior (plan/deploy now create the direct-only resource via the in-memory
migration).

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Empty/direct env on a terraform state now migrates to direct before planning, so
those steps run on the direct engine (not terraform). Update the user-agent
assertions and comments, and ignore .databricks (migration writes state files).

Co-authored-by: Isaac <no-reply@databricks.com>
…aformState

Call MigrateToDirect before plan/deploy and re-resolve state afterwards, instead
of a separate in-memory reimplementation. On a failed migration plan check it
warns and leaves terraform state intact, so the run falls back to the terraform
engine. Remove the //deadcode:allow markers (all helpers are reachable now) and
regenerate the migrate/state/resource_deps/telemetry goldens.

Co-authored-by: Isaac <no-reply@databricks.com>
The prior regen baked a script failure (rm of an already-backed-up terraform.tfstate)
into the golden. state_present will be reworked once the bundle-plan migration behavior
is decided.

Co-authored-by: Isaac <no-reply@databricks.com>
…MigrateToDirect

MigrateTerraformState converts terraform state to direct and opens the state DB:
in memory for plan (no writes/pushes), and committing on deploy (resources.json
written+pushed, terraform.tfstate backed up) after a plan check that falls back
to terraform on failure. Delete the post-deploy MigrateToDirect and its dry-run
telemetry helpers (no longer used); no deadcode markers.

Co-authored-by: Isaac <no-reply@databricks.com>
…it migration

Co-authored-by: Isaac <no-reply@databricks.com>
… for pre-deploy migration

Empty/direct-env plan migrates in memory (no commit) so it runs on direct without
backing up terraform.tfstate; deploy migrates and commits. Update state_present
user-agent assertions/comments and ignore .databricks.

Co-authored-by: Isaac <no-reply@databricks.com>
…igation

The empty-env 'bundle plan' runs on terraform, not direct, contradicting the
in-memory-migrate-on-plan design; -update baked that assertion failure into the
golden. state_present is reverted to main pending a proper fix of the plan path.

Co-authored-by: Isaac <no-reply@databricks.com>
…esent

PullResourcesState set the user-agent engine tag from the terraform state file;
after migrating in memory to direct, update it to engine/direct so requests
reflect the engine actually running. Rework state_present: empty/direct-env plan
now runs on direct (in-memory migration, no commit), the explicit terraform
deploy stays on terraform, and the post-migration serial is 6 (one fewer write
than the old post-deploy migration).

Co-authored-by: Isaac <no-reply@databricks.com>
Migrating deploys/plans now report engine/direct in the user-agent (matching the
engine actually running), so regenerate migrate/state/resource_deps/telemetry/
user_agent/snapshot-comparison goldens.

Co-authored-by: Isaac <no-reply@databricks.com>
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.

2 participants