Skip to content

Commit ff9afcc

Browse files
authored
Fix bind/unbind to resolve engine from bundle config, not just env var (#4894)
## Changes - `bind` and `unbind` now resolve the deployment engine from bundle config (`bundle.engine`), not just the `DATABRICKS_BUNDLE_ENGINE` env var. This matches how `deploy` and `destroy` already work. ## Why When `bundle.engine: direct` was set in config but the env var was unset, `bind` would silently create terraform state alongside `resources.json`, and `unbind` would fail with "No state file was found!" because it looked for terraform state. ## Tests - Added acceptance tests for both `bind` and `unbind` with `bundle.engine: direct` in config and no env var set, verifying the engine is resolved from config.
1 parent 476af5d commit ff9afcc

14 files changed

Lines changed: 117 additions & 20 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
bundle:
2+
name: engine-from-config
3+
engine: direct
4+
5+
resources:
6+
jobs:
7+
job_1:
8+
name: Updated Job

acceptance/bundle/deployment/bind/job/engine-from-config/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.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/engine-from-config/default/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
7+
=== State files after deploy ===
8+
.databricks/bundle/default/resources.json
9+
10+
>>> [CLI] bundle deployment unbind job_1
11+
Updating deployment state...
12+
13+
>>> [CLI] jobs create --json {"name": "My Job"}
14+
15+
>>> [CLI] bundle deployment bind job_1 [NUMID] --auto-approve
16+
Updating deployment state...
17+
Successfully bound job with an id '[NUMID]'
18+
Run 'bundle deploy' to deploy changes to your workspace
19+
=== State files after bind ===
20+
.databricks/bundle/default/resources.json
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Verify that bind respects bundle.engine config setting.
2+
#
3+
# bundle.engine is set to "direct" in databricks.yml.
4+
# Both deploy and bind should use the direct engine.
5+
6+
trace $CLI bundle deploy
7+
8+
echo "=== State files after deploy ==="
9+
find.py 'resources\.json|terraform\.tfstate$'
10+
11+
# Unbind so we can rebind
12+
trace $CLI bundle deployment unbind job_1
13+
14+
# Create a new job to bind to
15+
job_id=$(trace $CLI jobs create --json '{"name": "My Job"}' | jq -r '.job_id')
16+
17+
# Bind uses direct engine (reads bundle.engine from config).
18+
trace $CLI bundle deployment bind job_1 $job_id --auto-approve
19+
20+
echo "=== State files after bind ==="
21+
find.py 'resources\.json|terraform\.tfstate$'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Cloud = false # test leaves deployed job
2+
Ignore = [".databricks"]
3+
4+
# Omit DATABRICKS_BUNDLE_ENGINE so bind must read engine from bundle.engine config.
5+
[EnvMatrix]
6+
DATABRICKS_BUNDLE_ENGINE = []
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
bundle:
2+
name: engine-from-config
3+
engine: direct
4+
5+
resources:
6+
jobs:
7+
job_1:
8+
name: My Job

acceptance/bundle/deployment/unbind/engine-from-config/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.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/engine-from-config/default/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
7+
=== State files after deploy ===
8+
.databricks/bundle/default/resources.json
9+
10+
>>> [CLI] bundle deployment unbind job_1
11+
Updating deployment state...
12+
=== State files after unbind ===
13+
.databricks/bundle/default/resources.json
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Verify that unbind respects bundle.engine config setting.
2+
#
3+
# bundle.engine is set to "direct" in databricks.yml.
4+
# Both deploy and unbind should use the direct engine.
5+
6+
trace $CLI bundle deploy
7+
8+
echo "=== State files after deploy ==="
9+
find.py 'resources\.json|terraform\.tfstate$'
10+
11+
# Unbind uses direct engine (reads bundle.engine from config).
12+
trace $CLI bundle deployment unbind job_1
13+
14+
echo "=== State files after unbind ==="
15+
find.py 'resources\.json|terraform\.tfstate$'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Cloud = false # test leaves deployed job
2+
Ignore = [".databricks"]
3+
4+
# Omit DATABRICKS_BUNDLE_ENGINE so unbind must read engine from bundle.engine config.
5+
[EnvMatrix]
6+
DATABRICKS_BUNDLE_ENGINE = []

0 commit comments

Comments
 (0)