diff --git a/.nextchanges/bundles/builtin-templates-workspace-url.md b/.nextchanges/bundles/builtin-templates-workspace-url.md new file mode 100644 index 00000000000..76e97992a1e --- /dev/null +++ b/.nextchanges/bundles/builtin-templates-workspace-url.md @@ -0,0 +1 @@ +* Built-in templates add the workspace ID to `workspace.host` (`?w=`) 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=` to the HTTP path it suggests for `dbt init`. ([#7350](https://github.com/databricks/cli/pull/7350)) diff --git a/acceptance/bundle/templates/dbt-sql-workspace-id/input.json b/acceptance/bundle/templates/dbt-sql-workspace-id/input.json new file mode 100644 index 00000000000..ca84320e6d7 --- /dev/null +++ b/acceptance/bundle/templates/dbt-sql-workspace-id/input.json @@ -0,0 +1,6 @@ +{ + "project_name": "my_dbt_sql", + "http_path": "/sql/2.0/warehouses/f00dcafe", + "default_catalog": "main", + "personal_schemas": "yes" +} diff --git a/acceptance/bundle/templates/dbt-sql-workspace-id/out.test.toml b/acceptance/bundle/templates/dbt-sql-workspace-id/out.test.toml new file mode 100644 index 00000000000..19b5b15d11f --- /dev/null +++ b/acceptance/bundle/templates/dbt-sql-workspace-id/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/templates/dbt-sql-workspace-id/output.txt b/acceptance/bundle/templates/dbt-sql-workspace-id/output.txt new file mode 100644 index 00000000000..836fba4f276 --- /dev/null +++ b/acceptance/bundle/templates/dbt-sql-workspace-id/output.txt @@ -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 diff --git a/acceptance/bundle/templates/dbt-sql-workspace-id/script b/acceptance/bundle/templates/dbt-sql-workspace-id/script new file mode 100644 index 00000000000..f7cfa1bd350 --- /dev/null +++ b/acceptance/bundle/templates/dbt-sql-workspace-id/script @@ -0,0 +1,25 @@ +setup_custom_host + +cat > .databrickscfg <>> [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 diff --git a/acceptance/bundle/templates/default-minimal/profiles/script b/acceptance/bundle/templates/default-minimal/profiles/script new file mode 100644 index 00000000000..f3d1d94a153 --- /dev/null +++ b/acceptance/bundle/templates/default-minimal/profiles/script @@ -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 < 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)': diff --git a/libs/template/templates/default-minimal/databricks_template_schema.json b/libs/template/templates/default-minimal/databricks_template_schema.json index 0935684256b..b8df334a017 100644 --- a/libs/template/templates/default-minimal/databricks_template_schema.json +++ b/libs/template/templates/default-minimal/databricks_template_schema.json @@ -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'", diff --git a/libs/template/templates/default-python/databricks_template_schema.json b/libs/template/templates/default-python/databricks_template_schema.json index d8d5e485ced..e9e61f4a924 100644 --- a/libs/template/templates/default-python/databricks_template_schema.json +++ b/libs/template/templates/default-python/databricks_template_schema.json @@ -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'", diff --git a/libs/template/templates/default-scala/databricks_template_schema.json b/libs/template/templates/default-scala/databricks_template_schema.json index 9501c56196d..652c0d374e4 100644 --- a/libs/template/templates/default-scala/databricks_template_schema.json +++ b/libs/template/templates/default-scala/databricks_template_schema.json @@ -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", diff --git a/libs/template/templates/default-scala/template/{{.project_name}}/databricks.yml.tmpl b/libs/template/templates/default-scala/template/{{.project_name}}/databricks.yml.tmpl index 749f2a4e993..ec11354f3b6 100644 --- a/libs/template/templates/default-scala/template/{{.project_name}}/databricks.yml.tmpl +++ b/libs/template/templates/default-scala/template/{{.project_name}}/databricks.yml.tmpl @@ -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: @@ -42,7 +42,7 @@ targets: mode: development default: true workspace: - host: {{workspace_host}} + host: {{.workspace.URL}} variables: catalog: {{.default_catalog}} schema: {{$dev_schema}} @@ -50,7 +50,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} permissions: diff --git a/libs/template/templates/default-sql/databricks_template_schema.json b/libs/template/templates/default-sql/databricks_template_schema.json index c6f66d495a8..6967c3ec123 100644 --- a/libs/template/templates/default-sql/databricks_template_schema.json +++ b/libs/template/templates/default-sql/databricks_template_schema.json @@ -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", diff --git a/libs/template/templates/default-sql/template/{{.project_name}}/databricks.yml.tmpl b/libs/template/templates/default-sql/template/{{.project_name}}/databricks.yml.tmpl index 0645de3dadf..cfc2c2cc2fc 100644 --- a/libs/template/templates/default-sql/template/{{.project_name}}/databricks.yml.tmpl +++ b/libs/template/templates/default-sql/template/{{.project_name}}/databricks.yml.tmpl @@ -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}} @@ -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: diff --git a/libs/template/templates/default/template/{{.project_name}}/databricks.yml.tmpl b/libs/template/templates/default/template/{{.project_name}}/databricks.yml.tmpl index 73cddd42052..42b15164c8e 100644 --- a/libs/template/templates/default/template/{{.project_name}}/databricks.yml.tmpl +++ b/libs/template/templates/default/template/{{.project_name}}/databricks.yml.tmpl @@ -49,7 +49,7 @@ targets: mode: development default: true workspace: - host: {{workspace_host}} + host: {{.workspace.URL}} variables: catalog: {{.default_catalog}} schema: {{$dev_schema}} @@ -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: diff --git a/libs/template/templates/lakeflow-integrations/template/{{.project_name}}/databricks.yml.tmpl b/libs/template/templates/lakeflow-integrations/template/{{.project_name}}/databricks.yml.tmpl index 8087d648d4d..ba651def676 100644 --- a/libs/template/templates/lakeflow-integrations/template/{{.project_name}}/databricks.yml.tmpl +++ b/libs/template/templates/lakeflow-integrations/template/{{.project_name}}/databricks.yml.tmpl @@ -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: diff --git a/libs/template/templates/lakeflow-pipelines/databricks_template_schema.json b/libs/template/templates/lakeflow-pipelines/databricks_template_schema.json index 8639acc49e9..ddd17278829 100644 --- a/libs/template/templates/lakeflow-pipelines/databricks_template_schema.json +++ b/libs/template/templates/lakeflow-pipelines/databricks_template_schema.json @@ -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'", diff --git a/libs/template/templates/pydabs/databricks_template_schema.json b/libs/template/templates/pydabs/databricks_template_schema.json index 4819b5bb773..d53f8ba85cc 100644 --- a/libs/template/templates/pydabs/databricks_template_schema.json +++ b/libs/template/templates/pydabs/databricks_template_schema.json @@ -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'",