Skip to content
Merged
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
3 changes: 1 addition & 2 deletions acceptance/bundle/migrate/auto/default/databricks.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
bundle:
name: test-bundle
bundle: {name: test-bundle}

resources:
jobs:
Expand Down
45 changes: 45 additions & 0 deletions acceptance/bundle/migrate/auto/default/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,51 @@
=== Replay a prior terraform deployment
>>> replay_tfstate.py terraform-requests.json terraform.tfstate

=== Summary works with engine: terraform and shows the deployed job's ID and URL
>>> update_file.py databricks.yml {name: test-bundle} {name: test-bundle, engine: terraform}

>>> [CLI] bundle summary
Warning: the Terraform deployment engine has been removed in Databricks CLI v1.20.0
in databricks.yml:1:37

Remove the "bundle.engine" setting (or set it to "direct") to deploy with the direct engine; existing Terraform state is migrated automatically. To keep using Terraform, revert to Databricks CLI v1.19.x.
See https://docs.databricks.com/dev-tools/bundles/direct for details

Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765).
Name: test-bundle
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
Resources:
Jobs:
test_job:
Name: Test Auto-Migrate Job
URL: [DATABRICKS_URL]/jobs/[TEST_JOB_ID]?w=[NUMID]

>>> [CLI] bundle summary -o json
Warning: the Terraform deployment engine has been removed in Databricks CLI v1.20.0
in databricks.yml:1:37

Remove the "bundle.engine" setting (or set it to "direct") to deploy with the direct engine; existing Terraform state is migrated automatically. To keep using Terraform, revert to Databricks CLI v1.19.x.
See https://docs.databricks.com/dev-tools/bundles/direct for details

Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765).
{
"engine": "terraform",
"id": "[TEST_JOB_ID]",
"url": "[DATABRICKS_URL]/jobs/[TEST_JOB_ID]?w=[NUMID]"
}

=== Summary does not migrate: no state writes, terraform state is left untouched

>>> print_requests.py

>>> find.py \.databricks/.*(\.tfstate|resources.*\.json|\.wal)
.databricks/bundle/default/terraform/terraform.tfstate

>>> update_file.py databricks.yml {name: test-bundle, engine: terraform} {name: test-bundle}

=== Redeploy with nothing set: direct is the default, so auto-migration triggers
>>> [CLI] bundle deploy
Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765).
Expand Down
12 changes: 12 additions & 0 deletions acceptance/bundle/migrate/auto/default/script
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ export DATABRICKS_BUNDLE_ENGINE=
# must not deploy with terraform.
title "Replay a prior terraform deployment"
trace replay_tfstate.py terraform-requests.json terraform.tfstate
replace_ids.py
rm -f "$OUT_REQUESTS"

# Set after the replay: replay_tfstate.py runs bundle validate, which rejects engine: terraform.
title "Summary works with engine: terraform and shows the deployed job's ID and URL"
trace update_file.py databricks.yml "{name: test-bundle}" "{name: test-bundle, engine: terraform}"
trace $CLI bundle summary
trace $CLI bundle summary -o json | jq '{engine: .bundle.engine, id: .resources.jobs.test_job.id, url: .resources.jobs.test_job.url}'

title "Summary does not migrate: no state writes, terraform state is left untouched\n"
trace print_requests.py
trace find.py '\.databricks/.*(\.tfstate|resources.*\.json|\.wal)'
trace update_file.py databricks.yml "{name: test-bundle, engine: terraform}" "{name: test-bundle}"

title "Redeploy with nothing set: direct is the default, so auto-migration triggers"
trace $CLI bundle deploy
trace print_migration_telemetry
Expand Down
13 changes: 11 additions & 2 deletions acceptance/bundle/state/bad_env/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ Error: unexpected setting for DATABRICKS_BUNDLE_ENGINE="abc" (expected 'direct')
>>> musterr [CLI] bundle deploy
Error: unexpected setting for DATABRICKS_BUNDLE_ENGINE="abc" (expected 'direct')

>>> musterr [CLI] bundle summary
Error: unexpected setting for DATABRICKS_BUNDLE_ENGINE="abc" (expected 'direct')
>>> [CLI] bundle summary
Name: test-bundle
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
Resources:
Schemas:
foo:
Name: foo
URL: (not deployed)

