What you will be able to do
- Lay out a bundle repository with databricks.yml, resources/, src/ and tests/ so that jobs, pipelines and tests share one code base
- Split resource definitions into separate YAML files and wire them into one deployment with the include mapping
- Load resources defined in Python alongside YAML through the python section of databricks.yml
- Configure dev and prod targets with deployment modes and a service-principal run_as identity for unattended CI/CD deployment
Key concept
databricks.yml as the single bundle root — Every bundle has exactly one databricks.yml at the top of the project folder. Every other configuration file, whether resource YAML or Python resource loaders, only becomes part of the deployment because databricks.yml points to it.
1.What a bundle project contains
A Declarative Automation Bundle (formerly Databricks Asset Bundle) is an infrastructure-as-code project. It holds your business logic and the definitions of the Databricks resources that run it, and both live in source control. The whole folder is deployed as one unit to a target environment. Because of that, the project's structure decides what reaches a workspace together, and what a CI/CD pipeline can validate in a single step.
A bundle bundles four kinds of content:
- cloud infrastructure and workspace configuration
- source files such as notebooks and Python files holding the business logic
- definitions and settings for resources such as Lakeflow Jobs, Lakeflow pipelines, dashboards and MLflow experiments
- unit tests and integration tests
The default-python template from databricks bundle init shows the conventional layout. Configuration and code sit in separate folders. databricks.yml at the root names the bundle, references the other configuration files, holds the wheel build settings and catalog/schema variables, and defines the targets. Each resource gets its own file under resources/, such as resources/sample_job.job.yml. The importable Python package lives under src/, and a pyproject.toml describes how to build it. Tests sit in tests/. A job task, a pipeline and a pytest suite can all import the same package from src/, so a transformation is written once and exercised everywhere. Writing those tests is covered in unit and integration testing.
| Path | Role in the project |
|---|---|
| databricks.yml | Bundle name, references to other files, whl build settings, catalog and schema variables, target settings |
| resources/sample_job.job.yml | Settings for one job resource |
| src/ | Files the Python wheel job uses to build the Python wheel file |
| tests/ | Sample unit tests |
| README.md | Getting-started notes for the bundle |
Teams that start many projects can make this layout a standard. A custom bundle template can bake in default permissions, service principals and CI/CD configuration, so each new repository begins with the same structure instead of a hand-copied one.
Checkpoint 1 of 7· Match them up
In a project generated by the default-python template, match each path to its role in the bundle.
Tap a term, then the definition that fits it.
The template keeps configuration apart from code. databricks.yml is the single root that names the bundle, references the other files and defines the targets. Each resource has its own YAML file under resources/. The package that is built into the wheel lives in src/, and tests/ holds the tests that import it.
“databricks.yml: This file specifies the bundle's name, includes references to the bundle's files, specifies whl build settings, defines catalog and schema variables”Source: docs.databricks.com
2.Splitting resource definitions with include
The include mapping is how separate configuration files join the deployment. databricks.yml is the main file, but it can list other files or path globs under include. The CLI reads every file that matches and combines them into one bundle configuration. A project with a pipeline and two jobs can therefore keep each definition in its own file under resources/ and add one glob such as resources/*.yml. All three stay active in every deploy.
# databricks.yml
bundle:
name: hello-bundle
include:
- '*.yml'An included file can carry any top-level mapping, not only resources. In the same example, hello-job.yml holds the job and a separate targets.yml holds the dev and prod targets. That split is useful when several people edit different jobs: each change touches one small file, and a reviewer sees just that resource in the diff.
Checkpoint 2 of 7· Check yourself
A team moves its pipeline and two job definitions out of databricks.yml into separate files under resources/. After the next deploy, none of the three resources is created or updated. What change to databricks.yml fixes this?
Configuration files outside databricks.yml become part of the bundle only when the include mapping lists them, by name or by glob. sync only controls which files are uploaded. artifacts builds code such as wheels. workspace sets paths in the remote workspace. None of those three loads resource definitions.
“it can reference other configuration files, such as resource configuration files, in the include mapping.”Source: docs.databricks.com
Checkpoint 3 of 7· Exam question
A team maintains a Declarative Automation Bundle for a Lakeflow pipeline and two Lakeflow Jobs. As the project grows, they want to define each job and pipeline in its own YAML file under a resources/ folder while keeping every definition active in one bundle deployment. Which approach correctly wires these separate resource files into databricks.yml?
Correct answer: A — Add an include: mapping listing glob patterns such as resources/*.yml, so the CLI merges every matched file into the deployment.
- A. The top-level
include:key accepts glob patterns and is exactly the mechanism bundles use to pull in additional configuration files, so definitions split acrossresources/*.ymlare merged into the same deployment asdatabricks.yml. - B. There is no
resources_pathsetting undertargets; target blocks configure things like mode, workspace root, and variable overrides, not folder auto-discovery of resource files. - C. The
artifactsblock builds code artifacts such as Python wheels for job libraries; it has no role in loading or compiling resource YAML files. - D.
workspace.file_pathsets where bundle-synced files land in the workspace; it does not create additional bundle roots or load extra resource definitions.
Sources3
3.Defining resources in Python
Resources can also be written as Python code, and they can sit alongside YAML resources in the same bundle. This needs Databricks CLI 0.275.0 or above. The pydabs template sets it up, and in an existing bundle you add a python section to databricks.yml. That section names a virtual environment, which must have the databricks-bundles package installed, and one or more loader functions.
python:
# Activate the virtual environment before loading resources defined in
# Python. If disabled, it defaults to using the Python interpreter
# available in the current shell.
venv_path: .venv
# Functions called to load resources defined in Python.
# See resources/__init__.py
resources:
- 'resources:load_resources'The resources folder has to be a package, so it needs an __init__.py. By default that file defines load_resources, which calls load_resources_from_current_package_module() to pick up every Python file in the package. The CLI calls this function at deploy time only and never at run time. That makes it a good place to generate resources from metadata: the documented example loops over ["US", "NL"] and calls resources.add_resource once per country, so adding a market means editing a list rather than copying a job definition. Jobs are built with Job.from_dict, which takes the same dictionary shape as YAML, or with dataclasses such as Job, Task and NotebookTask.
Choose Python definitions when resources follow a pattern you would otherwise copy and paste. Keep YAML for one-off resources, where a flat file is easier to review.
Checkpoint 4 of 7· Fill the gap
An existing YAML bundle is getting resources defined in Python. Which top-level key in databricks.yml makes the CLI load them?
? :
# Activate the virtual environment before loading resources defined in
# Python. If disabled, it defaults to using the Python interpreter
# available in the current shell.
venv_path: .venv
# Functions called to load resources defined in Python.
# See resources/__init__.py
resources:
- 'resources:load_resources'Python-defined resources join the bundle through the python section in databricks.yml. That section names the virtual environment and the loader functions, such as resources:load_resources, which the CLI calls at deploy time. include merges YAML configuration files, artifacts builds code such as wheels, and sync only controls which files are uploaded. None of these three calls a Python loader.
Source: docs.databricks.comSources4
4.Targets, deployment modes and run identity
The targets mapping lets one bundle deploy to several environments. Anything defined at the top level applies to every target. A target overrides only the fields it lists, and everything else falls back to the top-level definition. In the example below, prod changes the workspace host and the cluster ID but keeps the job's notebook_task from the top-level resource.
targets:
dev:
default: true
prod:
workspace:
host: https://<production-workspace-url>
resources:
jobs:
hello-job:
name: hello-job
tasks:
- task_key: hello-task
existing_cluster_id: 2345-678901-fabcd456Only one target can be marked default: true, and it is the target used when a command names none. Putting it on dev is the safe choice: a developer who forgets the flag deploys to their own sandbox. Reaching production then always takes a deliberate -t prod. For the workspace itself, set the host mapping on each target. The CLI then finds the matching profile in .databrickscfg, which keeps the configuration portable.
Deployment modes are optional. Each one applies a group of commonly used settings to a target, and you choose it with mode: development or mode: production. Development mode suits each engineer's own copy. Production mode adds the checks that an unattended CI/CD deployment should not skip.
| Behaviour | mode: development | mode: production |
|---|---|---|
| Resource names | Prefixed with [dev ${workspace.current_user.short_name}] and tagged dev | Not prefixed (a name_prefix preset can be added) |
| Lakeflow pipelines | Marked development: true | Validated to be development: false |
| Concurrency and locking | Concurrent job runs enabled; deployment lock disabled | Validates the current Git branch matches the target's git branch (override with --force) |
| Identity | Runs as the deploying user | Service principals recommended; enforce by setting run_as to one |
The [dev username] prefix is what keeps developers from colliding in a shared workspace. Putting development mode on a prod target would therefore stamp one person's name on production jobs and mark production pipelines as development pipelines.
run_as sets the identity that deployed jobs execute under, and you can set it per target. For production the right value is a service principal, given by its application ID in service_principal_name. With that in place, scheduled jobs no longer run as whichever developer or pipeline happened to deploy last. The permission to run the production workflow is separate from the identity that deployed the bundle. If a production-mode deploy fails because no run_as identity is set, the direct fix is a run_as block with service_principal_name under the prod target. A permissions block will not fix it. Permissions say who can access or manage the resources, while run_as says who the workloads run as. Deleting the mode key would also make the error go away, but only by removing the production checks. The deploy and run commands themselves are covered in deploying bundles.
# This is the identity to use to run the bundle
run_as:
- user_name: <user-name>
- service_principal_name: <service-principal-name>Checkpoint 5 of 7· Check yourself
Scheduled production jobs from a bundle keep running as whichever engineer or pipeline deployed them last. The team wants them to execute as the service principal sp-prod-etl instead. Which change to the prod target does this?
run_as sets the identity that deployed workloads execute under, and you can set it per target. permissions only controls who can access or manage the resources. mode: production recommends a service principal, but run_as is the setting that enforces one.
“This is the identity to use to run the bundle”Source: docs.databricks.com
Checkpoint 6 of 7· Exam question
An engineer is configuring dev and prod targets in a single databricks.yml so the same bundle can be validated by individual developers and deployed unattended by a CI/CD pipeline into a shared production workspace. Which two configuration choices are appropriate for the prod target specifically? (Choose 2.)(Select 2)
Correct answers: A, B — Set mode: production on the prod target so the CLI enforces stricter checks, such as requiring a fixed run_as identity for every deployment to that target.; Set run_as on the prod target to a service principal so scheduled jobs execute under a shared identity instead of whichever developer last deployed the bundle.
- A. Production mode is the setting meant for shared, unattended deployments; it enforces safeguards such as requiring a fixed
run_asidentity and disabling development-only conveniences that are unsafe outside a personal workspace. - B. Pinning
run_asto a service principal for the production target ensures jobs run under a stable, auditable identity rather than inheriting the credentials of whichever engineer happened to trigger the deploy. - C. Development mode is what appends a username prefix and applies other per-developer conveniences; applying it to the production target would defeat the purpose of a stable, shared deployment.
- D. Leaving
prodpointed at the same workspace path used for local testing would let developer deployments overwrite production resources, which is the opposite of the isolation a separate target is meant to provide. - E. Marking the
devtarget as the default only changes which target is picked when none is named on the command line; it does not configure any safeguard on theprodtarget itself and risks accidental production deploys.
Checkpoint 7 of 7· Exam question
A CI/CD pipeline runs databricks bundle deploy --target prod against the prod target, which has mode: production set. The deploy fails with an error stating that a run_as identity must be specified for the target. What is the most direct fix that keeps the production deployment unattended and reproducible?
Correct answer: A — Add a run_as block under the prod target that sets service_principal_name to the pipeline's own principal, so jobs run under that fixed identity.
- A. Production mode requires an explicit
run_asidentity precisely so unattended deploys have a fixed, known owner; setting it to the pipeline's service principal satisfies that check and keeps ownership consistent across runs. - B. Switching to development mode would silence the error but also removes the production safeguards the team relies on, such as identity pinning and protection against concurrent-run cancellation, which is not an acceptable trade-off here.
- C. Omitting
modedoes not disable the identity check for a target already treated as production-like; the requirement comes from the mode being set toproduction, and removing it changes other safeguards without resolving the underlying need for a stable identity. - D. A
permissionsblock controls who can view or manage the deployed resources after deployment; it does not satisfy therun_asrequirement, which specifically governs the identity jobs execute under.
Sources
(6)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://docs.databricks.com/aws/en/dev-tools/bundlesOfficial docs
“Your bundle project's collection of source files and metadata is deployed as a single bundle to your target environment.”
↩︎ What a bundle project contains“A custom template might include default permissions, service principals, and custom CI/CD configuration.”
↩︎ What a bundle project contains - 2.
“This file specifies the bundle's name, includes references to the bundle's files, specifies whl build settings, defines catalog and schema variables”
↩︎ What a bundle project contains“databricks.yml: This file specifies the bundle's name, includes references to the bundle's files, specifies whl build settings, defines catalog and schema variables”
↩︎ Checkpoint - 3.
“For more modularization and better reuse of definitions and settings across bundles, split your bundle configuration into separate files:”
↩︎ Splitting resource definitions with include“it falls back to use the notebook_task mapping within the top-level resources mapping”
↩︎ Targets, deployment modes and run identity“Databricks recommends that you use the host mapping instead of the default mapping wherever possible, as this makes your bundle configuration files more portable.”
↩︎ Targets, deployment modes and run identity“A bundle must contain one (and only one) configuration file named databricks.yml at the root of the bundle project folder.”
↩︎ Key concept“but it can reference other configuration files, such as resource configuration files, in the include mapping”
↩︎ Exam trap 1“it can reference other configuration files, such as resource configuration files, in the include mapping.”
↩︎ Checkpoint“You must specify "-t prod", because the "dev" target”
↩︎ Prediction“This is the identity to use to run the bundle”
↩︎ Checkpoint - 4.
“Define resources in Python code. These definitions can coexist with resources defined in YAML.”
↩︎ Defining resources in Python“The specified virtual environment must contain the installed databricks-bundles PyPi package.”
↩︎ Defining resources in Python“You can use Python to create resources programmatically. For example, you can load configuration files and create jobs in a loop:”
↩︎ Defining resources in Python - 5.
“Deployment modes are optional. You can deploy bundles without setting a mode or configuring presets.”
↩︎ Targets, deployment modes and run identity“Databricks recommends that you use service principals for production deployments. You can enforce this by setting run_as to a service principal.”
↩︎ Targets, deployment modes and run identity“Prepends all resources that are not deployed as files or notebooks with the prefix [dev ${workspace.current_user.short_name}]”
↩︎ Exam trap 2 - 6.
“setting a run_as identity to a service principal for production targets is the most secure way of running a production workflow”
↩︎ Targets, deployment modes and run identity“Decouples the permission to run the production workflow from the identity that created or deployed the bundle.”
↩︎ Exam trap 3