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/variable-locations.md
Original file line number Diff line number Diff line change
@@ -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))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"from_file": "file-value"
}
1 change: 1 addition & 0 deletions acceptance/bundle/variables/locations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!.databricks
44 changes: 44 additions & 0 deletions acceptance/bundle/variables/locations/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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
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
2 changes: 2 additions & 0 deletions acceptance/bundle/variables/locations/out.test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DMS = ["", "true"]
95 changes: 95 additions & 0 deletions acceptance/bundle/variables/locations/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

=== 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",
"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:43:9"
],
"variables.dash-name": [
"databricks.yml:30:5"
],
"variables.dash-name.value": [
"databricks.yml:30: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:32:5"
],
"variables.lookup_overridden.value": [
"databricks.yml:44:26"
],
"variables.override_full": [
"databricks.yml:26:5"
],
"variables.override_full.value": [
"databricks.yml:41:18"
],
"variables.override_short": [
"databricks.yml:24:5"
],
"variables.override_short.value": [
"databricks.yml:39:23"
],
"variables.simple": [
"databricks.yml:10:5"
],
"variables.simple.value": [
"databricks.yml:10:14"
],
"variables.split": [
"databricks.yml:28: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"
]
}
7 changes: 7 additions & 0 deletions acceptance/bundle/variables/locations/script
Original file line number Diff line number Diff line change
@@ -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])"))'
4 changes: 4 additions & 0 deletions acceptance/bundle/variables/locations/targets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
targets:
dev:
variables:
included: dev-included
5 changes: 5 additions & 0 deletions acceptance/bundle/variables/locations/variables/shared.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variables:
included:
default: included-default
split:
default: split-default
2 changes: 2 additions & 0 deletions libs/dyn/dynloc/locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this get a .nextchanges/bundles/ entry? The last --include-locations change (#7185) has one in the changelog, and the UI side will want to know which CLI version ships the variable keys.

}

for _, pattern := range patterns {
Expand Down
Loading