This commit is contained in:
Shreyas Goenka 2024-09-04 16:18:34 +02:00
parent 176bb4b382
commit 507b99dca1
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
4 changed files with 69 additions and 19 deletions

View File

@ -139,12 +139,12 @@ func TestRootMergeTargetOverridesWithVariables(t *testing.T) {
},
Targets: map[string]*Target{
"development": {
Variables: map[string]any{
"foo": variable.Variable{
Variables: map[string]*TargetVariable{
"foo": {
Default: "bar",
Description: "wrong",
},
"complex": variable.Variable{
"complex": {
Type: "wrong",
Description: "wrong",
Default: map[string]interface{}{

View File

@ -2,11 +2,14 @@ package config
import (
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/cli/bundle/config/variable"
"github.com/databricks/databricks-sdk-go/service/jobs"
)
type Mode string
type TargetVariable variable.Variable
// Target defines overrides for a single target.
// This structure is recursively merged into the root configuration.
type Target struct {
@ -56,7 +59,7 @@ type Target struct {
// variables:
// foo:
// lookup: "resource_name"
Variables map[string]any `json:"variables,omitempty"`
Variables map[string]*TargetVariable `json:"variables,omitempty"`
Git Git `json:"git,omitempty"`

View File

@ -21,6 +21,19 @@ func addInterpolationPatterns(typ reflect.Type, s jsonschema.Schema) jsonschema.
return s
}
// The variables block in a target override allows for directly specifying
// the value if it is a primitive type.
if typ == reflect.TypeOf(config.TargetVariable{}) {
return jsonschema.Schema{
AnyOf: []jsonschema.Schema{s,
{Type: jsonschema.StringType},
{Type: jsonschema.BooleanType},
{Type: jsonschema.IntegerType},
{Type: jsonschema.NumberType},
},
}
}
switch s.Type {
case jsonschema.ArrayType, jsonschema.ObjectType:
// arrays and objects can have complex variable values specified.

View File

@ -995,7 +995,7 @@
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Sync"
},
"variables": {
"$ref": "#/$defs/map/interface"
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config.TargetVariable"
},
"workspace": {
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Workspace"
@ -1009,6 +1009,40 @@
}
]
},
"config.TargetVariable": {
"anyOf": [
{
"type": "object",
"properties": {
"default": {
"$ref": "#/$defs/interface"
},
"description": {
"$ref": "#/$defs/string"
},
"lookup": {
"$ref": "#/$defs/github.com/databricks/cli/bundle/config/variable.Lookup"
},
"type": {
"$ref": "#/$defs/github.com/databricks/cli/bundle/config/variable.VariableType"
}
},
"additionalProperties": false
},
{
"type": "string"
},
{
"type": "boolean"
},
{
"type": "integer"
},
{
"type": "number"
}
]
},
"config.Workspace": {
"anyOf": [
{
@ -5049,25 +5083,25 @@
"pattern": "\\$\\{(var(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)+)\\}"
}
]
},
"config.TargetVariable": {
"anyOf": [
{
"type": "object",
"additionalProperties": {
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.TargetVariable"
}
},
{
"type": "string",
"pattern": "\\$\\{(var(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)*(\\[[0-9]+\\])*)\\}"
}
]
}
}
}
}
},
"interface": {
"anyOf": [
{
"type": "object",
"additionalProperties": {
"$ref": "#/$defs/interface"
}
},
{
"type": "string",
"pattern": "\\$\\{(var(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)*(\\[[0-9]+\\])*)\\}"
}
]
},
"string": {
"anyOf": [
{