diff --git a/acceptance/bundle/variables/variable_overrides_in_target/databricks.yml b/acceptance/bundle/variables/variable_overrides_in_target/databricks.yml index 3a26996dd8..9c1512dd87 100644 --- a/acceptance/bundle/variables/variable_overrides_in_target/databricks.yml +++ b/acceptance/bundle/variables/variable_overrides_in_target/databricks.yml @@ -22,6 +22,11 @@ variables: default: true description: "A boolean variable" + w_lookup: + description: "A variable with a lookup" + lookup: + cluster: "some-test-cluster" # id 4321 + targets: use-default-variable-values: @@ -37,3 +42,13 @@ targets: variables: foo: "overridden_string" baz: false + + override-lookup-variable-with-value: + variables: + w_lookup: "my-specific-cluster-id" + + override-lookup-variable-with-lookup: + variables: + w_lookup: + lookup: + cluster: "some-other-cluster" # id 9876 diff --git a/acceptance/bundle/variables/variable_overrides_in_target/output.txt b/acceptance/bundle/variables/variable_overrides_in_target/output.txt index 106253110f..e34e2df930 100644 --- a/acceptance/bundle/variables/variable_overrides_in_target/output.txt +++ b/acceptance/bundle/variables/variable_overrides_in_target/output.txt @@ -86,3 +86,9 @@ } } } + +>>> [CLI] bundle validate -o json -t override-lookup-variable-with-value +"my-specific-cluster-id" + +>>> [CLI] bundle validate -o json -t override-lookup-variable-with-lookup +"9876" diff --git a/acceptance/bundle/variables/variable_overrides_in_target/script b/acceptance/bundle/variables/variable_overrides_in_target/script index 686b3102a6..e814802893 100644 --- a/acceptance/bundle/variables/variable_overrides_in_target/script +++ b/acceptance/bundle/variables/variable_overrides_in_target/script @@ -2,3 +2,5 @@ trace $CLI bundle validate -o json -t use-default-variable-values | jq .resource trace $CLI bundle validate -o json -t override-string-variable | jq .resources trace $CLI bundle validate -o json -t override-int-variable | jq .resources trace $CLI bundle validate -o json -t override-both-bool-and-string-variables | jq .resources +trace $CLI bundle validate -o json -t override-lookup-variable-with-value | jq .variables.w_lookup.value +trace $CLI bundle validate -o json -t override-lookup-variable-with-lookup | jq .variables.w_lookup.value diff --git a/bundle/config/root.go b/bundle/config/root.go index 861791fc34..a32ca8ea28 100644 --- a/bundle/config/root.go +++ b/bundle/config/root.go @@ -347,12 +347,28 @@ func (r *Root) MergeTargetOverrides(name string) error { if vDefault.Kind() != dyn.KindInvalid { defaultPath := varPath.Append(dyn.Key("default")) root, err = dyn.SetByPath(root, defaultPath, vDefault) + if err != nil { + return root, err + } + + // If the target explicitly sets a default value, drop any lookup from the + // root variable definition so SetVariables can assign this default. + lookupPath := varPath.Append(dyn.Key("lookup")) + root, err = dyn.SetByPath(root, lookupPath, dyn.NilValue) } vLookup := variable.Get("lookup") if vLookup.Kind() != dyn.KindInvalid { lookupPath := varPath.Append(dyn.Key("lookup")) root, err = dyn.SetByPath(root, lookupPath, vLookup) + if err != nil { + return root, err + } + + // If the target explicitly sets a lookup, drop any default value from the + // root variable definition so lookup resolution remains authoritative. + defaultPath := varPath.Append(dyn.Key("default")) + root, err = dyn.SetByPath(root, defaultPath, dyn.NilValue) } return root, err