From d7d4f660bb2765676283796e8b78f7669e49b315 Mon Sep 17 00:00:00 2001 From: Petra Postelnicu Date: Mon, 2 Nov 2026 14:51:18 +0000 Subject: [PATCH 1/2] Include variable locations in --include-locations output The location map that `bundle validate` and `bundle summary` emit with --include-locations now covers variables: - variables.: where the variable is declared. - variables..value: where the resolved value comes from, such as a target override or .databricks/bundle//variable-overrides.json. It is absent when the value has no file, as with --var, BUNDLE_VAR_*, and lookups. The workspace UI uses this to link each variable to its file. Co-authored-by: Isaac --- .../bundle/dev/variable-overrides.json | 3 + .../bundle/variables/locations/.gitignore | 1 + .../bundle/variables/locations/databricks.yml | 47 +++++++++ .../bundle/variables/locations/out.test.toml | 2 + .../bundle/variables/locations/output.txt | 99 +++++++++++++++++++ acceptance/bundle/variables/locations/script | 7 ++ .../bundle/variables/locations/targets.yml | 4 + .../bundle/variables/locations/test.toml | 10 ++ .../variables/locations/variables/shared.yml | 5 + libs/dyn/dynloc/locations.go | 2 + 10 files changed, 180 insertions(+) create mode 100644 acceptance/bundle/variables/locations/.databricks/bundle/dev/variable-overrides.json create mode 100644 acceptance/bundle/variables/locations/.gitignore create mode 100644 acceptance/bundle/variables/locations/databricks.yml create mode 100644 acceptance/bundle/variables/locations/out.test.toml create mode 100644 acceptance/bundle/variables/locations/output.txt create mode 100644 acceptance/bundle/variables/locations/script create mode 100644 acceptance/bundle/variables/locations/targets.yml create mode 100644 acceptance/bundle/variables/locations/test.toml create mode 100644 acceptance/bundle/variables/locations/variables/shared.yml diff --git a/acceptance/bundle/variables/locations/.databricks/bundle/dev/variable-overrides.json b/acceptance/bundle/variables/locations/.databricks/bundle/dev/variable-overrides.json new file mode 100644 index 00000000000..d423fa9a7d9 --- /dev/null +++ b/acceptance/bundle/variables/locations/.databricks/bundle/dev/variable-overrides.json @@ -0,0 +1,3 @@ +{ + "from_file": "file-value" +} diff --git a/acceptance/bundle/variables/locations/.gitignore b/acceptance/bundle/variables/locations/.gitignore new file mode 100644 index 00000000000..bd1711fd16e --- /dev/null +++ b/acceptance/bundle/variables/locations/.gitignore @@ -0,0 +1 @@ +!.databricks diff --git a/acceptance/bundle/variables/locations/databricks.yml b/acceptance/bundle/variables/locations/databricks.yml new file mode 100644 index 00000000000..9a2f6b2b9ee --- /dev/null +++ b/acceptance/bundle/variables/locations/databricks.yml @@ -0,0 +1,47 @@ +bundle: + name: variable_locations + +include: + - variables/*.yml + - targets.yml + +variables: + simple: + default: simple-default + from_cli: + description: Required, assigned with --var + from_env: + description: Required, assigned with BUNDLE_VAR_from_env + from_file: + description: Required, assigned in variable-overrides.json + complex_var: + type: complex + default: + key: value + var_in_var: + default: ${var.simple}-suffix + lookup_var: + lookup: + service_principal: deco-test-spn + override_short: + default: base + override_full: + default: base + split: + description: Declared here, default in an included file + dash-name: + default: dash-default + lookup_overridden: + lookup: + service_principal: deco-test-spn + +targets: + dev: + default: true + variables: + override_short: dev-short + override_full: + default: dev-full + complex_var: + key: dev-value + lookup_overridden: dev-instead-of-lookup diff --git a/acceptance/bundle/variables/locations/out.test.toml b/acceptance/bundle/variables/locations/out.test.toml new file mode 100644 index 00000000000..a927a5fbc06 --- /dev/null +++ b/acceptance/bundle/variables/locations/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/variables/locations/output.txt b/acceptance/bundle/variables/locations/output.txt new file mode 100644 index 00000000000..8995835129d --- /dev/null +++ b/acceptance/bundle/variables/locations/output.txt @@ -0,0 +1,99 @@ + +=== Resolved variable values +>>> [CLI] bundle summary -o json --include-locations --var from_cli=cli-value +{ + "complex_var": { + "key": "dev-value" + }, + "dash-name": "dash-default", + "from_cli": "cli-value", + "from_env": "env-value", + "from_file": "file-value", + "included": "dev-included", + "lookup_overridden": "dev-instead-of-lookup", + "lookup_var": "[UUID]", + "override_full": "dev-full", + "override_short": "dev-short", + "simple": "simple-default", + "split": "split-default", + "var_in_var": "simple-default-suffix" +} + +=== Variable locations as file:line:column +>>> [CLI] bundle summary -o json --include-locations --var from_cli=cli-value +{ + "variables": [ + "databricks.yml:9:3", + "variables/shared.yml:2:3" + ], + "variables.complex_var": [ + "databricks.yml:18:5" + ], + "variables.complex_var.value": [ + "databricks.yml:46:9" + ], + "variables.dash-name": [ + "databricks.yml:33:5" + ], + "variables.dash-name.value": [ + "databricks.yml:33:14" + ], + "variables.from_cli": [ + "databricks.yml:12:5" + ], + "variables.from_env": [ + "databricks.yml:14:5" + ], + "variables.from_file": [ + "databricks.yml:16:5" + ], + "variables.from_file.value": [ + ".databricks/bundle/dev/variable-overrides.json:2:28" + ], + "variables.included": [ + "variables/shared.yml:3:5" + ], + "variables.included.value": [ + "targets.yml:4:17" + ], + "variables.lookup_overridden": [ + "databricks.yml:35:5" + ], + "variables.lookup_overridden.value": [ + "databricks.yml:47:26" + ], + "variables.lookup_var": [ + "databricks.yml:24:5" + ], + "variables.override_full": [ + "databricks.yml:29:5" + ], + "variables.override_full.value": [ + "databricks.yml:44:18" + ], + "variables.override_short": [ + "databricks.yml:27:5" + ], + "variables.override_short.value": [ + "databricks.yml:42:23" + ], + "variables.simple": [ + "databricks.yml:10:5" + ], + "variables.simple.value": [ + "databricks.yml:10:14" + ], + "variables.split": [ + "databricks.yml:31:5", + "variables/shared.yml:5:5" + ], + "variables.split.value": [ + "variables/shared.yml:5:14" + ], + "variables.var_in_var": [ + "databricks.yml:22:5" + ], + "variables.var_in_var.value": [ + "databricks.yml:22:14" + ] +} diff --git a/acceptance/bundle/variables/locations/script b/acceptance/bundle/variables/locations/script new file mode 100644 index 00000000000..eca7391e312 --- /dev/null +++ b/acceptance/bundle/variables/locations/script @@ -0,0 +1,7 @@ +export BUNDLE_VAR_from_env=env-value + +title "Resolved variable values" +trace $CLI bundle summary -o json --include-locations --var from_cli=cli-value | jq '.variables | map_values(.value)' + +title "Variable locations as file:line:column" +trace $CLI bundle summary -o json --include-locations --var from_cli=cli-value | jq '.__locations as $l | $l.locations | with_entries(select(.key | startswith("variables"))) | map_values(map("\($l.files[.[0]]):\(.[1]):\(.[2])"))' diff --git a/acceptance/bundle/variables/locations/targets.yml b/acceptance/bundle/variables/locations/targets.yml new file mode 100644 index 00000000000..6f7b18fc5e0 --- /dev/null +++ b/acceptance/bundle/variables/locations/targets.yml @@ -0,0 +1,4 @@ +targets: + dev: + variables: + included: dev-included diff --git a/acceptance/bundle/variables/locations/test.toml b/acceptance/bundle/variables/locations/test.toml new file mode 100644 index 00000000000..d8de392a48e --- /dev/null +++ b/acceptance/bundle/variables/locations/test.toml @@ -0,0 +1,10 @@ +[[Server]] +Pattern = "GET /api/2.0/preview/scim/v2/ServicePrincipals" +Response.Body = '''{ + "Resources": [ + { + "displayName": "deco-test-spn", + "applicationId": "123e4567-e89b-12d3-a456-426614174000" + } + ] +}''' diff --git a/acceptance/bundle/variables/locations/variables/shared.yml b/acceptance/bundle/variables/locations/variables/shared.yml new file mode 100644 index 00000000000..1696dc5d154 --- /dev/null +++ b/acceptance/bundle/variables/locations/variables/shared.yml @@ -0,0 +1,5 @@ +variables: + included: + default: included-default + split: + default: split-default diff --git a/libs/dyn/dynloc/locations.go b/libs/dyn/dynloc/locations.go index d343e24533c..0d3f55be08f 100644 --- a/libs/dyn/dynloc/locations.go +++ b/libs/dyn/dynloc/locations.go @@ -46,6 +46,8 @@ func (l *Locations) gatherLocations(v dyn.Value) (map[string][]diag.Location, er dyn.NewPattern(dyn.Key("resources"), dyn.AnyKey(), dyn.AnyKey()), // Resources for all types ("resources.jobs.my_job") dyn.NewPattern(dyn.Key("resources"), dyn.Key("jobs"), dyn.AnyKey(), dyn.Key("tasks")), // Job tasks ("resources.jobs.my_job.tasks") dyn.NewPattern(dyn.Key("resources"), dyn.Key("jobs"), dyn.AnyKey(), dyn.Key("tasks"), dyn.AnyIndex()), // Job task items ("resources.jobs.my_job.tasks[2]") + dyn.NewPattern(dyn.Key("variables"), dyn.AnyKey()), // Variable definitions ("variables.my_var") + dyn.NewPattern(dyn.Key("variables"), dyn.AnyKey(), dyn.Key("value")), // Resolved variable values ("variables.my_var.value") } for _, pattern := range patterns { From f969f68e6e82b72672759f7e30b19e7f87dad323 Mon Sep 17 00:00:00 2001 From: Petra Postelnicu Date: Fri, 6 Nov 2026 12:34:25 +0000 Subject: [PATCH 2/2] fix comments --- .nextchanges/bundles/variable-locations.md | 1 + .../bundle/variables/locations/databricks.yml | 3 --- .../bundle/variables/locations/output.txt | 24 ++++++++----------- .../bundle/variables/locations/test.toml | 10 -------- 4 files changed, 11 insertions(+), 27 deletions(-) create mode 100644 .nextchanges/bundles/variable-locations.md delete mode 100644 acceptance/bundle/variables/locations/test.toml diff --git a/.nextchanges/bundles/variable-locations.md b/.nextchanges/bundles/variable-locations.md new file mode 100644 index 00000000000..7a52d159168 --- /dev/null +++ b/.nextchanges/bundles/variable-locations.md @@ -0,0 +1 @@ +* Include variable declarations and the source of each resolved value in the `--include-locations` output of `bundle validate` and `bundle summary`. ([#7351](https://github.com/databricks/cli/pull/7351)) diff --git a/acceptance/bundle/variables/locations/databricks.yml b/acceptance/bundle/variables/locations/databricks.yml index 9a2f6b2b9ee..3057615118d 100644 --- a/acceptance/bundle/variables/locations/databricks.yml +++ b/acceptance/bundle/variables/locations/databricks.yml @@ -20,9 +20,6 @@ variables: key: value var_in_var: default: ${var.simple}-suffix - lookup_var: - lookup: - service_principal: deco-test-spn override_short: default: base override_full: diff --git a/acceptance/bundle/variables/locations/output.txt b/acceptance/bundle/variables/locations/output.txt index 8995835129d..aa7897fbaba 100644 --- a/acceptance/bundle/variables/locations/output.txt +++ b/acceptance/bundle/variables/locations/output.txt @@ -11,7 +11,6 @@ "from_file": "file-value", "included": "dev-included", "lookup_overridden": "dev-instead-of-lookup", - "lookup_var": "[UUID]", "override_full": "dev-full", "override_short": "dev-short", "simple": "simple-default", @@ -30,13 +29,13 @@ "databricks.yml:18:5" ], "variables.complex_var.value": [ - "databricks.yml:46:9" + "databricks.yml:43:9" ], "variables.dash-name": [ - "databricks.yml:33:5" + "databricks.yml:30:5" ], "variables.dash-name.value": [ - "databricks.yml:33:14" + "databricks.yml:30:14" ], "variables.from_cli": [ "databricks.yml:12:5" @@ -57,25 +56,22 @@ "targets.yml:4:17" ], "variables.lookup_overridden": [ - "databricks.yml:35:5" + "databricks.yml:32:5" ], "variables.lookup_overridden.value": [ - "databricks.yml:47:26" - ], - "variables.lookup_var": [ - "databricks.yml:24:5" + "databricks.yml:44:26" ], "variables.override_full": [ - "databricks.yml:29:5" + "databricks.yml:26:5" ], "variables.override_full.value": [ - "databricks.yml:44:18" + "databricks.yml:41:18" ], "variables.override_short": [ - "databricks.yml:27:5" + "databricks.yml:24:5" ], "variables.override_short.value": [ - "databricks.yml:42:23" + "databricks.yml:39:23" ], "variables.simple": [ "databricks.yml:10:5" @@ -84,7 +80,7 @@ "databricks.yml:10:14" ], "variables.split": [ - "databricks.yml:31:5", + "databricks.yml:28:5", "variables/shared.yml:5:5" ], "variables.split.value": [ diff --git a/acceptance/bundle/variables/locations/test.toml b/acceptance/bundle/variables/locations/test.toml deleted file mode 100644 index d8de392a48e..00000000000 --- a/acceptance/bundle/variables/locations/test.toml +++ /dev/null @@ -1,10 +0,0 @@ -[[Server]] -Pattern = "GET /api/2.0/preview/scim/v2/ServicePrincipals" -Response.Body = '''{ - "Resources": [ - { - "displayName": "deco-test-spn", - "applicationId": "123e4567-e89b-12d3-a456-426614174000" - } - ] -}'''