Note 50 · Databricks (3/4)

Databricks Bundles: What Changes per Target?

One bundle, three targets. What should change per environment, why modes are not a ladder, and how to split deploy and run identities for prod.

22 October 202610 min read

Key takeaways

  • Code never changes between targets. Only bindings do: catalog, host, schedules, identity and permissions.
  • Development and production modes are bundles of presets, not a ladder. A test target with no mode gets none of their safety defaults.
  • A setting on the resource beats a preset, which beats the mode. Hardcode a schedule as unpaused and it runs everywhere.
  • Bundle variables resolve at deploy time. Pass the catalog to code as a job parameter.
  • Deploy as one service principal, run as another. When they differ, only jobs and pipelines are supported.

Keep the code identical in every target, and put only a small, explicit set of bindings in each target block: catalog, host, schedules, run identity and permissions. The payoff: the commit you tested in dev is the same commit that runs in prod, and a hardcoded schedule or host cannot leak from one environment into the next.

A bundle will not make that split for you. It will happily deploy the same jobs to three environments, but its defaults are lopsided: development mode is careful, production mode checks a few things, and a test target in the middle gets nothing unless you ask.

Named model: fixed code, bound targets, split identities

  • Fixed code: notebooks, SQL and job definitions are identical in every target. No hosts, catalogs or IDs in code.
  • Bound targets: each target sets its catalog, schedules, run identity and permissions; the host comes from the pipeline.
  • Split identities: a CI identity deploys; a separate service principal runs; people get permissions, not credentials.

One commit flows into three targets. Each target binds its own catalog, schedule state, run identity and mode; the code, job definitions and SQL stay identical

Figure 1. The code column never changes. If something differs between environments, it belongs in the target block.

Context and constraint

Declarative Automation Bundles describe jobs, pipelines and other resources in YAML next to the code, and the Databricks CLI deploys them per target. They were called Databricks Asset Bundles until March 2026; the rename is non-breaking (bundle FAQs).

The bundle template I maintain is small: one catalog per environment, serverless jobs, an integration test job deployed with the bundle, and an Azure DevOps pipeline using workload identity federation. It ships two targets, dev and prod. What follows comes from deciding what goes in those target blocks, and what changes when you add a third.

It is the Databricks counterpart to post 11 (parameterize environment bindings) and post 46 (promote by commit).

Design

1. Treat modes as presets, not as a ladder

mode: development prefixes resource names with your user name, tags jobs and pipelines, pauses all schedules and triggers, allows concurrent runs, and disables the deployment lock. mode: production validates that pipelines are not in development, optionally checks that you are deploying from the expected Git branch, and expects either a service principal as run_as or explicit run_as and permissions (deployment modes).

Modes are optional, and there is no test mode. A test target without one gets no prefix, no schedule pausing and no production checks unless you add presets.

Then the precedence rule from the same page: resource settings override presets, and presets override the mode. Learn's own example is the one that bites: a schedule set to UNPAUSED on the job stays unpaused even when the target's trigger_pause_status preset says PAUSED. Write pause_status: UNPAUSED into the job YAML because prod needs it, and every target that deploys the job runs it on schedule. That includes development mode: an explicit pause_status: UNPAUSED stays unpaused in dev too, so set the dev value yourself (deployment modes).

Databricks Jobs list filtered to demo_daily_job: a dev copy named [dev sai] demo_daily_job with a tag, next to the prod demo_daily_job, and both triggers still Scheduled

Figure 2. One bundle deployed to dev and prod gives two jobs. Development mode added the [dev sai] prefix and a tag, but the job sets pause_status: UNPAUSED, so the dev copy stayed Scheduled. At the time of this shot prod had no run_as and ran as the deploying user, which is not what I recommend for a real prod target. Figure 4 shows the same prod job after I added a service principal.

So I make the schedule state a variable, paused by default, and unpause it only in the prod target:

variables:
  catalog:
    description: One Unity Catalog catalog per environment.
  schedule_pause_status:
    default: PAUSED
  test_sp_app_id:
    description: Application ID of the test run principal.
  prod_sp_app_id:
    description: Application ID of the prod run principal.

targets:
  dev:
    mode: development
    default: true
    variables:
      catalog: project_dev
  test:
    variables:
      catalog: project_test
    run_as:
      service_principal_name: ${var.test_sp_app_id}
  prod:
    mode: production
    git:
      branch: main
    variables:
      catalog: project_prod
      schedule_pause_status: UNPAUSED
    run_as:
      service_principal_name: ${var.prod_sp_app_id}

The job reads pause_status: ${var.schedule_pause_status}. Forget to set it and the job stays paused, which is the failure you want.

Three layers of precedence: resource settings beat presets, which beat mode defaults. Example: a job schedule hardcoded as unpaused overrides a paused preset and runs in every target; a schedule bound to a variable stays paused until the prod target sets it

Figure 3. Safety defaults live at the weakest layer. Anything you write on the resource wins.

2. Bind the catalog at deploy time, read it at run time

One catalog per environment is the simplest Unity Catalog layout I know that keeps environments apart by construction. The catch is how the catalog reaches code. Bundle variables are deployment-time values: running a job uses the values from its last deployment, and passing a different variable at run time does not apply. Learn says to use job parameters for run values instead (substitutions and variables).

So the job declares a catalog parameter whose default is ${var.catalog}. SQL uses a ${catalog} placeholder, Python reads the parameter, and no file under the source folder names a catalog. A small lint in CI fails the build if it finds a workspace host, a token, a catalog name or a cluster ID in code.

