Sub topic 8
Starting from a template with bundle init
This chapter shows how to scaffold a new bundle project with databricks bundle init. It assumes you have installed the Databricks CLI and authenticated, and that you know the layout of databricks.yml and resource files from earlier chapters. You should also be comfortable with YAML and basic Git.
What a bundle template is
A bundle template is a reusable project skeleton. It contains a databricks.yml, resource files, and source folders, with placeholders that the CLI fills in from your answers. You get a working layout without writing the first files by hand.
databricks bundle init reads a template, asks you for values, and writes a new project directory. It does not deploy anything. Nothing reaches your workspace until you run databricks bundle deploy.
Running bundle init
Run the command with no arguments to choose from the built-in templates:
databricks bundle initThe CLI lists the available templates and prompts you to pick one. Common choices include a Python project (default-python), a SQL project (default-sql), and a dbt project (dbt-sql). The exact list depends on your CLI version, so check the prompt rather than relying on this chapter.
To skip the menu, pass the template name:
databricks bundle init default-pythonYou can also point at a template in a Git repository or on your local disk. This is how teams share their own standards:
databricks bundle init https://github.com/<your-org>/<your-template-repo>
databricks bundle init ./path/to/local-templateAnswering the prompts
The template asks for values such as the project name and whether to include a sample notebook or pipeline. The project name becomes the name of the new directory and the bundle.name value in databricks.yml.
For automation, you can supply the answers in a JSON file instead of typing them:
databricks bundle init default-python --config-file ./init-config.json{
"project_name": "my_project"
}The keys in the file must match the template's own prompt names. If a key is missing, the CLI prompts for it. Different templates ask for different values, so read the prompts from an interactive run first.
What you get
For a Python template, the generated project looks roughly like this:
my_project/
databricks.yml
resources/
src/
tests/
pyproject.toml
README.mddatabricks.yml holds the bundle name, an include entry for resources/*.yml, and dev and prod targets. The resources/ folder holds job or pipeline definitions. The src/ folder holds the notebooks or Python code those resources point to. Exact files vary by template and CLI version.
Because the generated layout matches the structure you have already learned, you can read it without surprises.
Reviewing before you deploy
Treat the output as a starting point. Before the first deploy, check these items:
- Open
databricks.ymland set theworkspace.hostfor each target to your own workspace URL if the template left a placeholder. - Confirm that node types and Spark versions in the resource files exist in your cloud and workspace.
- Read the job definitions and remove sample tasks you do not need.
- Commit the generated project to Git so later changes are easy to review.
Then validate and deploy to the dev target:
cd my_project
databricks bundle validate -t dev
databricks bundle deploy -t devCommon errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Template not found | Misspelled name, or an older CLI without that template | Run `databricks bundle init` with no arguments to see the list, or upgrade the CLI |
| Output directory already exists | A folder with the project name is already present | Choose another project name or remove the old folder |
| Validation fails on a node type | The template default is not available in your cloud | Set a valid value, for example through the `node_type_id` variable |
| Config file values ignored | Keys do not match the template's prompt names | Compare the keys with the prompts from an interactive run |
Exercise
You want a teammate's CI job to create new projects from your team's template without any prompts. Which command form do you use, and what must the JSON file contain?
Show answer
Run databricks bundle init <template-path-or-url> --config-file <file>.json. The JSON file must contain keys that match the template's prompt names, such as project_name, with the values you want. Any missing key causes the CLI to prompt for it.