Sub topic 9
Organizing configuration across multiple files
A bundle's databricks.yml is fine for one job. Once a project has several jobs, pipelines, and per-target overrides, the file gets long and merge conflicts become common. The include mapping lets you split configuration across files and have the CLI combine them. This chapter covers how includes are resolved, how files merge, and how to debug the result.
This chapter assumes you have a working databricks.yml with at least one job, and that you have run databricks bundle validate and databricks bundle deploy at least once. It also assumes you can read YAML lists and mappings.
What include does
include is a top-level list of glob patterns in databricks.yml. Each pattern is resolved relative to the folder that contains databricks.yml. Every matching file is read as bundle configuration and merged into the root configuration before validation or deployment.
bundle:
name: my_project
include:
- resources/*.yml
targets:
dev:
mode: development
default: true
workspace:
host: https://<your-dev-workspace-url>With this setup, any file such as resources/daily_etl.yml or resources/quality_checks.yml becomes part of the bundle. You don't list the files one by one, so adding a job means adding a file and nothing else.
The include list is read from the root databricks.yml. Keep it there, and keep the bundle name and your targets there too, so a reader can find the entry points of the project in one place.
A typical layout
A common structure puts the root file at the top, resource definitions in resources/, and code in src/:
my_project/
├── databricks.yml
├── resources/
│ ├── daily_etl.yml
│ └── quality_checks.yml
└── src/
├── ingest.py
└── check_quality.pyThis is also the layout that databricks bundle init produces for most templates, so the pattern is familiar to anyone who has used a template.
The diagram below shows how the CLI builds the final configuration.
Writing an included file
An included file looks like a slice of databricks.yml. It starts from a top-level key, usually resources, and has no wrapper of its own.
# resources/daily_etl.yml
resources:
jobs:
daily_etl:
name: daily_etl
job_clusters:
- job_cluster_key: main
new_cluster:
spark_version: 15.4.x-scala2.12
node_type_id: ${var.node_type_id}
num_workers: 2
tasks:
- task_key: ingest
job_cluster_key: main
notebook_task:
notebook_path: ../src/ingest.py
base_parameters:
catalog: ${var.catalog}A second file adds a separate job:
# resources/quality_checks.yml
resources:
jobs:
quality_checks:
name: quality_checks
job_clusters:
- job_cluster_key: small
new_cluster:
spark_version: 15.4.x-scala2.12
node_type_id: ${var.node_type_id}
num_workers: 1
tasks:
- task_key: check
job_cluster_key: small
notebook_task:
notebook_path: ../src/check_quality.py
base_parameters:
catalog: ${var.catalog}Two details matter here.
- Relative paths resolve from the file that contains them. The notebook path
../src/ingest.pyis relative toresources/, not to the project root. If you move a file to a different folder, update the relative paths in it. - Variables are shared.
${var.node_type_id}and${var.catalog}are declared once undervariablesindatabricks.yml. Every included file can reference them, so you define each variable once.
How merging works
All files contribute to a single configuration tree. The rules you need to know:
- Different keys combine.
resources.jobs.daily_etlin one file andresources.jobs.quality_checksin another both end up underresources.jobs. - The same resource key merges. If two files both define
resources.jobs.daily_etl, the CLI merges their settings into one job. It does not create two jobs. - Scalars conflict. If two files set the same scalar field, such as
name, to different values, only one value survives. Don't rely on file order to resolve this. Define each field in one place. - Some lists merge by key. Entries in
tasksmerge bytask_key, and entries injob_clustersmerge byjob_cluster_key. This is what makes target overrides practical, as shown below.
The same merge logic applies when a target overrides a resource, so understanding it once covers both cases.
Overriding a resource per target
Targets can contain a resources section. The CLI merges it over the base definition when you select that target. Use this to change a few fields for one environment without copying the whole job.
# databricks.yml (excerpt)
targets:
dev:
mode: development
default: true
workspace:
host: https://<your-dev-workspace-url>
prod:
mode: production
workspace:
host: https://<your-prod-workspace-url>
root_path: /Workspace/Shared/.bundle/${bundle.name}/${bundle.target}
run_as:
service_principal_name: <service-principal-application-id>
resources:
jobs:
daily_etl:
job_clusters:
- job_cluster_key: main
new_cluster:
num_workers: 8In prod, the main cluster of daily_etl gets num_workers: 8. The cluster is matched by job_cluster_key: main, so its spark_version and node_type_id from resources/daily_etl.yml stay as they were. Without a matching key, the entry would be added as a new cluster instead of changing the existing one.
If an override only needs to change a value like a catalog name or a node type, a variable is simpler than a resource override. Use resource overrides for structural differences, such as cluster size, a schedule, or a task that exists only in one environment.
Choosing a file structure
There is no single correct split. These options are common:
| Strategy | Layout | Works well when | Drawback |
|---|---|---|---|
| One file per resource | `resources/daily_etl.yml`, `resources/quality_checks.yml` | Each job is large or owned by a different person | Many small files for tiny projects |
| One file per domain | `resources/ingestion.yml` holding several related jobs | Jobs change together | Larger diffs, more merge conflicts |
| One file per resource type | `resources/jobs.yml`, `resources/pipelines.yml` | Few resources of each type | A single file grows without limit |
| Subfolders per domain | `resources/ingestion/*.yml`, `resources/reporting/*.yml` | Large projects with several teams | You must list each subfolder in `include` |
For most teams, one file per resource is a good default. Reviewers see changes to a single job in isolation, and code owners can be assigned per file.
Debugging the merged result
When a deployment doesn't match your expectations, look at the merged configuration instead of reading each file. Validate with JSON output:
databricks bundle validate -t prod -o jsonThe output is the full configuration after includes, variable substitution, and target overrides. Check it for:
- the resource you expected to see under
resources.jobs; - the final values of fields you overrode in the target;
- relative paths that were resolved to the wrong location.
Running databricks bundle validate -t prod without -o json prints a summary and reports syntax or schema errors. Run it before every deploy, as in the workflow from the earlier chapter on lifecycle commands.
Common errors
- A job is missing after deploy. The file didn't match an include pattern. A pattern of
resources/*.ymldoes not matchresources/daily_etl.yaml, because the extension differs. It also does not match files in subfolders such asresources/jobs/daily_etl.yml. Add a pattern for each case, or use one consistent extension. - A job was changed unexpectedly. Two files define the same resource key, and the CLI merged them. Search for the key with
grep -r "daily_etl:" resources/, and give each job a unique key. - A notebook is not found. The path in the included file is relative to that file. Compare it to the file's location, and check the merged JSON output.
- A target override adds a second cluster or task. The
job_cluster_keyortask_keyin the override doesn't match the base. Use the exact same key. - Include patterns are ignored. The
includelist is in an included file instead of the rootdatabricks.yml. Move it to the root.
Summary of the working model
includetakes a list of globs relative todatabricks.yml.- Matching files are merged into one configuration tree.
- Relative paths inside a file resolve from that file's location.
- Variables declared in the root file are available in every included file.
- Resources with the same key merge, and
tasksandjob_clustersmerge by their key fields. - A target's
resourcessection is merged over the base definition when that target is selected. databricks bundle validate -o jsonshows the final result.
Exercise
You add resources/reporting.yaml with a new job and run databricks bundle deploy -t dev. The deploy succeeds, but the job does not appear in the workspace. Your databricks.yml contains include: [resources/*.yml]. What is the cause, and how do you confirm it and fix it?
Show answer
The pattern resources/*.yml does not match a file ending in .yaml, so the CLI never read the file and skipped it without an error. Confirm it by running databricks bundle validate -t dev -o json and noticing that the job is missing from resources.jobs. Fix it by renaming the file to reporting.yml, or by adding resources/*.yaml to the include list. Then run validate again and check that the job appears before you deploy.
Exercise
The base file resources/daily_etl.yml defines a cluster with job_cluster_key: main and num_workers: 2. You want the prod target to use 8 workers without copying the whole job. Write the resources section for the prod target and explain why the key matters.
Show answer
Under targets.prod, add resources.jobs.daily_etl.job_clusters containing one entry with job_cluster_key: main and new_cluster.num_workers: 8. The CLI merges job clusters by job_cluster_key, so this changes only num_workers on the existing main cluster and keeps the other settings. If the key were different or missing, the entry would be treated as a new cluster instead of an override.