Skip to content

Auto-migrate to direct engine when opted in and dry-run is clean#5858

Draft
denik wants to merge 5 commits into
mainfrom
denik/engine-migrate-optin
Draft

Auto-migrate to direct engine when opted in and dry-run is clean#5858
denik wants to merge 5 commits into
mainfrom
denik/engine-migrate-optin

Conversation

@denik

@denik denik commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • When a bundle has bundle.engine: direct (or DATABRICKS_BUNDLE_ENGINE=direct) but the state file is still terraform, a deploy currently deploys under terraform and only dry-runs the migration for telemetry. This PR commits that dry-run in place when it's clean: rename the converted state to resources.json, back up terraform.tfstate, and push the new state to the workspace.
  • If the dry-run surfaces errors or warnings, auto-migration is skipped with a warning telling the user to run databricks bundle deployment migrate manually.
  • Threads the already-resolved EngineSetting from process.go through phases.DeploydeployCoreCheckDirectMigration so the same "config > env" priority used by PullResourcesState decides opt-in. Renames the misleading targetEngine parameter to stateEngine.

Test plan

  • acceptance/bundle/migrate/auto-migrate-clean — covers bundle.engine: direct opt-in path
  • acceptance/bundle/migrate/auto-migrate-envvar — covers DATABRICKS_BUNDLE_ENGINE=direct opt-in path
  • existing acceptance/bundle/telemetry/deploy still passes (dry-run telemetry unchanged when not opted in)
  • existing acceptance/bundle/migrate and acceptance/bundle/deploy suites pass

This pull request and its description were written by Isaac.

@denik denik temporarily deployed to test-trigger-is July 8, 2026 11:42 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is July 8, 2026 11:42 — with GitHub Actions Inactive
@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Integration test report

Commit: 6c09183

Run: 28972130684

Env 🟨​KNOWN 🔄​flaky 💚​RECOVERED 🙈​SKIP ✅​pass 🙈​skip Time
💚​ aws linux 4 4 230 1074 4:05
💚​ aws windows 4 4 232 1072 4:07
💚​ aws-ucws linux 4 4 314 992 6:42
💚​ aws-ucws windows 4 4 316 990 5:11
🔄​ azure linux 1 4 4 229 1073 5:00
🔄​ azure windows 1 4 4 231 1071 4:40
🟨​ azure-ucws linux 3 1 4 316 989 8:44
🟨​ azure-ucws windows 3 1 4 318 987 7:27
💚​ gcp linux 4 4 229 1075 4:09
💚​ gcp windows 4 4 231 1073 4:16
10 interesting tests: 4 SKIP, 3 KNOWN, 2 flaky, 1 RECOVERED
Test Name aws linux aws windows aws-ucws linux aws-ucws windows azure linux azure windows azure-ucws linux azure-ucws windows gcp linux gcp windows
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
🙈​ TestAccept/bundle/invariant/no_drift 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_endpoints/drift/recreated_same_name 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_indexes/recreate/embedding_dimension 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/ssh/connection 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🔄​ TestSyncFullFileSync ✅​p ✅​p ✅​p ✅​p ✅​p 🔄​f ✅​p ✅​p ✅​p ✅​p
🔄​ TestFilerWorkspaceFilesExtensionsDelete ✅​p ✅​p ✅​p ✅​p 🔄​f ✅​p ✅​p ✅​p ✅​p ✅​p
🟨​ TestFetchRepositoryInfoAPI_FromRepo 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 🟨​K 🟨​K 💚​R 💚​R
🟨​ TestFetchRepositoryInfoAPI_FromRepo/root 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 🟨​K 🟨​K 💚​R 💚​R
🟨​ TestFetchRepositoryInfoAPI_FromRepo/subdir 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 🟨​K 🟨​K 💚​R 💚​R
Top 5 slowest tests (at least 2 minutes):
duration env testname
3:15 azure windows TestAccept
3:12 gcp windows TestAccept
3:08 azure-ucws windows TestAccept
3:07 aws windows TestAccept
3:03 aws-ucws windows TestAccept

@denik denik closed this Jul 8, 2026
@denik denik reopened this Jul 8, 2026
denik added 5 commits July 8, 2026 21:56
When bundle.engine is set to "direct" (or DATABRICKS_BUNDLE_ENGINE=direct)
and the just-deployed terraform state can be dry-run migrated with no
errors and no warnings, commit the migration in place instead of just
recording telemetry: rename the converted state to resources.json, move
terraform.tfstate to .backup, and push the new state to the workspace.
If the dry-run surfaces issues, emit a warning that auto-migration is
stopped and leave the state as-is.

Threads the resolved EngineSetting from process.go through phases.Deploy
and deployCore into CheckDirectMigration so the same "config > env"
priority already used by PullResourcesState decides opt-in. Renames the
misleading targetEngine parameter to stateEngine (it's the state's
engine, not any deploy target).

Co-authored-by: Isaac
The state_present test's first stanza exercised
DATABRICKS_BUNDLE_ENGINE=direct against a seeded terraform state to
assert "state wins over env var mismatch." Auto-migration now treats
that env var as an opt-in signal and rewrites the state at the end of
the deploy, which changes what the follow-up assertions observe.

The rest of the file already covers state precedence for empty and
terraform env-var values, so drop the direct-env stanza to keep the
test focused on the resolver contract. Auto-migration under a
direct-opt-in signal is covered separately in
acceptance/bundle/migrate/auto-migrate-envvar.

Co-authored-by: Isaac
The previous synchronize event did not fire the build workflow for
some reason; nudge it with an empty commit.

Co-authored-by: Isaac
- Warning when direct is requested and state is terraform now reads
  "Using X engine for deployment, then will try to migrate your state
  to direct engine" so the user knows the state-wins outcome is only
  temporary. Regenerated the golden in state/engine_mismatch.

- "Migrated N resource(s) to direct deployment engine." now reports
  the resource count.

- Emit new bool telemetry keys migrated-via-config / migrated-via-env
  when auto-migration actually rewrites the state, so we can slice by
  opt-in source.

- Test coverage: put the new auto-migrate tests under
  EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] instead of [] so
  they participate in the CI engine-filter; extend auto-migrate-clean
  to end with a no-op deploy, a config edit, and a with/without --plan
  deploy of the resulting update (READPLAN matrix).

Co-authored-by: Isaac
- Rename bundle/statemgmt/check_direct_migration.go to direct_migration.go
  and the top-level function CheckDirectMigration → MigrateToDirect. The
  old name suggested a passive check, but the function now can rewrite
  state when the user opts in.

- Split metrics: DirectDryMigrate{Success,Warnings} now fire ONLY when
  the conversion is truly a dry run (no opt-in). When the user opted in,
  emit the new direct_migrate_error / direct_migrate_commit_error /
  direct_migrate_warnings keys instead, matching the two failure paths
  (state conversion vs. commit) and the warnings case.

Co-authored-by: Isaac
@denik denik force-pushed the denik/engine-migrate-optin branch from f385901 to 6c09183 Compare July 8, 2026 20:05
@denik denik temporarily deployed to test-trigger-is July 8, 2026 20:06 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is July 8, 2026 20:06 — with GitHub Actions Inactive
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