Skip to content

Commit 7826da9

Browse files
authored
bundle migrate: handle added/removed resources gracefully (#5463)
## Changes - Update "bundle deployment migrate" to support added/removed resources: - If resource is present in databricks.yml but not in terraform state the migrate command no longer fails, it skips the resource, it'll be deployed by direct engine. - If resource is present in the state but not in databricks.yml, migration preserves their ID in the state so that it can be deleted by direct engine. ## Why Towards auto-migration: we should migrate any situation without errors. ## Tests New acceptance tests.
1 parent 098788b commit 7826da9

22 files changed

Lines changed: 222 additions & 15 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Bundles
1010
* Set the default `data_security_mode` to `DATA_SECURITY_MODE_AUTO` in bundle templates ([#5452](https://github.com/databricks/cli/pull/5452)).
1111
* Mark vector search index index_subtype as backend_default to prevent drift after deployment ([#5454](https://github.com/databricks/cli/pull/5454)).
12+
* `bundle deployment migrate`: handle resources added to or removed from `databricks.yml` since the last Terraform deploy ([#5463](https://github.com/databricks/cli/pull/5463)).
1213

1314
### Dependency updates
1415

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bundle:
2+
name: migrate-added-test
3+
4+
resources:
5+
jobs:
6+
job_a: {name: "Job A"}
7+
#job_b: {name: "Job B"}

acceptance/bundle/migrate/added/out.test.toml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-added-test/default/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
7+
8+
>>> musterr [CLI] bundle deployment migrate
9+
Note: Migration should be done after a full deploy. Running plan now to verify that deployment was done:
10+
create jobs.job_b
11+
12+
Plan: 1 to add, 0 to change, 0 to delete, 1 unchanged
13+
Error: 'databricks bundle plan' shows actions planned, aborting migration. Please run 'databricks bundle deploy' first to ensure your bundle is up to date, If actions persist after deploy, skip plan check with --noplancheck option
14+
15+
>>> [CLI] bundle deployment migrate --noplancheck
16+
Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json
17+
18+
Validate the migration by running "databricks bundle plan", there should be no actions planned.
19+
20+
The state file is not synchronized to the workspace yet. To do that and finalize the migration, run "bundle deploy".
21+
22+
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
23+
24+
25+
>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan
26+
create jobs.job_b
27+
28+
Plan: 1 to add, 0 to change, 0 to delete, 1 unchanged
29+
30+
>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy
31+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-added-test/default/files...
32+
Deploying resources...
33+
Updating deployment state...
34+
Deployment complete!
35+
36+
>>> print_requests.py //jobs/create
37+
{
38+
"headers": {
39+
"User-Agent": [
40+
"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID] interactive/none engine/direct auth/pat"
41+
]
42+
},
43+
"method": "POST",
44+
"path": "/api/2.2/jobs/create",
45+
"body": {
46+
"deployment": {
47+
"kind": "BUNDLE",
48+
"metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-added-test/default/state/metadata.json"
49+
},
50+
"edit_mode": "UI_LOCKED",
51+
"format": "MULTI_TASK",
52+
"max_concurrent_runs": 1,
53+
"name": "Job B",
54+
"queue": {
55+
"enabled": true
56+
}
57+
}
58+
}
59+
60+
>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan
61+
Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export DATABRICKS_BUNDLE_ENGINE=terraform
2+
3+
# Deploy with terraform (only job_a; job_b is commented out)
4+
trace $CLI bundle deploy
5+
6+
# Uncomment job_b (add it to config without deploying)
7+
update_file.py databricks.yml "#job_b" "job_b"
8+
9+
# Should fail at plan check: job_b is "1 to add"
10+
trace musterr $CLI bundle deployment migrate
11+
12+
# Should succeed: job_b skipped, will be created on next deploy
13+
trace $CLI bundle deployment migrate --noplancheck
14+
15+
# After migration: plan shows job_b as "to add"
16+
trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "1 to add"
17+
18+
# Deploy creates job_b; verify via recorded requests
19+
rm out.requests.txt
20+
trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy
21+
trace print_requests.py //jobs/create
22+
23+
# No further actions planned
24+
trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "2 unchanged"
25+
26+
rm out.requests.txt

acceptance/bundle/migrate/basic/out.test.toml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

acceptance/bundle/migrate/dashboards/out.test.toml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

acceptance/bundle/migrate/default-python/out.test.toml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)