>>> musterr [CLI] bundle destroy --auto-approve
Error: unexpected setting for DATABRICKS_BUNDLE_ENGINE="abc" (expected 'direct')
3 changes: 2 additions & 1 deletion acceptance/bundle/state/bad_env/script
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export DATABRICKS_BUNDLE_ENGINE=abc
trace musterr $CLI bundle plan
trace musterr $CLI bundle deploy
trace musterr $CLI bundle summary
# summary does not check DATABRICKS_BUNDLE_ENGINE
trace $CLI bundle summary
trace musterr $CLI bundle destroy --auto-approve
8 changes: 8 additions & 0 deletions acceptance/bundle/summary/engine-terraform/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bundle:
name: test-bundle
engine: terraform

resources:
jobs:
my_job:
name: my job
2 changes: 2 additions & 0 deletions acceptance/bundle/summary/engine-terraform/out.test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DMS = ["", "true"]
90 changes: 90 additions & 0 deletions acceptance/bundle/summary/engine-terraform/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

>>> [CLI] bundle summary
Warning: the Terraform deployment engine has been removed in Databricks CLI v1.20.0
in databricks.yml:3:11

Remove the "bundle.engine" setting (or set it to "direct") to deploy with the direct engine; existing Terraform state is migrated automatically. To keep using Terraform, revert to Databricks CLI v1.19.x.
See https://docs.databricks.com/dev-tools/bundles/direct for details

Name: test-bundle
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
Resources:
Jobs:
my_job:
Name: my job
URL: (not deployed)

>>> [CLI] bundle summary -o json
Warning: the Terraform deployment engine has been removed in Databricks CLI v1.20.0
in databricks.yml:3:11

Remove the "bundle.engine" setting (or set it to "direct") to deploy with the direct engine; existing Terraform state is migrated automatically. To keep using Terraform, revert to Databricks CLI v1.19.x.
See https://docs.databricks.com/dev-tools/bundles/direct for details

"terraform"

>>> musterr [CLI] bundle validate
Error: the Terraform deployment engine has been removed in Databricks CLI v1.20.0
in databricks.yml:3:11

Remove the "bundle.engine" setting (or set it to "direct") to deploy with the direct engine; existing Terraform state is migrated automatically. To keep using Terraform, revert to Databricks CLI v1.19.x.
See https://docs.databricks.com/dev-tools/bundles/direct for details

Name: test-bundle
Target: default

Found 1 error

>>> musterr [CLI] bundle validate -o json
Error: the Terraform deployment engine has been removed in Databricks CLI v1.20.0
in databricks.yml:3:11

Remove the "bundle.engine" setting (or set it to "direct") to deploy with the direct engine; existing Terraform state is migrated automatically. To keep using Terraform, revert to Databricks CLI v1.19.x.
See https://docs.databricks.com/dev-tools/bundles/direct for details

{
"engine": "terraform",
"environment": "default",
"name": "test-bundle",
"target": "default"
}

>>> update_file.py databricks.yml engine: terraform

>>> [CLI] bundle summary
Name: test-bundle
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
Resources:
Jobs:
my_job:
Name: my job
URL: (not deployed)

>>> musterr [CLI] bundle validate
Error: the Terraform deployment engine has been removed in Databricks CLI v1.20.0

Unset the DATABRICKS_BUNDLE_ENGINE environment variable (or set it to "direct") to deploy with the direct engine; existing Terraform state is migrated automatically. To keep using Terraform, revert to Databricks CLI v1.19.x.
See https://docs.databricks.com/dev-tools/bundles/direct for details

Name: test-bundle
Target: default

Found 1 error

>>> musterr [CLI] bundle validate -o json
Error: the Terraform deployment engine has been removed in Databricks CLI v1.20.0

Unset the DATABRICKS_BUNDLE_ENGINE environment variable (or set it to "direct") to deploy with the direct engine; existing Terraform state is migrated automatically. To keep using Terraform, revert to Databricks CLI v1.19.x.
See https://docs.databricks.com/dev-tools/bundles/direct for details

