diff --git a/bundle/config/root_test.go b/bundle/config/root_test.go index b40a5f2b7b..a3934267be 100644 --- a/bundle/config/root_test.go +++ b/bundle/config/root_test.go @@ -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{}{ diff --git a/bundle/config/target.go b/bundle/config/target.go index 4b20fac15b..718dd3acb7 100644 --- a/bundle/config/target.go +++ b/bundle/config/target.go @@ -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"` diff --git a/bundle/internal/schema/main.go b/bundle/internal/schema/main.go index 3c1fb5da05..51eb1e2668 100644 --- a/bundle/internal/schema/main.go +++ b/bundle/internal/schema/main.go @@ -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. diff --git a/bundle/schema/jsonschema.json b/bundle/schema/jsonschema.json index 6de293648e..95edbae180 100644 --- a/bundle/schema/jsonschema.json +++ b/bundle/schema/jsonschema.json @@ -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": [ {