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/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..3057615118d --- /dev/null +++ b/acceptance/bundle/variables/locations/databricks.yml @@ -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 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..aa7897fbaba --- /dev/null +++ b/acceptance/bundle/variables/locations/output.txt @@ -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" + ] +} 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/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 {