diff --git a/.nextchanges/bundles/7410.md b/.nextchanges/bundles/7410.md new file mode 100644 index 00000000000..5ec47d599eb --- /dev/null +++ b/.nextchanges/bundles/7410.md @@ -0,0 +1 @@ +* Add `DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE`, which names a profile whose host the `workspace_host` template helper returns instead of the selected profile's host. The profile must have the selected profile's workspace ID. ([#7410](https://github.com/databricks/cli/pull/7410)) diff --git a/acceptance/bundle/templates-machinery/workspace_variable/runtime/helpers/databricks_template_schema.json b/acceptance/bundle/templates-machinery/workspace_variable/runtime/helpers/databricks_template_schema.json new file mode 100644 index 00000000000..c72d0ef82b2 --- /dev/null +++ b/acceptance/bundle/templates-machinery/workspace_variable/runtime/helpers/databricks_template_schema.json @@ -0,0 +1,10 @@ +{ + "welcome_message": "workspace_host: {{ workspace_host }}, URL: {{ .workspace.URL }}", + "properties": { + "host": { + "type": "string", + "description": "Host for {{ user_name }}", + "default": "{{ workspace_host }}" + } + } +} diff --git a/acceptance/bundle/templates-machinery/workspace_variable/runtime/helpers/template/helpers.txt.tmpl b/acceptance/bundle/templates-machinery/workspace_variable/runtime/helpers/template/helpers.txt.tmpl new file mode 100644 index 00000000000..b8a4edeaaa7 --- /dev/null +++ b/acceptance/bundle/templates-machinery/workspace_variable/runtime/helpers/template/helpers.txt.tmpl @@ -0,0 +1,4 @@ +workspace_host: {{ workspace_host }} +host: {{ .host }} +URL: {{ .workspace.URL }} +user_name: {{ user_name }} diff --git a/acceptance/bundle/templates-machinery/workspace_variable/runtime/output.txt b/acceptance/bundle/templates-machinery/workspace_variable/runtime/output.txt index eec7fe20829..daf86a3620f 100644 --- a/acceptance/bundle/templates-machinery/workspace_variable/runtime/output.txt +++ b/acceptance/bundle/templates-machinery/workspace_variable/runtime/output.txt @@ -221,6 +221,34 @@ URL "/jobs": [DATABRICKS_URL]/jobs?w=[WORKSPACE_ID] URL "/jobs?view=list#top": [DATABRICKS_URL]/jobs?view=list&w=[WORKSPACE_ID]#top URLID: "[WORKSPACE_ID]" +=== Workspace host profile + +>>> DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE=workspace_classic_id [CLI] bundle debug render-template-schema ./helpers --profile workspace_custom_host +{ + "welcome_message": "workspace_host: [DATABRICKS_URL], URL: [CUSTOM_HOST]?w=[WORKSPACE_ID]", + "success_message": null, + "properties": { + "host": { + "description": "Host for [USERNAME]", + "default": "[DATABRICKS_URL]" + } + } +} + +>>> DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE=workspace_classic_id [CLI] bundle init ./helpers --profile workspace_custom_host +workspace_host: [DATABRICKS_URL], URL: [CUSTOM_HOST]?w=[WORKSPACE_ID] +✨ Successfully initialized template +workspace_host: [DATABRICKS_URL] +host: [DATABRICKS_URL] +URL: [CUSTOM_HOST]?w=[WORKSPACE_ID] +user_name: [USERNAME] + +>>> DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE=other_workspace musterr [CLI] bundle init ./helpers --profile workspace_custom_host +Error: template: :1:19: executing "" at : error calling workspace_host: profile "other_workspace" from DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE has workspace ID "1234", but the selected profile has workspace ID "[WORKSPACE_ID]" + +>>> DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE=missing musterr [CLI] bundle debug render-template-schema ./helpers --profile workspace_custom_host +Error: property host default: failed to render template "{{ workspace_host }}": template: base:1:3: executing "base" at : error calling workspace_host: profile "missing" from DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE not found or has no host + === ID >>> [CLI] bundle init ./id --profile workspace_classic diff --git a/acceptance/bundle/templates-machinery/workspace_variable/runtime/script b/acceptance/bundle/templates-machinery/workspace_variable/runtime/script index 45e8bb48226..c670d6dcec1 100644 --- a/acceptance/bundle/templates-machinery/workspace_variable/runtime/script +++ b/acceptance/bundle/templates-machinery/workspace_variable/runtime/script @@ -52,6 +52,24 @@ grep ^URL urls.txt cd .. rm -r in_bundle +# DABs in the Workspace selects the profile for the host of the page and names a profile for the +# workspace's own host in DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE: workspace_host returns +# that host, while .workspace and the other helpers keep the selected profile. +title "Workspace host profile\n" +trace DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE=workspace_classic_id $CLI bundle debug render-template-schema ./helpers --profile workspace_custom_host | schema_fields +trace DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE=workspace_classic_id $CLI bundle init ./helpers --profile workspace_custom_host +cat helpers.txt +rm helpers.txt + +cat >> .databrickscfg <