diff --git a/bundle/config/engine/engine.go b/bundle/config/engine/engine.go index c2c251e8f9b..70eb852d831 100644 --- a/bundle/config/engine/engine.go +++ b/bundle/config/engine/engine.go @@ -12,9 +12,10 @@ const EnvVar = "DATABRICKS_BUNDLE_ENGINE" type EngineType string const ( - EngineDirect EngineType = "direct" - EngineTerraform EngineType = "terraform" - EngineNotSet EngineType = "" + EngineDirect EngineType = "direct" + EngineDirectWithHistory EngineType = "direct_with_history" + EngineTerraform EngineType = "terraform" + EngineNotSet EngineType = "" ) // Default is used for new bundles if user has not set the value @@ -29,6 +30,8 @@ func Parse(engine string) (EngineType, bool) { return EngineTerraform, true case "direct": return EngineDirect, true + case "direct_with_history": + return EngineDirectWithHistory, true default: return EngineNotSet, false } @@ -39,7 +42,7 @@ func FromEnv(ctx context.Context) (EngineType, error) { value := env.Get(ctx, EnvVar) engine, ok := Parse(value) if !ok { - return EngineNotSet, fmt.Errorf("unexpected setting for %s=%#v (expected 'terraform' or 'direct')", EnvVar, value) + return EngineNotSet, fmt.Errorf("unexpected setting for %s=%#v (expected 'terraform', 'direct', or 'direct_with_history')", EnvVar, value) } return engine, nil } @@ -58,6 +61,13 @@ func (e EngineType) ThisOrDefault() EngineType { return e } +// IsDirect reports whether the engine is a direct engine (with or without history). func (e EngineType) IsDirect() bool { - return e.ThisOrDefault() == EngineDirect + t := e.ThisOrDefault() + return t == EngineDirect || t == EngineDirectWithHistory +} + +// IsDirectWithHistory reports whether the engine is direct with deployment history enabled. +func (e EngineType) IsDirectWithHistory() bool { + return e.ThisOrDefault() == EngineDirectWithHistory } diff --git a/bundle/direct_with_history.go b/bundle/direct_with_history.go new file mode 100644 index 00000000000..a708183a69b --- /dev/null +++ b/bundle/direct_with_history.go @@ -0,0 +1,19 @@ +package bundle + +import ( + "context" + + "github.com/databricks/cli/bundle/config/engine" +) + +// IsDirectWithHistory reports whether the bundle uses the direct engine with +// deployment history enabled (engine: direct_with_history). +// Configuration takes priority over the DATABRICKS_BUNDLE_ENGINE environment variable. +func IsDirectWithHistory(ctx context.Context, b *Bundle) bool { + engineType := b.Config.Bundle.Engine + if engineType == engine.EngineNotSet { + envEngine, _ := engine.FromEnv(ctx) + engineType = envEngine + } + return engineType.IsDirectWithHistory() +} diff --git a/bundle/direct_with_history_test.go b/bundle/direct_with_history_test.go new file mode 100644 index 00000000000..448e91b4b3f --- /dev/null +++ b/bundle/direct_with_history_test.go @@ -0,0 +1,60 @@ +package bundle_test + +import ( + "testing" + + "github.com/databricks/cli/bundle" + "github.com/databricks/cli/bundle/config" + "github.com/databricks/cli/bundle/config/engine" + "github.com/databricks/cli/internal/testutil" + "github.com/stretchr/testify/assert" +) + +func TestIsDirectWithHistoryEnvVar(t *testing.T) { + testutil.CleanupEnvironment(t) + t.Setenv("DATABRICKS_BUNDLE_ENGINE", "direct_with_history") + b := &bundle.Bundle{} + assert.True(t, bundle.IsDirectWithHistory(t.Context(), b)) +} + +func TestIsDirectWithHistoryOtherEngines(t *testing.T) { + for _, v := range []string{"direct", "terraform", ""} { + t.Run(v, func(t *testing.T) { + testutil.CleanupEnvironment(t) + t.Setenv("DATABRICKS_BUNDLE_ENGINE", v) + b := &bundle.Bundle{} + assert.False(t, bundle.IsDirectWithHistory(t.Context(), b)) + }) + } +} + +func TestIsDirectWithHistoryConfig(t *testing.T) { + testutil.CleanupEnvironment(t) + b := &bundle.Bundle{ + Config: config.Root{ + Bundle: config.Bundle{ + Engine: engine.EngineDirectWithHistory, + }, + }, + } + assert.True(t, bundle.IsDirectWithHistory(t.Context(), b)) +} + +func TestIsDirectWithHistoryConfigTakesPriority(t *testing.T) { + testutil.CleanupEnvironment(t) + t.Setenv("DATABRICKS_BUNDLE_ENGINE", "direct_with_history") + b := &bundle.Bundle{ + Config: config.Root{ + Bundle: config.Bundle{ + Engine: engine.EngineDirect, + }, + }, + } + assert.False(t, bundle.IsDirectWithHistory(t.Context(), b)) +} + +func TestIsDirectWithHistoryUnset(t *testing.T) { + testutil.CleanupEnvironment(t) + b := &bundle.Bundle{} + assert.False(t, bundle.IsDirectWithHistory(t.Context(), b)) +} diff --git a/bundle/internal/schema/annotations.yml b/bundle/internal/schema/annotations.yml index 6a1070ddcd4..933ed9342ac 100644 --- a/bundle/internal/schema/annotations.yml +++ b/bundle/internal/schema/annotations.yml @@ -44,7 +44,7 @@ github.com/databricks/cli/bundle/config.Bundle: The definition of the bundle deployment. For supported attributes see [\_](/dev-tools/bundles/deployment-modes.md). "engine": "description": |- - The deployment engine to use. Valid values are `terraform` and `direct`. Takes priority over `DATABRICKS_BUNDLE_ENGINE` environment variable. Default is "terraform". + The deployment engine to use. Valid values are `terraform`, `direct`, and `direct_with_history`. Takes priority over `DATABRICKS_BUNDLE_ENGINE` environment variable. Default is "terraform". "git": "description": |- The Git version control details that are associated with your bundle. @@ -63,6 +63,9 @@ github.com/databricks/cli/bundle/config.Deployment: "lock": "description": |- The deployment lock attributes. + "managed_state": + "description": |- + PLACEHOLDER github.com/databricks/cli/bundle/config.Experimental: "pydabs": "description": |- @@ -491,6 +494,8 @@ github.com/databricks/cli/bundle/config/engine.EngineType: terraform - |- direct + - |- + direct_with_history github.com/databricks/cli/bundle/config/resources.Alert: "create_time": "description": |- diff --git a/bundle/schema/jsonschema.json b/bundle/schema/jsonschema.json index c2026fc43bc..afc68033eb3 100644 --- a/bundle/schema/jsonschema.json +++ b/bundle/schema/jsonschema.json @@ -65,7 +65,8 @@ "type": "string", "enum": [ "terraform", - "direct" + "direct", + "direct_with_history" ] }, { @@ -2367,7 +2368,7 @@ "markdownDescription": "The definition of the bundle deployment. For supported attributes see [link](https://docs.databricks.com/dev-tools/bundles/deployment-modes.html)." }, "engine": { - "description": "The deployment engine to use. Valid values are `terraform` and `direct`. Takes priority over `DATABRICKS_BUNDLE_ENGINE` environment variable. Default is \"terraform\".", + "description": "The deployment engine to use. Valid values are `terraform`, `direct`, and `direct_with_history`. Takes priority over `DATABRICKS_BUNDLE_ENGINE` environment variable. Default is \"terraform\".", "$ref": "#/$defs/github.com/databricks/cli/bundle/config/engine.EngineType" }, "git": {