Skip to content

Commit 0ea2dd3

Browse files
denikclaude
andauthored
Make bundle.engine setting higher priority than DATABRICKS_BUNDLE_ENGINE (#4782)
## Changes - Final priority: existing state > bundle.engine > DATABRICKS_BUNDLE_ENGINE - Simplify API, merge SettingFromEnv into ResolveEngineSetting ## Why This makes it possible to use env var as a default but let users opt our per-bundle or per-target level via config setting. --------- Co-authored-by: Claude Sonnet 4.6 <[email protected]>
1 parent ed6f73f commit 0ea2dd3

File tree

13 files changed

+98
-82
lines changed

13 files changed

+98
-82
lines changed

acceptance/bundle/state/bad_env/output.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,3 @@ Error: unexpected setting for DATABRICKS_BUNDLE_ENGINE="abc" (expected 'terrafor
1010

1111
>>> musterr [CLI] bundle destroy --auto-approve
1212
Error: unexpected setting for DATABRICKS_BUNDLE_ENGINE="abc" (expected 'terraform' or 'direct')
13-
14-
>>> musterr [CLI] bundle validate
15-
Error: unexpected setting for DATABRICKS_BUNDLE_ENGINE="abc" (expected 'terraform' or 'direct')
16-
17-
Found 1 error

acceptance/bundle/state/bad_env/script

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ trace musterr $CLI bundle plan
33
trace musterr $CLI bundle deploy
44
trace musterr $CLI bundle summary
55
trace musterr $CLI bundle destroy --auto-approve
6-
trace musterr $CLI bundle validate

acceptance/bundle/state/engine_mismatch/output.txt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,12 @@ Available state files:
99

1010
[TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate: local terraform state serial=1 lineage="test-lineage"
1111

12-
=== Env var confirms config, both mismatch state: warning expected
12+
=== Invalid env var with config set: no error, config takes priority
1313

14-
>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle debug states
15-
Warning: Deployment engine "direct" configured in DATABRICKS_BUNDLE_ENGINE environment variable does not match the existing state (engine "terraform"). Using "terraform" engine from the existing state.
14+
>>> DATABRICKS_BUNDLE_ENGINE=bla [CLI] bundle debug states
15+
Warning: Deployment engine "direct" configured in bundle.engine setting at [TEST_TMP_DIR]/databricks.yml:3:11 does not match the existing state (engine "terraform"). Using "terraform" engine from the existing state.
1616

1717
Available state files:
1818
- [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate: local terraform state serial=1 lineage="test-lineage"
1919

2020
[TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate: local terraform state serial=1 lineage="test-lineage"
21-
22-
=== Env var overrides config to match state: no warning expected
23-
24-
>>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle debug states
25-
[TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate: local terraform state serial=1 lineage="test-lineage"
26-
27-
=== Invalid env var: error expected
28-
29-
>>> musterr [CLI] bundle debug states
30-
Error: unexpected setting for DATABRICKS_BUNDLE_ENGINE="bla" (expected 'terraform' or 'direct')

acceptance/bundle/state/engine_mismatch/script

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,5 @@ title 'Config mismatch with state: warning expected\n'
55
unset DATABRICKS_BUNDLE_ENGINE
66
trace $CLI bundle debug states
77

8-
title 'Env var confirms config, both mismatch state: warning expected\n'
9-
trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle debug states
10-
11-
title 'Env var overrides config to match state: no warning expected\n'
12-
trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle debug states
13-
14-
title 'Invalid env var: error expected\n'
15-
export DATABRICKS_BUNDLE_ENGINE=bla
16-
trace musterr $CLI bundle debug states
8+
title 'Invalid env var with config set: no error, config takes priority\n'
9+
trace DATABRICKS_BUNDLE_ENGINE=bla $CLI bundle debug states

bundle/config/engine/engine.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,11 @@ func FromEnv(ctx context.Context) (EngineType, error) {
4646

4747
// EngineSetting represents a requested engine type along with the source of the request.
4848
type EngineSetting struct {
49-
Type EngineType // effective: env var if set, else config
49+
Type EngineType // effective resolved engine
5050
Source string // human-readable source of Type
5151
ConfigType EngineType // from bundle config (EngineNotSet if not configured)
5252
}
5353

54-
// SettingFromEnv returns an EngineSetting from the environment variable.
55-
// ConfigType is left as EngineNotSet and populated later by ResolveEngineSetting.
56-
func SettingFromEnv(ctx context.Context) (EngineSetting, error) {
57-
e, err := FromEnv(ctx)
58-
if err != nil {
59-
return EngineSetting{}, err
60-
}
61-
return EngineSetting{Type: e, Source: EnvVar + " environment variable"}, nil
62-
}
63-
6454
func (e EngineType) ThisOrDefault() EngineType {
6555
if e == EngineNotSet {
6656
return Default

bundle/config/engine/engine_test.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,21 @@ import (
88
"github.com/stretchr/testify/require"
99
)
1010

11-
func TestSettingFromEnv(t *testing.T) {
12-
ctx := t.Context()
13-
ctx = env.Set(ctx, EnvVar, "direct")
14-
req, err := SettingFromEnv(ctx)
11+
func TestFromEnv(t *testing.T) {
12+
ctx := env.Set(t.Context(), EnvVar, "direct")
13+
e, err := FromEnv(ctx)
1514
require.NoError(t, err)
16-
assert.Equal(t, EngineDirect, req.Type)
17-
assert.Contains(t, req.Source, EnvVar)
15+
assert.Equal(t, EngineDirect, e)
1816
}
1917

20-
func TestSettingFromEnvNotSet(t *testing.T) {
21-
req, err := SettingFromEnv(t.Context())
18+
func TestFromEnvNotSet(t *testing.T) {
19+
e, err := FromEnv(t.Context())
2220
require.NoError(t, err)
23-
assert.Equal(t, EngineNotSet, req.Type)
21+
assert.Equal(t, EngineNotSet, e)
2422
}
2523

26-
func TestSettingFromEnvInvalid(t *testing.T) {
24+
func TestFromEnvInvalid(t *testing.T) {
2725
ctx := env.Set(t.Context(), EnvVar, "invalid")
28-
_, err := SettingFromEnv(ctx)
26+
_, err := FromEnv(ctx)
2927
assert.Error(t, err)
3028
}

bundle/internal/schema/annotations.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ github.com/databricks/cli/bundle/config.Bundle:
4444
The definition of the bundle deployment. For supported attributes see [\_](/dev-tools/bundles/deployment-modes.md).
4545
"engine":
4646
"description": |-
47-
The deployment engine to use. Valid values are `terraform` and `direct`. Can be overridden with the `DATABRICKS_BUNDLE_ENGINE` environment variable.
47+
The deployment engine to use. Valid values are `terraform` and `direct`. Takes priority over `DATABRICKS_BUNDLE_ENGINE` environment variable. Default is "terraform".
4848
"git":
4949
"description": |-
5050
The Git version control details that are associated with your bundle.

bundle/schema/jsonschema.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/schema/jsonschema_for_docs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,7 @@
21512151
"x-since-version": "v0.229.0"
21522152
},
21532153
"engine": {
2154-
"description": "The deployment engine to use. Valid values are `terraform` and `direct`. Can be overridden with the `DATABRICKS_BUNDLE_ENGINE` environment variable.",
2154+
"description": "The deployment engine to use. Valid values are `terraform` and `direct`. Takes priority over `DATABRICKS_BUNDLE_ENGINE` environment variable. Default is \"terraform\".",
21552155
"$ref": "#/$defs/github.com/databricks/cli/bundle/config/engine.EngineType"
21562156
},
21572157
"git": {

cmd/bundle/generate/dashboard.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"time"
1515

1616
"github.com/databricks/cli/bundle"
17-
"github.com/databricks/cli/bundle/config/engine"
1817
"github.com/databricks/cli/bundle/generate"
1918
"github.com/databricks/cli/bundle/phases"
2019
"github.com/databricks/cli/bundle/resources"
@@ -374,18 +373,16 @@ func (d *dashboard) initialize(ctx context.Context, b *bundle.Bundle) {
374373
}
375374

376375
func (d *dashboard) runForResource(ctx context.Context, b *bundle.Bundle) {
377-
envEngine, err := engine.SettingFromEnv(ctx)
378-
if err != nil {
379-
logdiag.LogError(ctx, err)
380-
return
381-
}
382-
383376
phases.Initialize(ctx, b)
384377
if logdiag.HasError(ctx) {
385378
return
386379
}
387380

388-
requiredEngine := utils.ResolveEngineSetting(b, envEngine)
381+
requiredEngine, err := utils.ResolveEngineSetting(ctx, b)
382+
if err != nil {
383+
logdiag.LogError(ctx, err)
384+
return
385+
}
389386
ctx, stateDesc := statemgmt.PullResourcesState(ctx, b, statemgmt.AlwaysPull(true), requiredEngine)
390387
if logdiag.HasError(ctx) {
391388
return

0 commit comments

Comments
 (0)