Skip to content
Draft
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
20 changes: 15 additions & 5 deletions bundle/config/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
type EngineType string

const (
EngineDirect EngineType = "direct"
EngineTerraform EngineType = "terraform"
EngineNotSet EngineType = ""
EngineDirect EngineType = "direct"

Check failure on line 15 in bundle/config/engine/engine.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gofmt)
EngineDirectWithHistory EngineType = "direct_with_history"
EngineTerraform EngineType = "terraform"
EngineNotSet EngineType = ""
)

// Default is used for new bundles if user has not set the value
Expand All @@ -29,6 +30,8 @@
return EngineTerraform, true
case "direct":
return EngineDirect, true
case "direct_with_history":
return EngineDirectWithHistory, true
default:
return EngineNotSet, false
}
Expand All @@ -39,7 +42,7 @@
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
}
Expand All @@ -58,6 +61,13 @@
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
}
19 changes: 19 additions & 0 deletions bundle/direct_with_history.go
Original file line number Diff line number Diff line change
@@ -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()
}
60 changes: 60 additions & 0 deletions bundle/direct_with_history_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
7 changes: 6 additions & 1 deletion bundle/internal/schema/annotations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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": |-
Expand Down Expand Up @@ -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": |-
Expand Down
5 changes: 3 additions & 2 deletions bundle/schema/jsonschema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading