databricks-vscode icon indicating copy to clipboard operation
databricks-vscode copied to clipboard

[BUG] DATABRICKS_HOST environment variable is not respected if host if not specified in bundle configuration

Open NathanNZ opened this issue 8 months ago • 2 comments

Describe the bug I often work with example bundles for deployment - one useful feature is to use the "DATABRICKS_HOST"' command to enable reproducible deployments targeted towards any environment. This allows a single place to change in a DevOps pipeline to deploy all the bundles

To Reproduce

  1. Set the DATABRICKS_HOST environment variable
  2. Open any Bundle file that doesn't have a "host" entry.
  3. See error 'Invalid host for target" in the configuration section.

Expected Behaviour

If the workspace.host variable is not set and DATABRICKS_HOST is set - match the behaviour of the Databricks CLI and assume that workspace.host is the DATABRICKS_HOST variable. The user could also be prompted at this stage to select or provide a workspace URL, similar to the workspace prompt when you initalise a new bundle and the DATABRICKS_HOST variable is in that selection.

Screenshots

Image

Image

System information:

Version: 1.99.0 (user setup) Commit: 4437686ffebaf200fa4a6e6e67f735f3edf24ada Date: 2025-04-02T21:35:19.530Z Electron: 34.3.2 ElectronBuildId: 11161073 Chromium: 132.0.6834.210 Node.js: 20.18.3 V8: 13.2.152.41-electron.0 OS: Windows_NT x64 10.0.26100

Version : 2.9.2

Additional context Running the "databricks bundle deploy" command in the command line works.

I believe this could be fixed by:

Happy to take a stab at putting together a pull request if a general approach is agreed!

NathanNZ avatar Apr 20 '25 12:04 NathanNZ

Hi, one clarification - how do you set the DATABRICKS_HOST env var? It's easy to do for CLI commands, as you can set in in the shell session right before running a command. But that value won't be accessible to the extension process, as it was started by the VSCode and only has access to the env vars VSCode was launched with.

But it's true that even if you set it for the VSCode, we will still ignore it.

ilia-db avatar Apr 23 '25 11:04 ilia-db

Hi, one clarification - how do you set the DATABRICKS_HOST env var? It's easy to do for CLI commands, as you can set in in the shell session right before running a command. But that value won't be accessible to the extension process, as it was started by the VSCode and only has access to the env vars VSCode was launched with.

But it's true that even if you set it for the VSCode, we will still ignore it.

Good question! I'm using Dev Containers and GitHub Codespaces that allow you to set environment variables that all processes (including VSCode processes) end up using.

This is a bit clunky - so I'm leaning towards providing a prompt and just suggesting DATABRICKS_HOST if it's set, and allowing someone to manually enter it if not. Should help when hosting labs or working in organisations that have a subscription per developer. (such as Microsoft's MSDN that gives an individual credit). Or just those who prefer to adopt a pattern where all environments are treated the same with the DevOps agent handling where to deploy the code to.

This would be expanding to adopt similar logic for how initialisation of a new project is currently handled.

If an environment without a host is not selected, use the selector to choose a host (but not persist it to the file, just so other developers can apply it to their own environment) - probably would make sense to remember this host for future development as well. Image

NathanNZ avatar Apr 23 '25 23:04 NathanNZ