One more edge: variable precedence runs from --var, to BUNDLE_VAR_ environment variables, to the per-target override file, to target values, to the default. A stray environment variable on a build agent quietly beats your YAML.

3. Split the deploy identity from the run identity

CI deploys as a service principal through workload identity federation, so there is no secret to rotate. On Azure DevOps that is a federated service connection with the Azure CLI task and DATABRICKS_AUTH_TYPE=azure-cli (authenticate with Azure DevOps); on GitHub Actions it is github-oidc with id-token: write (GitHub Actions). The workspace host stays out of the repo and comes from pipeline variables.

Workloads then run as a different service principal per environment through run_as. Learn calls this the most secure way to run production: the run identity can have fewer permissions than the deployer, and only that principal or someone allowed to use it can deploy with it (run identity).

In my demo the prod job shows the service principal under Run as, while I stay the creator (Figure 4). Two steps sat outside the YAML: I needed the Service Principal User role on it before the deploy would set it as run_as, and the first run failed with UnauthorizedError until the service principal had access to the workspace. The rerun succeeded.

Databricks job details for the bundle-managed prod job: Run as shows a service principal, the creator is the deploying user, the schedule is paused, and the run history shows one failed run with UnauthorizedError followed by a successful run, with the job and run IDs blurred

Figure 4. The prod job runs as agent-sp, not as me. The first run failed before the service principal had workspace access; the rerun succeeded. The schedule is paused only because the demo ships it paused.

The sharp edges are on that page too. When the deploying identity differs from run_as, only jobs and pipelines are supported. Top-level and target run_as take a user or a service principal, not a group, and non-admins can only set it to themselves. Model serving endpoints error if run_as is set in the same bundle. If the bundle will grow beyond jobs and pipelines, decide early where those resources live.

4. Permissions on jobs are not grants on data

Top-level permissions give users, groups and service principals CAN_VIEW, CAN_RUN or CAN_MANAGE on everything the bundle deploys, and Databricks recommends that approach. The same principal cannot appear in both the top-level mapping and a resource's own permissions (bundle permissions).

One naming catch: the bundle takes CAN_RUN, and on a job the UI shows it as Can Manage Run (Figure 5).

Job permissions panel: the deploying user is owner, admins can manage, analysts can view, and demo_runners can manage run

Figure 5. Permissions on the deployed prod job. The demo_runners group was given CAN_RUN in the bundle and shows as Can Manage Run.

Those control who can see, run or edit the job. They do not decide what the job can read and write. That is Unity Catalog grants for the run identity on its own catalog, so the test principal cannot touch the prod catalog even if someone points a job at it.

In my demo the run service principal holds USE CATALOG, USE SCHEMA, SELECT and MODIFY on its own catalog (Figure 6).

Unity Catalog permissions on the demo catalog: agent-sp holds MODIFY, SELECT, USE CATALOG and USE SCHEMA, and two groups hold USE CATALOG, with the workspace suffix of one group name blurred

Figure 6. Data access is a Unity Catalog grant to the run identity, separate from who may view or run the job.

Identity map: a CI service principal deploys through workload identity federation; a run service principal per environment executes jobs and holds Unity Catalog grants on only its own catalog; people get view or run permissions through groups on the deployed jobs

Figure 7. Three different questions: who deploys, who runs, and who may look. Only the run identity needs data access.

5. Promote the commit, and test where it will run

Every target deploys the same commit. My template's pipeline runs unit tests on the agent without Spark, deploys to dev, runs the bundle's integration test job on serverless with databricks bundle run, and only then deploys prod behind an environment approval. The git.branch check in production mode is a second lock: a prod deploy from any other branch fails unless someone passes --force.

Same idea as post 46: what reaches prod is a commit you can name, not whatever the branch tip happens to be.

6. Add a test target only when it buys something

Two targets is a real option. A third costs a catalog, a run principal, grants, a pipeline stage and test data. It pays when other teams consume the output before prod, when you need prod-shaped data that dev must not hold, or when a release needs sign-off on a stable shared environment. If integration tests run fine against dev, a test target mostly adds a place for drift.

When I add one, it copies prod's shape, not dev's: no development mode, a service principal as run_as, paused schedules, its own catalog.

Common mistakes

Hardcoding UNPAUSED on the job. Resource settings beat presets, so test runs on prod's schedule.

A test target with no mode and no presets. It gets none of the development defaults and none of the production checks.

Passing the catalog as a bundle variable at run time. Variables resolve at deploy; use a job parameter.

Catalog names in notebooks. One copied notebook writes to the wrong environment.

One service principal for deploy and run. It works, but the run identity now needs deploy rights.

Job permissions as data access. They govern the job, not the tables.

Use as-is or adapt

Use as-is

  • Identical code in every target; environment only in target blocks.
  • Schedules paused by variable, unpaused only in prod.
  • The catalog as a job parameter defaulting to a bundle variable.
  • Workload identity federation for CI, and a service principal run_as for test and prod.

Adapt before you use

  • Whether you need a test target at all, using the costs in section 6.
  • One workspace with a catalog per environment, or a workspace per environment as well, depending on your isolation and network requirements.
  • Whether jobs and pipelines share a bundle with resources that cannot use a separate run_as.
  • Read-only deployment folders: the immutable folder setting is in Private Preview and requires the direct deployment engine (configuration reference).

Try it yourself

The dev and prod bundle demo in my public tech-demos repo deploys one job to two targets, so you can see what development mode does to the job name and schedule.

Related

The bundle will deploy anything to anywhere. Decide what differs per target, write it down once, and let the code stay the same.