Skip to content

Commit e97c00c

Browse files
denikclaude
andauthored
Add bundle.engine config setting for deployment engine selection (#4749)
## Summary Add a new `engine` field at the bundle/target level that allows users to configure the deployment engine (`"terraform"` or `"direct"`) in their bundle config. ### Behavior - New bundles (no existing state): uses the configured engine, or defaults to `terraform` - Existing bundles (state present): if the configured engine doesn't match state, a **warning** is issued pointing to the config source, and the existing state's engine is used. Note, this is different from current behaviour, where databricks CLI refuses to proceed with config/state mismatch. - Priority: state > `DATABRICKS_BUNDLE_ENGINE` env var > `bundle.engine` config > default ### Example ```yaml bundle: name: my-bundle engine: direct targets: production: bundle: engine: terraform ``` ## Test plan Unit tests and acceptance tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 146c0dc commit e97c00c

58 files changed

Lines changed: 518 additions & 169 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

NEXT_CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Release v0.295.0
44

5+
### Notable Changes
6+
7+
- Add `bundle.engine` config setting to select the deployment engine (`terraform` or `direct`). The `DATABRICKS_BUNDLE_ENGINE` environment variable takes precedence over this setting. When the configured engine doesn't match existing deployment state, a warning is issued and the existing engine is used ([#4749](https://github.com/databricks/cli/pull/4749)).
8+
59
### CLI
610

711
### Bundles
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Error: --plan is only supported with direct engine (set DATABRICKS_BUNDLE_ENGINE=direct)
1+
Error: --plan is only supported with direct engine (set bundle.engine to "direct" or DATABRICKS_BUNDLE_ENGINE=direct)
22

33

44
Exit code: 1

acceptance/bundle/migrate/basic/out.plan_update.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"plan_version": 2,
33
"cli_version": "[DEV_VERSION]",
44
"lineage": "[UUID]",
5-
"serial": 7,
5+
"serial": 8,
66
"plan": {
77
"resources.jobs.test_job": {
88
"action": "update",

acceptance/bundle/migrate/basic/output.txt

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
>>> musterr [CLI] bundle deployment migrate
33
Error: This command migrates the existing Terraform state file (terraform.tfstate) to a direct deployment state file (resources.json). However, no existing local or remote state was found.
44

5-
To start using direct engine, deploy with DATABRICKS_BUNDLE_ENGINE=direct env var set.
5+
To start using direct engine, set "engine: direct" under bundle in your databricks.yml or deploy with DATABRICKS_BUNDLE_ENGINE=direct env var set.
66

77
>>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy
88
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files...
@@ -27,26 +27,19 @@ To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/dev/resources.js
2727
>>> jq .state."resources.pipelines.test_pipeline".state.tags.volume_storage_location out.new_state.json
2828
"s3://deco-uc-prod-isolated-aws-us-east-1/metastore/[UUID]/volumes/[UUID]"
2929

30-
>>> DATABRICKS_BUNDLE_ENGINE=terraform musterr [CLI] bundle plan
31-
Error: Required engine "terraform" does not match present state files. Clear "DATABRICKS_BUNDLE_ENGINE" env var to use engine appropriate for the state.
32-
33-
Available state files:
34-
- terraform.tfstate: remote terraform state serial=4 lineage="[UUID]"
35-
- [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=6 lineage="[UUID]"
36-
37-
38-
>>> DATABRICKS_BUNDLE_ENGINE=terraform musterr [CLI] bundle deploy
39-
Error: Required engine "terraform" does not match present state files. Clear "DATABRICKS_BUNDLE_ENGINE" env var to use engine appropriate for the state.
40-
41-
Available state files:
42-
- terraform.tfstate: remote terraform state serial=4 lineage="[UUID]"
43-
- [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=6 lineage="[UUID]"
30+
>>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle plan
31+
Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged
4432

33+
>>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy
34+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files...
35+
Deploying resources...
36+
Updating deployment state...
37+
Deployment complete!
4538

4639
=== Should show that it's already migrated
4740
>>> musterr [CLI] bundle deployment migrate
4841
Error: already using direct engine
49-
Details: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=6 lineage="[UUID]"
42+
Details: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=7 lineage="[UUID]"
5043

5144
>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan
5245
Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged
@@ -93,14 +86,14 @@ Deployment complete!
9386
=== Should show that it's already migrated
9487
>>> musterr [CLI] bundle deployment migrate
9588
Error: already using direct engine
96-
Details: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=7 lineage="[UUID]"
89+
Details: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=8 lineage="[UUID]"
9790

9891
>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states
99-
[TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=7 lineage="[UUID]"
92+
[TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=8 lineage="[UUID]"
10093

10194
>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states --force-pull
102-
resources.json: remote direct state serial=7 lineage="[UUID]"
103-
[TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=7 lineage="[UUID]"
95+
resources.json: remote direct state serial=8 lineage="[UUID]"
96+
[TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=8 lineage="[UUID]"
10497

10598
=== Extra plan: should have no drift
10699
>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan

acceptance/bundle/migrate/basic/script

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ rm out.backup_state.json
1414
# check that this is stored as resolved value, not as reference:
1515
trace jq '.state."resources.pipelines.test_pipeline".state.tags.volume_storage_location' out.new_state.json | contains.py 's3://'
1616

17-
# this is expected to fail because state does not match env var
18-
trace DATABRICKS_BUNDLE_ENGINE=terraform musterr $CLI bundle plan
19-
trace DATABRICKS_BUNDLE_ENGINE=terraform musterr $CLI bundle deploy
17+
# this is expected to warn because state does not match env var, but still succeed using state engine
18+
trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle plan
19+
trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy
2020

2121
title "Should show that it's already migrated"
2222
trace musterr $CLI bundle deployment migrate

acceptance/bundle/migrate/dashboards/out.plan_after_migrate.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"plan_version": 2,
33
"cli_version": "[DEV_VERSION]",
44
"lineage": "[UUID]",
5-
"serial": 3,
5+
"serial": 4,
66
"plan": {
77
"resources.dashboards.dashboard1": {
88
"action": "skip",

acceptance/bundle/migrate/dashboards/output.txt

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,14 @@ The state file is not synchronized to the workspace yet. To do that and finalize
1717
To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/default/resources.json and rename [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate.backup to [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate
1818

1919

20-
>>> DATABRICKS_BUNDLE_ENGINE=terraform musterr [CLI] bundle plan
21-
Error: Required engine "terraform" does not match present state files. Clear "DATABRICKS_BUNDLE_ENGINE" env var to use engine appropriate for the state.
22-
23-
Available state files:
24-
- terraform.tfstate: remote terraform state serial=1 lineage="[UUID]"
25-
- [TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=3 lineage="[UUID]"
26-
27-
28-
>>> DATABRICKS_BUNDLE_ENGINE=terraform musterr [CLI] bundle deploy
29-
Error: Required engine "terraform" does not match present state files. Clear "DATABRICKS_BUNDLE_ENGINE" env var to use engine appropriate for the state.
30-
31-
Available state files:
32-
- terraform.tfstate: remote terraform state serial=1 lineage="[UUID]"
33-
- [TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=3 lineage="[UUID]"
20+
>>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle plan
21+
Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
3422

23+
>>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy
24+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
25+
Deploying resources...
26+
Updating deployment state...
27+
Deployment complete!
3528

3629
>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan
3730
Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
@@ -54,11 +47,11 @@ Deployment complete!
5447
=== Should show that it's already migrated
5548
>>> musterr [CLI] bundle deployment migrate
5649
Error: already using direct engine
57-
Details: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=4 lineage="[UUID]"
50+
Details: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=5 lineage="[UUID]"
5851

5952
>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states
60-
[TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=4 lineage="[UUID]"
53+
[TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=5 lineage="[UUID]"
6154

6255
>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states --force-pull
63-
resources.json: remote direct state serial=4 lineage="[UUID]"
64-
[TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=4 lineage="[UUID]"
56+
resources.json: remote direct state serial=5 lineage="[UUID]"
57+
[TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=5 lineage="[UUID]"

acceptance/bundle/migrate/dashboards/script

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ print_state.py > out.original_state.json
66
trace $CLI bundle deployment migrate 2>&1 | contains.py 'Migrated 1 resources'
77
print_state.py > out.new_state.json
88

9-
# this is expected to fail because state does not match env var
10-
trace DATABRICKS_BUNDLE_ENGINE=terraform musterr $CLI bundle plan
11-
trace DATABRICKS_BUNDLE_ENGINE=terraform musterr $CLI bundle deploy
9+
# this is expected to warn because state does not match env var, but still succeed using state engine
10+
trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle plan
11+
trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy
1212

1313
rm out.requests.txt
1414
# Both DATABRICKS_BUNDLE_ENGINE=direct and DATABRICKS_BUNDLE_ENGINE= work
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bundle:
2+
name: test-migrate-engine
3+
engine: direct

acceptance/bundle/migrate/engine-config-direct/out.test.toml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)