Sub topic 10
Dev, staging, and production targets
This chapter assumes you can read a basic databricks.yml, know what a Databricks Asset Bundle is, and have used the Databricks CLI. A bundle is a set of files that describes your jobs and pipelines so the CLI can deploy them. Here you will see how one bundle serves three environments through targets.
What a target is
A target is a named set of settings for one environment. You write the jobs once. Each target then overrides the parts that differ, such as the workspace URL, the deployment path, and the identity that runs the jobs.
The databricks.yml below declares one bundle with three targets.
bundle:
name: orders_pipeline
include:
- resources/*.yml
targets:
dev:
mode: development
default: true
workspace:
host: https://adb-1111111111111111.1.azuredatabricks.net
staging:
workspace:
host: https://adb-2222222222222222.2.azuredatabricks.net
root_path: /Workspace/Shared/.bundle/${bundle.name}/${bundle.target}
prod:
mode: production
workspace:
host: https://adb-3333333333333333.3.azuredatabricks.net
root_path: /Workspace/Shared/.bundle/${bundle.name}/${bundle.target}
run_as:
service_principal_name: "<service-principal-application-id>"The include list pulls job definitions from the resources/ folder. Every target deploys the same jobs. Only the settings under each target change.
What differs between targets
| Setting | dev | staging | prod |
|---|---|---|---|
| Workspace | Dev workspace | Staging workspace | Production workspace |
| Mode | `development` | not set | `production` |
| Deploy path | Per-user default | Shared path | Shared path |
| Runs as | The deploying user | The deploying identity | A service principal |
Modes
mode: development is meant for individual work. Deployed resources get a [dev your_name] prefix, so two people can deploy the same bundle without overwriting each other. Schedules and triggers on jobs are paused. Marking dev as default: true means databricks bundle deploy with no -t flag goes to dev.
mode: production adds safety checks. Validation fails if the deployment path is not set explicitly, and it expects a clear run identity. Setting run_as to a service principal means production jobs do not depend on any one person's account.
Staging has no mode here. It behaves like production without the production checks. Add mode: production to staging if you want it to enforce the same rules.
Keeping the path unique
The root_path in staging and prod includes ${bundle.target}. This is a variable the CLI fills in when it reads the file. The deployed files from different targets then never collide, even if two targets ever point at the same workspace.
Choosing a target at run time
You select a target with -t. These commands show the usual flow.
databricks bundle validate -t staging
databricks bundle deploy -t staging
databricks bundle run -t staging orders_jobvalidate checks the configuration without changing anything. deploy uploads files and creates or updates jobs. run starts a job by its resource key.
Common errors
- Deploying to the wrong target. Because
devis the default, a missing-tflag deploys to dev. In scripts, always pass-texplicitly. - Production validation fails on the path.
mode: productionrequires an explicitroot_path, so add one. - Copying job settings into each target. Put shared definitions in
resources/and override only what differs. Otherwise the targets drift apart. - Placeholder identity left in place. The
run_asvalue must be a real service principal application ID before you deploy.
Exercise
A teammate runs databricks bundle deploy with no flags and is surprised that resources appear with a [dev ...] prefix. Which setting in the example caused the target choice, and which setting caused the prefix?
Show answer
default: true on the dev target made it the target when no -t flag was given. mode: development caused the [dev your_name] prefix.