{
"environment": "default",
"name": "test-bundle",
"target": "default"
}
11 changes: 11 additions & 0 deletions acceptance/bundle/summary/engine-terraform/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
trace $CLI bundle summary
trace $CLI bundle summary -o json | jq .bundle.engine
# Other commands still reject engine: terraform.
trace musterr $CLI bundle validate
trace musterr $CLI bundle validate -o json | jq .bundle

# The env var is not checked by summary (bundle.engine is removed first, since it takes priority over the env var).
trace update_file.py databricks.yml " engine: terraform" ""
DATABRICKS_BUNDLE_ENGINE=terraform trace $CLI bundle summary
DATABRICKS_BUNDLE_ENGINE=terraform trace musterr $CLI bundle validate
DATABRICKS_BUNDLE_ENGINE=terraform trace musterr $CLI bundle validate -o json | jq .bundle
5 changes: 5 additions & 0 deletions bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ type Bundle struct {
// leave the terraform state untouched.
MigratingToDirect bool

// AllowTerraformEngineConfig reports a terraform bundle.engine as a warning instead
// of an error and skips the DATABRICKS_BUNDLE_ENGINE check. Set by read-only commands
// (bundle summary) so users can still inspect a bundle that pins the removed engine.
AllowTerraformEngineConfig bool

// Quiet is the output verbosity reduction requested via -q/--quiet, which is
// repeatable: QuietSummary drops the per-resource lines, QuietAll additionally
// drops the summary and progress lines, leaving warnings and errors.
Expand Down
6 changes: 5 additions & 1 deletion bundle/config/validate/validate_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ func (v *validateEngine) Apply(_ context.Context, b *bundle.Bundle) diag.Diagnos
}

if parsed == engine.EngineTerraform {
severity := diag.Error
if b.AllowTerraformEngineConfig {
severity = diag.Warning
}
return diags.Append(diag.Diagnostic{
Severity: diag.Error,
Severity: severity,
Summary: engine.TerraformRemovedSummary,
Detail: engine.TerraformRemovedConfigDetail,
Locations: []dyn.Location{loc},
Expand Down
16 changes: 16 additions & 0 deletions bundle/config/validate/validate_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,19 @@ func TestValidateEngineTerraformConfigDeprecated(t *testing.T) {
assert.Contains(t, diags[0].Summary, "bundle.terraform is deprecated")
assert.Equal(t, []dyn.Location{loc}, diags[0].Locations)
}

func TestValidateEngineTerraformAllowed(t *testing.T) {
b := &bundle.Bundle{
Config: config.Root{
Bundle: config.Bundle{
Engine: engine.EngineTerraform,
},
},
AllowTerraformEngineConfig: true,
}
bundletest.SetLocation(b, "bundle.engine", []dyn.Location{{File: "databricks.yml", Line: 5, Column: 3}})
diags := ValidateEngine().Apply(t.Context(), b)
assert.Len(t, diags, 1)
assert.Equal(t, diag.Warning, diags[0].Severity)
assert.Contains(t, diags[0].Summary, "has been removed")
}
4 changes: 4 additions & 0 deletions cmd/bundle/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Useful after deployment to see what was created and where to find it.`,
AlwaysPull: forcePull,
IncludeLocations: includeLocations,
InitIDs: true,
// Let users inspect a bundle that pins the removed Terraform engine.
InitFunc: func(b *bundle.Bundle) {
b.AllowTerraformEngineConfig = true
},
})
if err != nil {
return err
Expand Down
6 changes: 5 additions & 1 deletion cmd/bundle/utils/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,16 @@ func ValidateEngineSetting(ctx context.Context, b *bundle.Bundle) error {
if !ok {
return fmt.Errorf("invalid value %q for bundle.engine (expected %q)", configEngine, engine.EngineDirect)
}
if parsed == engine.EngineTerraform {
if parsed == engine.EngineTerraform && !b.AllowTerraformEngineConfig {
return errors.New(engine.TerraformRemovedConfigMessage)
}
return nil
}

if b.AllowTerraformEngineConfig {
return nil
}

envEngine, err := engine.FromEnv(ctx)
if err != nil {
return err
Expand Down
Loading