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{ Targets: map[string]*Target{
"development": { "development": {
Variables: map[string]any{ Variables: map[string]*TargetVariable{
"foo": variable.Variable{ "foo": {
Default: "bar", Default: "bar",
Description: "wrong", Description: "wrong",
}, },
"complex": variable.Variable{ "complex": {
Type: "wrong", Type: "wrong",
Description: "wrong", Description: "wrong",
Default: map[string]interface{}{ Default: map[string]interface{}{

View File

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

View File

@ -21,6 +21,19 @@ func addInterpolationPatterns(typ reflect.Type, s jsonschema.Schema) jsonschema.
return s 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 { switch s.Type {
case jsonschema.ArrayType, jsonschema.ObjectType: case jsonschema.ArrayType, jsonschema.ObjectType:
// arrays and objects can have complex variable values specified. // arrays and objects can have complex variable values specified.

View File

@ -995,7 +995,7 @@
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Sync" "$ref": "#/$defs/github.com/databricks/cli/bundle/config.Sync"
}, },
"variables": { "variables": {
"$ref": "#/$defs/map/interface" "$ref": "#/$defs/map/github.com/databricks/cli/bundle/config.TargetVariable"
}, },
"workspace": { "workspace": {
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.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": { "config.Workspace": {
"anyOf": [ "anyOf": [
{ {
@ -5049,25 +5083,25 @@
"pattern": "\\$\\{(var(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)+)\\}" "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": { "string": {
"anyOf": [ "anyOf": [
{ {