Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/bundles/builtin-templates-workspace-url.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Built-in templates add the workspace ID to `workspace.host` (`?w=<id>`) when the profile or an environment variable sets it, so generated bundles select the right workspace on hosts shared by several workspaces. Welcome messages show the same URL, and `dbt-sql` also adds `?o=<id>` to the HTTP path it suggests for `dbt init`. ([#7350](https://github.com/databricks/cli/pull/7350))
6 changes: 6 additions & 0 deletions acceptance/bundle/templates/dbt-sql-workspace-id/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"project_name": "my_dbt_sql",
"http_path": "/sql/2.0/warehouses/f00dcafe",
"default_catalog": "main",
"personal_schemas": "yes"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DMS = [""]
48 changes: 48 additions & 0 deletions acceptance/bundle/templates/dbt-sql-workspace-id/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

=== Profile no_workspace_id

>>> [CLI] bundle init dbt-sql --config-file ./input.json --profile no_workspace_id

Welcome to the dbt template for Declarative Automation Bundles!

A workspace was selected based on your current profile. For information about how to change this, see https://docs.databricks.com/dev-tools/cli/profiles.html.
workspace_host: [DATABRICKS_URL]

📊 Your new project has been created in the 'my_dbt_sql' directory!
If you already have dbt installed, just type 'cd my_dbt_sql; dbt init' to get started.
Refer to the README.md file for full "getting started" guide and production setup instructions.


>>> grep host: my_dbt_sql/databricks.yml
host: [DATABRICKS_URL]
host: [DATABRICKS_URL]

>>> grep -E ^ default: [^{] my_dbt_sql/profile_template.yml
default: [DATABRICKS_HOST]
default: /sql/2.0/warehouses/f00dcafe
default: main
default: 4

=== Profile custom_host

>>> [CLI] bundle init dbt-sql --config-file ./input.json --profile custom_host

Welcome to the dbt template for Declarative Automation Bundles!

A workspace was selected based on your current profile. For information about how to change this, see https://docs.databricks.com/dev-tools/cli/profiles.html.
workspace_host: [CUSTOM_HOST]?w=[WORKSPACE_ID]

📊 Your new project has been created in the 'my_dbt_sql' directory!
If you already have dbt installed, just type 'cd my_dbt_sql; dbt init' to get started.
Refer to the README.md file for full "getting started" guide and production setup instructions.


>>> grep host: my_dbt_sql/databricks.yml
host: [CUSTOM_HOST]?w=[WORKSPACE_ID]
host: [CUSTOM_HOST]?w=[WORKSPACE_ID]

>>> grep -E ^ default: [^{] my_dbt_sql/profile_template.yml
default: [CUSTOM_HOSTNAME]
default: /sql/2.0/warehouses/f00dcafe?o=[WORKSPACE_ID]
default: main
default: 4
25 changes: 25 additions & 0 deletions acceptance/bundle/templates/dbt-sql-workspace-id/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
setup_custom_host

cat > .databrickscfg <<EOT
[no_workspace_id]
host = $DATABRICKS_HOST
token = $DATABRICKS_TOKEN

[custom_host]
host = $CUSTOM_HOST
workspace_id = $WORKSPACE_ID
token = $DATABRICKS_TOKEN
EOT
export DATABRICKS_CONFIG_FILE=$PWD/.databrickscfg
unset DATABRICKS_HOST
unset DATABRICKS_TOKEN

# dbt reads the workspace ID from ?o= in the HTTP path. The template adds it
# when the profile sets the ID, like ?w= in the bundle host.
for profile in no_workspace_id custom_host; do
title "Profile $profile\n"
trace $CLI bundle init dbt-sql --config-file ./input.json --profile $profile
trace grep 'host:' my_dbt_sql/databricks.yml
trace grep -E "^ default: [^{]" my_dbt_sql/profile_template.yml
rm -r my_dbt_sql
done
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ignore = [".databrickscfg"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"project_name": "my_default_minimal",
"language_choice": "python"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DMS = [""]
68 changes: 68 additions & 0 deletions acceptance/bundle/templates/default-minimal/profiles/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

=== Profile classic

>>> [CLI] bundle init default-minimal --config-file ./input.json --profile classic
Welcome to the minimal Declarative Automation Bundle template!

This template creates a minimal project structure without sample code, ideal for advanced users.
(For getting started with Python or SQL code, use the default-python or default-sql templates instead.)

Your workspace at [DATABRICKS_URL] is used for initialization.
(See https://docs.databricks.com/dev-tools/cli/profiles.html for how to change your profile.)

✨ Your new project has been created in the 'my_default_minimal' directory!

To get started, refer to the project README.md file and the documentation at https://docs.databricks.com/dev-tools/bundles/index.html.

>>> grep host: databricks.yml
host: [DATABRICKS_URL]
host: [DATABRICKS_URL]

>>> DATABRICKS_BUNDLE_STRICT_PROFILE_MATCH=1 [CLI] bundle validate -t dev
Name: my_default_minimal
Target: dev
Workspace:
Host: [DATABRICKS_URL]
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/my_default_minimal/dev

Validation OK!

>>> [CLI] bundle deploy -t dev
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/my_default_minimal/dev/files...
Files: 10 uploaded, 0 deleted
Resources: 0 created, 0 changed, 0 deleted, 0 unchanged

=== Profile custom_host

>>> [CLI] bundle init default-minimal --config-file ./input.json --profile custom_host
Welcome to the minimal Declarative Automation Bundle template!

This template creates a minimal project structure without sample code, ideal for advanced users.
(For getting started with Python or SQL code, use the default-python or default-sql templates instead.)

Your workspace at [CUSTOM_HOST]?w=[WORKSPACE_ID] is used for initialization.
(See https://docs.databricks.com/dev-tools/cli/profiles.html for how to change your profile.)

✨ Your new project has been created in the 'my_default_minimal' directory!

To get started, refer to the project README.md file and the documentation at https://docs.databricks.com/dev-tools/bundles/index.html.

>>> grep host: databricks.yml
host: [CUSTOM_HOST]?w=[WORKSPACE_ID]
host: [CUSTOM_HOST]?w=[WORKSPACE_ID]

>>> DATABRICKS_BUNDLE_STRICT_PROFILE_MATCH=1 [CLI] bundle validate -t dev
Name: my_default_minimal
Target: dev
Workspace:
Host: [CUSTOM_HOST]?w=[WORKSPACE_ID]
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/my_default_minimal/dev

Validation OK!

>>> [CLI] bundle deploy -t dev
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/my_default_minimal/dev/files...
Files: 10 uploaded, 0 deleted
Resources: 0 created, 0 changed, 0 deleted, 0 unchanged
29 changes: 29 additions & 0 deletions acceptance/bundle/templates/default-minimal/profiles/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
setup_custom_host

# The classic profile has no workspace_id. The SDK resolves the ID from host
# metadata, but the generated host stays without ?w= so that it matches the
# profile in strict mode too.
cat > .databrickscfg <<EOT
[classic]
host = $DATABRICKS_HOST
token = $DATABRICKS_TOKEN

[custom_host]
host = $CUSTOM_HOST
workspace_id = $WORKSPACE_ID
token = $DATABRICKS_TOKEN
EOT
export DATABRICKS_CONFIG_FILE=$PWD/.databrickscfg
unset DATABRICKS_HOST
unset DATABRICKS_TOKEN

for profile in classic custom_host; do
title "Profile $profile\n"
trace $CLI bundle init default-minimal --config-file ./input.json --profile $profile
cd my_default_minimal
trace grep 'host:' databricks.yml
trace DATABRICKS_BUNDLE_STRICT_PROFILE_MATCH=1 $CLI bundle validate -t dev
trace $CLI bundle deploy -t dev
cd ..
rm -r my_default_minimal
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# The script writes .databrickscfg.
Ignore = [".databrickscfg"]
5 changes: 5 additions & 0 deletions libs/template/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/databricks/cli/libs/cmdctx"
"github.com/databricks/cli/libs/dbr"
"github.com/databricks/cli/libs/filer"
"github.com/databricks/cli/libs/jsonschema"
"github.com/databricks/cli/libs/logdiag"
"github.com/databricks/cli/libs/tags"
"github.com/databricks/databricks-sdk-go"
Expand Down Expand Up @@ -49,6 +50,10 @@ func assertBuiltinTemplateValid(t *testing.T, template string, settings map[stri

renderer, err := newRenderer(ctx, settings, helpers, templateFS, templateDirName, libraryDirName)
require.NoError(t, err)
schema, err := jsonschema.LoadFS(templateFS, schemaFileName)
require.NoError(t, err)
renderer.workspace, err = loadWorkspaceContext(ctx, schema)
require.NoError(t, err)

// Evaluate template
err = renderer.walk()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"welcome_message": "\nWelcome to the dbt template for Declarative Automation Bundles!\n\nA workspace was selected based on your current profile. For information about how to change this, see https://docs.databricks.com/dev-tools/cli/profiles.html.\nworkspace_host: {{workspace_host}}",
"welcome_message": "\nWelcome to the dbt template for Declarative Automation Bundles!\n\nA workspace was selected based on your current profile. For information about how to change this, see https://docs.databricks.com/dev-tools/cli/profiles.html.\nworkspace_host: {{.workspace.URL}}",
"properties": {
"project_name": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ targets:
mode: development
default: true
workspace:
host: {{workspace_host}}
host: {{.workspace.URL}}

prod:
mode: production
workspace:
host: {{workspace_host}}
host: {{.workspace.URL}}
# We explicitly deploy to /Workspace/Users/{{user_name}} to make sure we only have a single copy.
root_path: /Workspace/Users/{{user_name}}/.bundle/${bundle.name}/${bundle.target}
permissions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ fixed:
type: databricks
prompts:
host:
default: {{(regexp "^https?://").ReplaceAllString workspace_host ""}}
default: {{.workspace.Hostname}}
token:
hint: 'personal access token to use, dapiXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
hide_input: true
http_path:
hint: 'HTTP path of SQL warehouse to use'
default: {{.http_path}}
{{- /* dbt selects the workspace on a host shared by several workspaces with ?o=<id> in the
HTTP path. Add it when the workspace URL has the ID. */}}
default: {{.http_path}}{{with .workspace.URLID}}?o={{urlquery .}}{{end}}
{{- if eq .default_catalog ""}}
_choose_unity_catalog:
'use the default workspace catalog (or do not use Unity Catalog)':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template_dir": "../default",
"welcome_message": "Welcome to the minimal Declarative Automation Bundle template!\n\nThis template creates a minimal project structure without sample code, ideal for advanced users.\n(For getting started with Python or SQL code, use the default-python or default-sql templates instead.)\n\nYour workspace at {{workspace_host}} is used for initialization.\n(See https://docs.databricks.com/dev-tools/cli/profiles.html for how to change your profile.)",
"welcome_message": "Welcome to the minimal Declarative Automation Bundle template!\n\nThis template creates a minimal project structure without sample code, ideal for advanced users.\n(For getting started with Python or SQL code, use the default-python or default-sql templates instead.)\n\nYour workspace at {{.workspace.URL}} is used for initialization.\n(See https://docs.databricks.com/dev-tools/cli/profiles.html for how to change your profile.)",
"properties": {
"template_name": {
"//": "This property is always set to 'default-minimal'",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template_dir": "../default",
"welcome_message": "Welcome to the default Python template for Declarative Automation Bundles!\n\nAnswer the following questions to customize your project.\nYou can always change your configuration in the databricks.yml file later.\n\nNote that {{workspace_host}} is used for initialization.\n(For information on how to change your profile, see https://docs.databricks.com/dev-tools/cli/profiles.html.)",
"welcome_message": "Welcome to the default Python template for Declarative Automation Bundles!\n\nAnswer the following questions to customize your project.\nYou can always change your configuration in the databricks.yml file later.\n\nNote that {{.workspace.URL}} is used for initialization.\n(For information on how to change your profile, see https://docs.databricks.com/dev-tools/cli/profiles.html.)",
"properties": {
"template_name": {
"//": "This property is always set to 'default-python'",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"welcome_message": "\nWelcome to the default-scala template for Declarative Automation Bundles!\n\nA workspace was selected based on your current profile. For information about how to change this, see https://docs.databricks.com/dev-tools/cli/profiles.html.\nworkspace_host: {{workspace_host}}",
"welcome_message": "\nWelcome to the default-scala template for Declarative Automation Bundles!\n\nA workspace was selected based on your current profile. For information about how to change this, see https://docs.databricks.com/dev-tools/cli/profiles.html.\nworkspace_host: {{.workspace.URL}}",
"properties": {
"project_name": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ variables:
{{- end}}

workspace:
host: {{workspace_host}}
host: {{.workspace.URL}}
artifact_path: {{.artifacts_dest_path}}/${bundle.name}/${bundle.target}/${workspace.current_user.short_name}

artifacts:
Expand All @@ -42,15 +42,15 @@ targets:
mode: development
default: true
workspace:
host: {{workspace_host}}
host: {{.workspace.URL}}
variables:
catalog: {{.default_catalog}}
schema: {{$dev_schema}}

prod:
mode: production
workspace:
host: {{workspace_host}}
host: {{.workspace.URL}}
# We explicitly deploy to /Workspace/Users/{{user_name}} to make sure we only have a single copy.
root_path: /Workspace/Users/{{user_name}}/.bundle/${bundle.name}/${bundle.target}
permissions:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"welcome_message": "\nWelcome to the default SQL template for Declarative Automation Bundles!\n\nA workspace was selected based on your current profile. For information about how to change this, see https://docs.databricks.com/dev-tools/cli/profiles.html.\nworkspace_host: {{workspace_host}}",
"welcome_message": "\nWelcome to the default SQL template for Declarative Automation Bundles!\n\nA workspace was selected based on your current profile. For information about how to change this, see https://docs.databricks.com/dev-tools/cli/profiles.html.\nworkspace_host: {{.workspace.URL}}",
"properties": {
"project_name": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ targets:
mode: development
default: true
workspace:
host: {{workspace_host}}
host: {{.workspace.URL}}
variables:
warehouse_id: {{index ((regexp "[^/]+$").FindStringSubmatch .http_path) 0}}
catalog: {{.default_catalog}}
Expand All @@ -42,7 +42,7 @@ targets:
prod:
mode: production
workspace:
host: {{workspace_host}}
host: {{.workspace.URL}}
# We explicitly deploy to /Workspace/Users/{{user_name}} to make sure we only have a single copy.
root_path: /Workspace/Users/{{user_name}}/.bundle/${bundle.name}/${bundle.target}
variables:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ targets:
mode: development
default: true
workspace:
host: {{workspace_host}}
host: {{.workspace.URL}}
variables:
catalog: {{.default_catalog}}
schema: {{$dev_schema}}
Expand All @@ -60,7 +60,7 @@ targets:
prod:
mode: production
workspace:
host: {{workspace_host}}
host: {{.workspace.URL}}
# We explicitly deploy to /Workspace/Users/{{user_name}} to make sure we only have a single copy.
root_path: /Workspace/Users/{{user_name}}/.bundle/${bundle.name}/${bundle.target}
variables:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ targets:
mode: development
default: true
workspace:
host: {{workspace_host}}
host: {{.workspace.URL}}
prod:
mode: production
workspace:
host: {{workspace_host}}
host: {{.workspace.URL}}
# We explicitly deploy to /Workspace/Users/{{user_name}} to make sure we only have a single copy.
root_path: /Workspace/Users/{{user_name}}/.bundle/${bundle.name}/${bundle.target}
permissions:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template_dir": "../default",
"welcome_message": "Welcome to the template for Lakeflow Spark Declarative Pipelines!\n\nPlease answer the below to tailor your project to your preferences.\nYou can always change your mind and change your configuration in the databricks.yml file later.\n\nNote that {{workspace_host}} is used for initialization\n(see https://docs.databricks.com/dev-tools/cli/profiles.html for how to change your profile).",
"welcome_message": "Welcome to the template for Lakeflow Spark Declarative Pipelines!\n\nPlease answer the below to tailor your project to your preferences.\nYou can always change your mind and change your configuration in the databricks.yml file later.\n\nNote that {{.workspace.URL}} is used for initialization\n(see https://docs.databricks.com/dev-tools/cli/profiles.html for how to change your profile).",
"properties": {
"template_name": {
"//": "This property is always set to 'lakeflow-pipelines'",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template_dir": "../default",
"welcome_message": "Welcome to PyDABs template for Declarative Automation Bundles!\n\nAnswer the following questions to customize your project.\nYou can always change your configuration in the databricks.yml file later.\n\nNote that {{workspace_host}} is used for initialization.\n(For information on how to change your profile, see https://docs.databricks.com/dev-tools/cli/profiles.html.)",
"welcome_message": "Welcome to PyDABs template for Declarative Automation Bundles!\n\nAnswer the following questions to customize your project.\nYou can always change your configuration in the databricks.yml file later.\n\nNote that {{.workspace.URL}} is used for initialization.\n(For information on how to change your profile, see https://docs.databricks.com/dev-tools/cli/profiles.html.)",
"properties": {
"template_name": {
"//": "This property is always set to 'PyDABs'",
Expand Down
Loading