Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +5 to +6
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

.variables.w_lookup.value because the value isn't being used in .resources - didn't want to change the whole bundle definition with something that supports lookup

16 changes: 16 additions & 0 deletions bundle/config/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading