From bab79343cf0508de9a2f51d06069be2ca010cae6 Mon Sep 17 00:00:00 2001 From: Andres Garcia Date: Thu, 22 Oct 2026 00:10:23 +0000 Subject: [PATCH 1/3] knowledge_base: add bind_existing_resources example Generate bundle config for an existing job and dashboard, bind them, deploy, then unbind and destroy without deleting the workspace resources. Co-authored-by: Isaac Co-authored-by: omnigent --- .../bind_existing_resources/.gitignore | 1 + .../bind_existing_resources/README.md | 41 +++++++++++++++++++ .../bind_existing_resources/databricks.yml | 31 ++++++++++++++ .../existing_dashboard.dashboard.yml | 9 ++++ .../resources/existing_job.job.yml | 24 +++++++++++ .../src/existing_dashboard.lvdash.json | 18 ++++++++ .../bind_existing_resources/src/hello.py | 2 + 7 files changed, 126 insertions(+) create mode 100644 knowledge_base/bind_existing_resources/.gitignore create mode 100644 knowledge_base/bind_existing_resources/README.md create mode 100644 knowledge_base/bind_existing_resources/databricks.yml create mode 100644 knowledge_base/bind_existing_resources/resources/existing_dashboard.dashboard.yml create mode 100644 knowledge_base/bind_existing_resources/resources/existing_job.job.yml create mode 100644 knowledge_base/bind_existing_resources/src/existing_dashboard.lvdash.json create mode 100644 knowledge_base/bind_existing_resources/src/hello.py diff --git a/knowledge_base/bind_existing_resources/.gitignore b/knowledge_base/bind_existing_resources/.gitignore new file mode 100644 index 00000000..15bcc6dd --- /dev/null +++ b/knowledge_base/bind_existing_resources/.gitignore @@ -0,0 +1 @@ +.databricks diff --git a/knowledge_base/bind_existing_resources/README.md b/knowledge_base/bind_existing_resources/README.md new file mode 100644 index 00000000..1cd50d33 --- /dev/null +++ b/knowledge_base/bind_existing_resources/README.md @@ -0,0 +1,41 @@ +# Bind existing resources + +This Declarative Automation Bundles example puts an existing job and dashboard under bundle management. +It generates the configuration, binds it to the workspace resources, deploys it, and then unbinds it. + +For more information, see the [bind documentation](https://docs.databricks.com/dev-tools/bundles/migrate-resources.html). + +## Prerequisites + +* Databricks CLI v1.20.0 or above +* A workspace with serverless jobs and a SQL warehouse named `Serverless Starter Warehouse`. +* An existing job and an existing AI/BI dashboard. Copy their IDs from the workspace URLs. + +## Usage + +1. Generate the job configuration. This replaces the sample files in `resources/` and `src/`: + `databricks bundle generate job --existing-job-id --key existing_job --force --profile ` +2. Generate the dashboard configuration: + `databricks bundle generate dashboard --existing-id --key existing_dashboard --force --profile ` +3. In `resources/existing_dashboard.dashboard.yml`, replace the literal `warehouse_id` with `${var.warehouse_id}`. +4. In the same file, set `parent_path: ${var.dashboard_parent_path}`. +5. Set the folder of the existing dashboard: `export BUNDLE_VAR_dashboard_parent_path=/Workspace/Users//` +6. Bind the job: `databricks bundle deployment bind existing_job -t prod --profile ` +7. Bind the dashboard: `databricks bundle deployment bind existing_dashboard -t prod --profile ` +8. Show the changes that the deploy makes: `databricks bundle plan -t prod --profile ` +9. Deploy the bundle: `databricks bundle deploy -t prod --profile ` +10. Run the job: `databricks bundle run existing_job -t prod --profile ` +11. Unbind the job: `databricks bundle deployment unbind existing_job -t prod --profile ` +12. Unbind the dashboard: `databricks bundle deployment unbind existing_dashboard -t prod --profile ` +13. Remove the bundle files: `databricks bundle destroy -t prod --profile ` + +After step 13, the job and the dashboard stay in the workspace with the bundle settings. +The job notebook path points to the deleted bundle files. Set a new notebook path before you run the job again. + +| Step | Effect on the workspace resource | +| --- | --- | +| `bind` | No change. The bundle state records the resource ID. | +| `plan` | Shows drift. Changes made in the UI appear as `update`. | +| `deploy` | Overwrites the resource with the bundle configuration. The ID stays the same. | +| `unbind` | No change. The bundle state forgets the resource ID. | +| `destroy` | Deletes only the bundle files. Unbound resources stay. | diff --git a/knowledge_base/bind_existing_resources/databricks.yml b/knowledge_base/bind_existing_resources/databricks.yml new file mode 100644 index 00000000..b9be9225 --- /dev/null +++ b/knowledge_base/bind_existing_resources/databricks.yml @@ -0,0 +1,31 @@ +# This is a Declarative Automation Bundle definition for bind_existing_resources. +# See https://docs.databricks.com/dev-tools/bundles/migrate-resources.html for documentation. +bundle: + name: bind_existing_resources + +include: + - resources/*.yml + +variables: + warehouse_id: + description: SQL warehouse that runs the dashboard queries + lookup: + warehouse: Serverless Starter Warehouse + dashboard_parent_path: + description: Workspace folder of the existing dashboard, for example /Workspace/Users// + +# The workspace host is not set here. Use a profile (--profile / -p) or the +# DATABRICKS_HOST environment variable. + +targets: + dev: + # Development mode adds a "[dev ]" prefix to the bound job name and pauses its schedules. + mode: development + default: true + workspace: + root_path: /Workspace/bundle-examples/${bundle.name}/${bundle.target}/${workspace.current_user.short_name} + + prod: + mode: production + workspace: + root_path: /Workspace/bundle-examples/${bundle.name}/${bundle.target} diff --git a/knowledge_base/bind_existing_resources/resources/existing_dashboard.dashboard.yml b/knowledge_base/bind_existing_resources/resources/existing_dashboard.dashboard.yml new file mode 100644 index 00000000..8de10098 --- /dev/null +++ b/knowledge_base/bind_existing_resources/resources/existing_dashboard.dashboard.yml @@ -0,0 +1,9 @@ +resources: + dashboards: + existing_dashboard: + display_name: "Existing dashboard" + # Generated as a literal warehouse ID. Replaced with a variable so the bundle works in any workspace. + warehouse_id: ${var.warehouse_id} + # The parent path cannot change. Keep the folder of the existing dashboard, or deploy recreates it with a new ID. + parent_path: ${var.dashboard_parent_path} + file_path: ../src/existing_dashboard.lvdash.json diff --git a/knowledge_base/bind_existing_resources/resources/existing_job.job.yml b/knowledge_base/bind_existing_resources/resources/existing_job.job.yml new file mode 100644 index 00000000..3a5ed9aa --- /dev/null +++ b/knowledge_base/bind_existing_resources/resources/existing_job.job.yml @@ -0,0 +1,24 @@ +resources: + jobs: + existing_job: + name: Existing job + tasks: + - task_key: hello + disabled: false + email_notifications: {} + environment_key: default + notebook_task: + notebook_path: ../src/hello.py + source: WORKSPACE + run_if: ALL_SUCCESS + timeout_seconds: 0 + email_notifications: {} + environments: + - environment_key: default + spec: + environment_version: "4" + max_concurrent_runs: 1 + queue: + enabled: true + timeout_seconds: 0 + webhook_notifications: {} diff --git a/knowledge_base/bind_existing_resources/src/existing_dashboard.lvdash.json b/knowledge_base/bind_existing_resources/src/existing_dashboard.lvdash.json new file mode 100644 index 00000000..72b78dff --- /dev/null +++ b/knowledge_base/bind_existing_resources/src/existing_dashboard.lvdash.json @@ -0,0 +1,18 @@ +{ + "datasets": [ + { + "displayName": "trips", + "name": "d1", + "queryLines": [ + "SELECT * FROM samples.nyctaxi.trips LIMIT 10" + ] + } + ], + "pages": [ + { + "displayName": "Trips", + "name": "p1", + "pageType": "PAGE_TYPE_CANVAS" + } + ] +} diff --git a/knowledge_base/bind_existing_resources/src/hello.py b/knowledge_base/bind_existing_resources/src/hello.py new file mode 100644 index 00000000..1a795266 --- /dev/null +++ b/knowledge_base/bind_existing_resources/src/hello.py @@ -0,0 +1,2 @@ +# Databricks notebook source +print("Hello from an existing job!") From c73b3da4b43640fa0a1ab0d4ba0aa7de70e0cf0d Mon Sep 17 00:00:00 2001 From: Andres Garcia Date: Thu, 22 Oct 2026 00:13:20 +0000 Subject: [PATCH 2/3] knowledge_base/bind_existing_resources: apply README review fixes Move the dashboard folder export to step 1, drop the post-Usage caveat, and describe what destroy did in the live test. Co-authored-by: Isaac Co-authored-by: omnigent --- .../bind_existing_resources/README.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/knowledge_base/bind_existing_resources/README.md b/knowledge_base/bind_existing_resources/README.md index 1cd50d33..58e74c47 100644 --- a/knowledge_base/bind_existing_resources/README.md +++ b/knowledge_base/bind_existing_resources/README.md @@ -13,13 +13,13 @@ For more information, see the [bind documentation](https://docs.databricks.com/d ## Usage -1. Generate the job configuration. This replaces the sample files in `resources/` and `src/`: +1. Set the folder of the existing dashboard: `export BUNDLE_VAR_dashboard_parent_path=/Workspace/Users//` +2. Generate the job configuration. This replaces the sample files in `resources/` and `src/`: `databricks bundle generate job --existing-job-id --key existing_job --force --profile ` -2. Generate the dashboard configuration: +3. Generate the dashboard configuration: `databricks bundle generate dashboard --existing-id --key existing_dashboard --force --profile ` -3. In `resources/existing_dashboard.dashboard.yml`, replace the literal `warehouse_id` with `${var.warehouse_id}`. -4. In the same file, set `parent_path: ${var.dashboard_parent_path}`. -5. Set the folder of the existing dashboard: `export BUNDLE_VAR_dashboard_parent_path=/Workspace/Users//` +4. In `resources/existing_dashboard.dashboard.yml`, replace the literal `warehouse_id` with `${var.warehouse_id}`. +5. In the same file, set `parent_path: ${var.dashboard_parent_path}`. 6. Bind the job: `databricks bundle deployment bind existing_job -t prod --profile ` 7. Bind the dashboard: `databricks bundle deployment bind existing_dashboard -t prod --profile ` 8. Show the changes that the deploy makes: `databricks bundle plan -t prod --profile ` @@ -27,10 +27,7 @@ For more information, see the [bind documentation](https://docs.databricks.com/d 10. Run the job: `databricks bundle run existing_job -t prod --profile ` 11. Unbind the job: `databricks bundle deployment unbind existing_job -t prod --profile ` 12. Unbind the dashboard: `databricks bundle deployment unbind existing_dashboard -t prod --profile ` -13. Remove the bundle files: `databricks bundle destroy -t prod --profile ` - -After step 13, the job and the dashboard stay in the workspace with the bundle settings. -The job notebook path points to the deleted bundle files. Set a new notebook path before you run the job again. +13. Destroy the bundle deployment: `databricks bundle destroy -t prod --profile ` | Step | Effect on the workspace resource | | --- | --- | @@ -38,4 +35,4 @@ The job notebook path points to the deleted bundle files. Set a new notebook pat | `plan` | Shows drift. Changes made in the UI appear as `update`. | | `deploy` | Overwrites the resource with the bundle configuration. The ID stays the same. | | `unbind` | No change. The bundle state forgets the resource ID. | -| `destroy` | Deletes only the bundle files. Unbound resources stay. | +| `destroy` | Deletes 0 resources and the `root_path` folder. The unbound job and dashboard stay. | From 378922af32235807948bee49a3fd2c430ba57d2d Mon Sep 17 00:00:00 2001 From: Andres Garcia Date: Thu, 22 Oct 2026 02:35:25 +0000 Subject: [PATCH 3/3] Update bound job serverless environment Co-authored-by: omnigent --- .../bind_existing_resources/resources/existing_job.job.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/knowledge_base/bind_existing_resources/resources/existing_job.job.yml b/knowledge_base/bind_existing_resources/resources/existing_job.job.yml index 3a5ed9aa..7c043437 100644 --- a/knowledge_base/bind_existing_resources/resources/existing_job.job.yml +++ b/knowledge_base/bind_existing_resources/resources/existing_job.job.yml @@ -16,7 +16,7 @@ resources: environments: - environment_key: default spec: - environment_version: "4" + environment_version: "6" max_concurrent_runs: 1 queue: enabled: true