Sub topic 3
Anatomy of databricks.yml
This chapter walks through the top-level structure of the bundle configuration file. It assumes you can read YAML, know what a Databricks job is, and have the CLI installed and authenticated from the previous chapter.
The role of databricks.yml
Every bundle has one root configuration file named databricks.yml at the project root. The CLI reads this file first. It tells the CLI what the bundle is called, which other files belong to it, and which environments (targets) you can deploy to.
The file is declarative. You describe the state you want, and databricks bundle deploy makes the workspace match it. Keeping this file in Git means every deployment can be traced to a commit.
The top-level keys
Here is a complete root file. It is the example we will use in the rest of the walkthrough.
bundle:
name: my_project
variables:
catalog:
description: Unity Catalog catalog the job writes to
default: dev_catalog
node_type_id:
description: Cloud-specific node type for job clusters
include:
- resources/*.yml
targets:
dev:
mode: development
default: true
workspace:
host: https://<your-dev-workspace-url>
variables:
node_type_id: <a-node-type-available-in-your-cloud>
prod:
mode: production
workspace:
host: https://<your-prod-workspace-url>
root_path: /Workspace/Shared/.bundle/${bundle.name}/${bundle.target}
variables:
catalog: prod_catalog
node_type_id: <a-node-type-available-in-your-cloud>
run_as:
service_principal_name: <service-principal-application-id>Replace each placeholder in angle brackets with a value from your own workspace and cloud before you validate.
The table below summarizes each top-level key in this file.
| Key | Purpose |
|---|---|
| `bundle` | Identifies the bundle. `name` is required. |
| `variables` | Declares named values that you can reference elsewhere. |
| `include` | Lists other YAML files to merge into the configuration. |
| `targets` | Defines the environments you deploy to and what each one overrides. |
Two keys you do not see here are resources and artifacts. You can declare resources directly in this file, but this project puts them in separate files that include pulls in. Later chapters cover both.
bundle
The bundle block holds metadata. The name becomes part of the deployment path and of the resource names in dev mode, so choose something stable. Renaming a bundle later makes the CLI treat it as a new deployment, and your old one stays behind.
variables
Each entry under variables declares a value that you reference as ${var.<name>}. A variable can carry a description and a default. In the example, catalog has a default and node_type_id does not. A variable with no default must receive a value from somewhere else, such as a target override or a --var flag. If none supplies one, validation fails.
include
The include list uses paths relative to databricks.yml. Globs are allowed, so resources/*.yml picks up every YAML file in the resources folder. The CLI merges the matched files into the root configuration. A typical layout looks like this:
my_project/
├── databricks.yml
├── resources/
│ └── daily_etl.yml
└── src/
└── ingest.pytargets
Each key under targets names an environment. The settings inside it override or add to the top-level configuration for that environment only.
mode: developmentprefixes deployed resource names with your user name and pauses schedules, so developers do not collide with each other.mode: productionapplies stricter checks. For example, it expects an explicitroot_pathor equivalent, and it expects you to setrun_aswhen deploying.default: truemakesdevthe target the CLI uses when you omit-t.workspace.hostpoints the target at a specific workspace.run_assets the identity that runs jobs, here a service principal.
How the pieces combine
The CLI builds one final configuration by layering. It starts with the root file, merges the included files, then applies the chosen target's overrides. Variables are resolved last. The diagram shows the order.
You can inspect the result for any target with databricks bundle validate -t prod. Add --output json to print the fully resolved configuration.
Common errors
- Missing variable value. A variable without a default and without a target override causes a validation error. Add a default or set it under the target.
- Wrong indentation. A key such as
variablesnested underbundleis read as a different setting. Keep top-level keys at column zero. - Include path not found. Paths are relative to
databricks.yml, not to your current directory. - Unfilled placeholders. Values such as
<your-dev-workspace-url>are templates. The CLI will try to use them literally and fail.
Exercise
A teammate adds a variable warehouse_id to databricks.yml with no default and no override in the dev target. What happens when they run databricks bundle validate -t dev, and what are two ways to fix it?
Show answer
Validation fails because the variable has no value. Fix it by adding a default to the variable declaration, or by setting warehouse_id under targets.dev.variables. Passing --var="warehouse_id=<value>" on the command line also works for a single invocation.
Exercise
In the example file, which key decides which target runs when you type databricks bundle deploy with no -t flag?
Show answer
default: true under the dev target.