From 042a6e99fdde2d3fad4c008128d03045a0f1a96c Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 28 Sep 2026 17:28:14 +0200 Subject: [PATCH 01/15] acceptance: seed migrate tests from a terraform-state fixture The migrate tests deployed with the terraform engine to produce a terraform state, then migrated it to direct. Replace that live terraform deploy with a checked-in terraform.tfstate fixture: seed_tfstate.py deploys the bundle on the direct engine to create backend resources that match config (so the migrated state's first plan is a no-op), threads their ids into the fixture, and drops the direct state so the bundle resolves to the terraform engine again; the next deploy migrates it. The terraform engine is still present on this branch, so migration behavior is unchanged: a failed plan check still falls back to terraform (auto/plan-failure), and engine: terraform is still a deprecation warning (command/engine-config-terraform). Removing the engine, and adapting these two tests, is a later PR. Co-authored-by: Isaac --- acceptance/bin/seed_tfstate.py | 114 +++++ .../migrate/auto/apply-failure/output.txt | 10 +- .../bundle/migrate/auto/apply-failure/script | 4 +- .../auto/apply-failure/terraform.tfstate | 17 + .../bundle/migrate/auto/artifacts/output.txt | 11 +- .../bundle/migrate/auto/artifacts/script | 9 +- .../migrate/auto/artifacts/terraform.tfstate | 23 + ...pdate.direct.json => out.plan_update.json} | 0 .../bundle/migrate/auto/clean/output.txt | 14 +- acceptance/bundle/migrate/auto/clean/script | 20 +- .../migrate/auto/clean/terraform.tfstate | 23 + .../bundle/migrate/auto/default/output.txt | 12 +- acceptance/bundle/migrate/auto/default/script | 9 +- .../migrate/auto/default/terraform.tfstate | 23 + .../bundle/migrate/auto/delete-all/output.txt | 8 +- .../bundle/migrate/auto/delete-all/script | 7 +- .../migrate/auto/delete-all/terraform.tfstate | 23 + .../bundle/migrate/auto/delete/output.txt | 9 +- acceptance/bundle/migrate/auto/delete/script | 7 +- .../migrate/auto/delete/terraform.tfstate | 38 ++ .../bundle/migrate/auto/destroy/output.txt | 9 +- acceptance/bundle/migrate/auto/destroy/script | 7 +- .../migrate/auto/destroy/terraform.tfstate | 23 + .../auto/direct-only-envvar/output.txt | 8 +- .../migrate/auto/direct-only-envvar/script | 7 +- .../auto/direct-only-envvar/terraform.tfstate | 23 + .../migrate/auto/direct-only/output.txt | 9 +- .../bundle/migrate/auto/direct-only/script | 7 +- .../auto/direct-only/terraform.tfstate | 23 + .../migrate/auto/dms-migration/output.txt | 9 +- .../bundle/migrate/auto/dms-migration/script | 4 +- .../auto/dms-migration/terraform.tfstate | 17 + .../bundle/migrate/auto/envvar/output.txt | 12 +- acceptance/bundle/migrate/auto/envvar/script | 8 +- .../migrate/auto/envvar/terraform.tfstate | 23 + .../auto/pipeline-storage-change/output.txt | 8 +- .../auto/pipeline-storage-change/script | 5 +- .../terraform.tfstate.tmpl | 22 + .../migrate/auto/plan-failure/output.txt | 16 +- .../bundle/migrate/auto/plan-failure/script | 16 +- .../auto/plan-failure/terraform.tfstate | 17 + .../migrate/auto/plan-missing/output.txt | 24 +- .../bundle/migrate/auto/plan-missing/script | 14 +- .../auto/plan-missing/terraform.tfstate | 17 + .../migrate/auto/push-failure/output.txt | 14 +- .../bundle/migrate/auto/push-failure/script | 7 +- .../auto/push-failure/terraform.tfstate | 17 + .../output.txt | 8 +- .../registered-model-catalog-change/script | 4 +- .../terraform.tfstate | 22 + .../auto/registered-model-rename/output.txt | 9 +- .../auto/registered-model-rename/script | 5 +- .../terraform.tfstate.tmpl | 36 ++ .../migrate/auto/run-no-commit/output.txt | 9 +- .../bundle/migrate/auto/run-no-commit/script | 7 +- .../auto/run-no-commit/terraform.tfstate | 23 + .../auto/schema-catalog-change/output.txt | 8 +- .../migrate/auto/schema-catalog-change/script | 4 +- .../schema-catalog-change/terraform.tfstate | 21 + .../auto/schema-name-normalized/output.txt | 8 +- .../auto/schema-name-normalized/script | 8 +- .../terraform.tfstate.tmpl | 22 + .../migrate/auto/schema-rename/output.txt | 8 +- .../bundle/migrate/auto/schema-rename/script | 5 +- .../auto/schema-rename/terraform.tfstate.tmpl | 22 + .../auto/schema-storage-change/output.txt | 13 +- .../migrate/auto/schema-storage-change/script | 5 +- .../schema-storage-change/terraform.tfstate | 23 + .../auto/schema-storage-normalized/output.txt | 8 +- .../auto/schema-storage-normalized/script | 4 +- .../terraform.tfstate | 23 + .../migrate/auto/tfbackup-failure/output.txt | 12 +- .../migrate/auto/tfbackup-failure/script | 20 +- .../auto/tfbackup-failure/terraform.tfstate | 17 + .../auto/volume-name-normalized/output.txt | 8 +- .../auto/volume-name-normalized/script | 8 +- .../terraform.tfstate.tmpl | 24 + .../migrate/auto/volume-rename/output.txt | 9 +- .../bundle/migrate/auto/volume-rename/script | 5 +- .../auto/volume-rename/terraform.tfstate.tmpl | 37 ++ .../auto/volume-type-change/output.txt | 8 +- .../migrate/auto/volume-type-change/script | 4 +- .../auto/volume-type-change/terraform.tfstate | 24 + .../command/added-direct-only/output.txt | 25 +- .../migrate/command/added-direct-only/script | 19 +- .../added-direct-only/terraform.tfstate | 17 + .../bundle/migrate/command/added/output.txt | 12 +- .../bundle/migrate/command/added/script | 14 +- .../migrate/command/added/terraform.tfstate | 17 + .../migrate/command/basic/out.new_state.json | 2 +- .../command/basic/out.original_state.json | 274 +--------- .../command/basic/out.plan_update.json | 2 +- .../bundle/migrate/command/basic/output.txt | 83 +-- .../bundle/migrate/command/basic/script | 42 +- .../command/basic/terraform-prod.tfstate | 17 + .../migrate/command/basic/terraform.tfstate | 35 ++ .../command/dashboards/out.new_state.json | 2 +- .../dashboards/out.original_state.json | 33 +- .../dashboards/out.plan_after_migrate.json | 2 +- .../migrate/command/dashboards/output.txt | 42 +- .../bundle/migrate/command/dashboards/script | 33 +- .../command/dashboards/terraform.tfstate | 26 + .../default-python/out.state_original.json | 478 +----------------- .../migrate/command/default-python/output.txt | 47 +- .../migrate/command/default-python/script | 13 +- .../command/default-python/terraform.tfstate | 26 + .../command/grants/out.original_state.json | 241 +-------- .../bundle/migrate/command/grants/output.txt | 32 +- .../bundle/migrate/command/grants/script | 16 +- .../migrate/command/grants/terraform.tfstate | 62 +++ .../permissions/out.original_state.json | 363 +------------ .../migrate/command/permissions/output.txt | 24 +- .../bundle/migrate/command/permissions/script | 7 +- .../command/permissions/terraform.tfstate | 44 ++ .../migrate/command/profile_arg/output.txt | 15 +- .../bundle/migrate/command/profile_arg/script | 8 +- .../profile_arg/terraform-prod.tfstate | 17 + .../command/profile_arg/terraform.tfstate | 17 + .../bundle/migrate/command/removed/output.txt | 13 +- .../bundle/migrate/command/removed/script | 12 +- .../migrate/command/removed/terraform.tfstate | 26 + .../command/runas/out.create_requests.json | 4 +- .../migrate/command/runas/out.old_state.json | 154 +----- .../bundle/migrate/command/runas/output.txt | 60 +-- .../bundle/migrate/command/runas/script | 16 +- .../migrate/command/runas/terraform.tfstate | 26 + .../bundle/migrate/command/var_arg/output.txt | 20 +- .../bundle/migrate/command/var_arg/script | 20 +- .../migrate/command/var_arg/terraform.tfstate | 17 + 129 files changed, 1510 insertions(+), 2193 deletions(-) create mode 100755 acceptance/bin/seed_tfstate.py create mode 100644 acceptance/bundle/migrate/auto/apply-failure/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/artifacts/terraform.tfstate rename acceptance/bundle/migrate/auto/clean/{out.plan_update.direct.json => out.plan_update.json} (100%) create mode 100644 acceptance/bundle/migrate/auto/clean/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/default/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/delete-all/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/delete/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/destroy/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/direct-only-envvar/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/direct-only/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/dms-migration/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/envvar/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/pipeline-storage-change/terraform.tfstate.tmpl create mode 100644 acceptance/bundle/migrate/auto/plan-failure/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/plan-missing/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/push-failure/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/registered-model-catalog-change/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/registered-model-rename/terraform.tfstate.tmpl create mode 100644 acceptance/bundle/migrate/auto/run-no-commit/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/schema-catalog-change/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/schema-name-normalized/terraform.tfstate.tmpl create mode 100644 acceptance/bundle/migrate/auto/schema-rename/terraform.tfstate.tmpl create mode 100644 acceptance/bundle/migrate/auto/schema-storage-change/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/schema-storage-normalized/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/tfbackup-failure/terraform.tfstate create mode 100644 acceptance/bundle/migrate/auto/volume-name-normalized/terraform.tfstate.tmpl create mode 100644 acceptance/bundle/migrate/auto/volume-rename/terraform.tfstate.tmpl create mode 100644 acceptance/bundle/migrate/auto/volume-type-change/terraform.tfstate create mode 100644 acceptance/bundle/migrate/command/added-direct-only/terraform.tfstate create mode 100644 acceptance/bundle/migrate/command/added/terraform.tfstate create mode 100644 acceptance/bundle/migrate/command/basic/terraform-prod.tfstate create mode 100644 acceptance/bundle/migrate/command/basic/terraform.tfstate create mode 100644 acceptance/bundle/migrate/command/dashboards/terraform.tfstate create mode 100644 acceptance/bundle/migrate/command/default-python/terraform.tfstate create mode 100644 acceptance/bundle/migrate/command/grants/terraform.tfstate create mode 100644 acceptance/bundle/migrate/command/permissions/terraform.tfstate create mode 100644 acceptance/bundle/migrate/command/profile_arg/terraform-prod.tfstate create mode 100644 acceptance/bundle/migrate/command/profile_arg/terraform.tfstate create mode 100644 acceptance/bundle/migrate/command/removed/terraform.tfstate create mode 100644 acceptance/bundle/migrate/command/runas/terraform.tfstate create mode 100644 acceptance/bundle/migrate/command/var_arg/terraform.tfstate diff --git a/acceptance/bin/seed_tfstate.py b/acceptance/bin/seed_tfstate.py new file mode 100755 index 00000000000..1fd037eae12 --- /dev/null +++ b/acceptance/bin/seed_tfstate.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python3 +""" +Seed a terraform-state fixture for the auto-migration acceptance tests. + +The terraform deployment engine was removed, so these tests can no longer produce a +terraform state with a real `bundle deploy`. Instead each test checks in a +terraform.tfstate fixture (real terraform state shape) whose resource ids are +placeholder tokens "__ID___" (e.g. __ID_resources.jobs.test_job__). +This helper simulates "a prior terraform deployment of the same config": + + 1. deploys the bundle on the direct engine, which creates every resource on the + backend exactly as a deploy would (so the migrated state's first plan is a + no-op, not a spurious update), and records their real ids and resolved state; + 2. substitutes each real id/attribute into its placeholder in the fixture and writes + the result to .databricks/bundle//terraform/terraform.tfstate; and + 3. removes the direct state (local + remote) so the bundle looks like it is still + on the terraform engine. + +The next `bundle deploy` then reads the fixture and migrates it to the direct engine. + +Fixture placeholders (substituted after the direct deploy): + __ID___ the resource's backend id, e.g. __ID_resources.jobs.foo__ + __ATTR{}{}__ a resolved top-level state field (JSON-encoded), for a + computed value a fixture cannot hardcode, e.g. a volume's + __ATTR{resources.volumes.v}{storage_location}__. Write it + WITHOUT surrounding quotes; the JSON value is inserted. + +Any deploy args after the known ones (e.g. --var) are passed through to the seeding deploy, +so the created resources match the config the test migrates. + +Usage: seed_tfstate.py FIXTURE [-t TARGET] [-- DEPLOY_ARG...] +""" + +import argparse +import json +import os +import re +import subprocess +import sys + +sys.path.insert(0, os.path.dirname(__file__)) +from print_state import get_remote_state_path, get_state_file + +CLI = os.environ["CLI"] + + +def run_quiet(cmd): + """Run cmd, capturing its output so this setup step does not leak into the test's + output.txt. Fails loudly (with the captured output) on a non-zero exit.""" + result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8") + if result.returncode != 0: + sys.exit(f"seed_tfstate.py: {cmd} failed:\n{result.stdout}") + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("fixture") + parser.add_argument("-t", "--target") + # Remaining args (e.g. --var "x=y") are forwarded to the seeding deploy verbatim. + args, deploy_args = parser.parse_known_args() + + # Read the fixture and drop it from the bundle root before deploying, so the deploy + # does not sync it as a bundle file. + with open(args.fixture) as f: + raw = f.read() + os.remove(args.fixture) + + # Create the resources on the backend, matching config, via a direct deploy. + deploy = [CLI, "bundle", "deploy"] + if args.target: + deploy += ["-t", args.target] + deploy += deploy_args + run_quiet(deploy) + + # Substitute each resource's id and requested attributes from the direct state. + state_file = get_state_file(args.target, backup=False) + state = json.loads(open(state_file).read())["state"] + for key, entry in state.items(): + rid = entry.get("__id__") + if rid is not None: + raw = raw.replace(f"__ID_{key}__", str(rid)) + + def attr(match): + key, field = match.group(1), match.group(2) + entry = state.get(key) + if entry is None: + sys.exit(f"seed_tfstate.py: __ATTR of unknown resource {key!r}") + return json.dumps(entry.get("state", {}).get(field)) + + raw = re.sub(r"__ATTR\{([^}]+)\}\{([^}]+)\}__", attr, raw) + + if "__ID_" in raw or "__ATTR{" in raw: + sys.exit(f"seed_tfstate.py: unresolved placeholders remain in {args.fixture}:\n{raw}") + + # Write the terraform state where the migration reads it. + tf_path = os.path.join(os.path.dirname(state_file), "terraform", "terraform.tfstate") + os.makedirs(os.path.dirname(tf_path), exist_ok=True) + with open(tf_path, "w") as f: + f.write(raw) + + # Remove the direct state, local and remote, so the bundle resolves to the terraform + # engine again and the next deploy migrates. + for path in (state_file, state_file + ".wal"): + try: + os.remove(path) + except FileNotFoundError: + pass + remote_state = get_remote_state_path(args.target) + if remote_state: + run_quiet([CLI, "workspace", "delete", f"{remote_state}/resources.json"]) + + +if __name__ == "__main__": + main() diff --git a/acceptance/bundle/migrate/auto/apply-failure/output.txt b/acceptance/bundle/migrate/auto/apply-failure/output.txt index 8a3455d4d2b..e637d3baed7 100644 --- a/acceptance/bundle/migrate/auto/apply-failure/output.txt +++ b/acceptance/bundle/migrate/auto/apply-failure/output.txt @@ -1,10 +1,6 @@ -=== Initial deploy on terraform ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.test_job -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== Seed a terraform-state fixture from a prior terraform deployment +>>> seed_tfstate.py terraform.tfstate >>> update_file.py databricks.yml Test Auto-Migrate Apply Failure Test Auto-Migrate Apply Failure (updated) @@ -38,7 +34,6 @@ ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate.backup === Retry finishes the apply on the already-migrated direct state (no re-migration) >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy @@ -60,4 +55,3 @@ ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate.backup diff --git a/acceptance/bundle/migrate/auto/apply-failure/script b/acceptance/bundle/migrate/auto/apply-failure/script index 6e2d1159cf7..826424584f5 100644 --- a/acceptance/bundle/migrate/auto/apply-failure/script +++ b/acceptance/bundle/migrate/auto/apply-failure/script @@ -1,7 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +title "Seed a terraform-state fixture from a prior terraform deployment" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" # Change the job so the migrating deploy must update it (jobs/reset), giving us a resource apply diff --git a/acceptance/bundle/migrate/auto/apply-failure/terraform.tfstate b/acceptance/bundle/migrate/auto/apply-failure/terraform.tfstate new file mode 100644 index 00000000000..8ae8f1e819e --- /dev/null +++ b/acceptance/bundle/migrate/auto/apply-failure/terraform.tfstate @@ -0,0 +1,17 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Auto-Migrate Apply Failure"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/artifacts/output.txt b/acceptance/bundle/migrate/auto/artifacts/output.txt index c6c6d8516c2..766404a1884 100644 --- a/acceptance/bundle/migrate/auto/artifacts/output.txt +++ b/acceptance/bundle/migrate/auto/artifacts/output.txt @@ -1,12 +1,6 @@ -=== Initial deploy on terraform (expands the whl glob and uploads the wheel) ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Warn: unable to get spark version for cluster 0717-132531-5opeqon1, err: Not Found -Uploading dist/my_test_code-0.0.1-py3-none-any.whl... -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.test_job -Files: 2 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== Seed a terraform-state fixture from a prior terraform deployment +>>> seed_tfstate.py terraform.tfstate === Redeploy with direct default: auto-migration runs after the build, so library refs are resolved >>> [CLI] bundle deploy @@ -29,7 +23,6 @@ ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate.backup === Migrated state's library path (should be the resolved remote path, not the local glob) >>> print_state.py diff --git a/acceptance/bundle/migrate/auto/artifacts/script b/acceptance/bundle/migrate/auto/artifacts/script index bb8bfd89ef7..f9a3cad132b 100644 --- a/acceptance/bundle/migrate/auto/artifacts/script +++ b/acceptance/bundle/migrate/auto/artifacts/script @@ -1,7 +1,12 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform (expands the whl glob and uploads the wheel)" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +# The terraform engine was removed in v1.19.0, so seed the state from a fixture instead of a real +# terraform deploy. seed_tfstate.py deploys on direct (expanding the whl glob and uploading the +# wheel), threads the job id into the fixture, and drops the direct state so the bundle is on +# terraform again. +title "Seed a terraform-state fixture from a prior terraform deployment" +trace seed_tfstate.py terraform.tfstate +rm -f "$OUT_REQUESTS" title "Redeploy with direct default: auto-migration runs after the build, so library refs are resolved" trace $CLI bundle deploy diff --git a/acceptance/bundle/migrate/auto/artifacts/terraform.tfstate b/acceptance/bundle/migrate/auto/artifacts/terraform.tfstate new file mode 100644 index 00000000000..44ee38d3549 --- /dev/null +++ b/acceptance/bundle/migrate/auto/artifacts/terraform.tfstate @@ -0,0 +1,23 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "508c2a92-232f-53f8-996d-264492348b01", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "__ID_resources.jobs.test_job__", + "name": "Test Auto-Migrate Artifacts Job" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/clean/out.plan_update.direct.json b/acceptance/bundle/migrate/auto/clean/out.plan_update.json similarity index 100% rename from acceptance/bundle/migrate/auto/clean/out.plan_update.direct.json rename to acceptance/bundle/migrate/auto/clean/out.plan_update.json diff --git a/acceptance/bundle/migrate/auto/clean/output.txt b/acceptance/bundle/migrate/auto/clean/output.txt index 4fc49a9a7d3..1da8f711fe5 100644 --- a/acceptance/bundle/migrate/auto/clean/output.txt +++ b/acceptance/bundle/migrate/auto/clean/output.txt @@ -1,16 +1,8 @@ -=== Initial deploy uses terraform engine (no bundle.engine set, override via env var) ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.test_job -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged - ->>> print_migration_telemetry -direct_drymigrate_success true -direct_drymigrate_warnings false +=== Seed a terraform-state fixture from a prior terraform deployment +>>> seed_tfstate.py terraform.tfstate -=== Opt in to direct engine via config and redeploy: dry-run is clean, auto-migration triggers +=== Opt in to direct engine via config and redeploy: auto-migration triggers >>> update_file.py databricks.yml name: test-bundle name: test-bundle engine: direct diff --git a/acceptance/bundle/migrate/auto/clean/script b/acceptance/bundle/migrate/auto/clean/script index 29afd6c31cc..c3b88c0e53e 100644 --- a/acceptance/bundle/migrate/auto/clean/script +++ b/acceptance/bundle/migrate/auto/clean/script @@ -1,13 +1,17 @@ export DATABRICKS_BUNDLE_ENGINE= -# Each call to print_migration_telemetry inspects "$OUT_REQUESTS"; clear -# it after each call so the next deploy's telemetry stands alone. -title "Initial deploy uses terraform engine (no bundle.engine set, override via env var)" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy -trace print_migration_telemetry +# A prior terraform deployment left this bundle on the terraform engine. The terraform engine +# was removed in v1.19.0, so instead of a real terraform deploy, seed the state from a fixture: +# seed_tfstate.py deploys on direct to create matching backend resources, threads their ids into +# the checked-in terraform.tfstate, and drops the direct state so the bundle looks like a +# terraform deployment again. +title "Seed a terraform-state fixture from a prior terraform deployment" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" -title "Opt in to direct engine via config and redeploy: dry-run is clean, auto-migration triggers" +# Each call to print_migration_telemetry inspects "$OUT_REQUESTS"; clear +# it after each call so the next deploy's telemetry stands alone. +title "Opt in to direct engine via config and redeploy: auto-migration triggers" trace update_file.py databricks.yml "name: test-bundle" $'name: test-bundle\n engine: direct' trace $CLI bundle deploy trace print_migration_telemetry @@ -30,10 +34,10 @@ rm -f "$OUT_REQUESTS" title "Modify the config — plan shows the pending update" trace update_file.py databricks.yml "Test Auto-Migrate Job" "Test Auto-Migrate Job (renamed)" trace $CLI bundle plan -$CLI bundle plan -o json > out.plan_update.direct.json +$CLI bundle plan -o json > out.plan_update.json title "Deploy picks up the update (with and without --plan)\n" -$CLI bundle deploy $(readplanarg out.plan_update.direct.json) +$CLI bundle deploy $(readplanarg out.plan_update.json) trace print_migration_telemetry rm -f "$OUT_REQUESTS" diff --git a/acceptance/bundle/migrate/auto/clean/terraform.tfstate b/acceptance/bundle/migrate/auto/clean/terraform.tfstate new file mode 100644 index 00000000000..527aa742bd6 --- /dev/null +++ b/acceptance/bundle/migrate/auto/clean/terraform.tfstate @@ -0,0 +1,23 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "__ID_resources.jobs.test_job__", + "name": "Test Auto-Migrate Job" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/default/output.txt b/acceptance/bundle/migrate/auto/default/output.txt index b22d845e772..152a9bfc05d 100644 --- a/acceptance/bundle/migrate/auto/default/output.txt +++ b/acceptance/bundle/migrate/auto/default/output.txt @@ -1,14 +1,6 @@ -=== Initial deploy opts out of direct, so it uses the terraform engine ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.test_job -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged - ->>> print_migration_telemetry -direct_drymigrate_success true -direct_drymigrate_warnings false +=== Seed a terraform-state fixture from a prior terraform deployment +>>> seed_tfstate.py terraform.tfstate === Redeploy with nothing set: direct is the default, so auto-migration triggers >>> [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/default/script b/acceptance/bundle/migrate/auto/default/script index 07cb3903546..df531ba65f3 100644 --- a/acceptance/bundle/migrate/auto/default/script +++ b/acceptance/bundle/migrate/auto/default/script @@ -1,8 +1,11 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy opts out of direct, so it uses the terraform engine" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy -trace print_migration_telemetry +# A prior terraform deployment left this bundle on the terraform engine. The terraform engine was +# removed in v1.19.0, so seed its state from a fixture (seed_tfstate.py deploys on direct to create +# matching backend resources, threads their ids into the checked-in terraform.tfstate, and drops +# the direct state so the bundle resolves to terraform again) instead of a real terraform deploy. +title "Seed a terraform-state fixture from a prior terraform deployment" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" title "Redeploy with nothing set: direct is the default, so auto-migration triggers" diff --git a/acceptance/bundle/migrate/auto/default/terraform.tfstate b/acceptance/bundle/migrate/auto/default/terraform.tfstate new file mode 100644 index 00000000000..02a0a6d3d19 --- /dev/null +++ b/acceptance/bundle/migrate/auto/default/terraform.tfstate @@ -0,0 +1,23 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "a1b2c3d4-0001-4aaa-8bbb-000000000001", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "__ID_resources.jobs.test_job__", + "name": "Test Auto-Migrate Job" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/delete-all/output.txt b/acceptance/bundle/migrate/auto/delete-all/output.txt index 9989d35f381..f02a325151f 100644 --- a/acceptance/bundle/migrate/auto/delete-all/output.txt +++ b/acceptance/bundle/migrate/auto/delete-all/output.txt @@ -1,10 +1,6 @@ -=== Initial deploy on terraform ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.job_a -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== Seed a terraform-state fixture from a prior terraform deployment +>>> seed_tfstate.py terraform.tfstate === Remove all resources, then deploy on direct: migrate and delete >>> [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/delete-all/script b/acceptance/bundle/migrate/auto/delete-all/script index bf3ae01ff5b..cba44047444 100644 --- a/acceptance/bundle/migrate/auto/delete-all/script +++ b/acceptance/bundle/migrate/auto/delete-all/script @@ -1,7 +1,10 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +# The terraform engine was removed in v1.19.0, so seed the state from a fixture (a prior terraform +# deployment) instead of a real terraform deploy. +title "Seed a terraform-state fixture from a prior terraform deployment" +trace seed_tfstate.py terraform.tfstate +rm -f "$OUT_REQUESTS" # Removing every resource leaves the migration with no config-declared resources, so # BuildStateFromTF records no WAL entries. The migration must still persist the seeded diff --git a/acceptance/bundle/migrate/auto/delete-all/terraform.tfstate b/acceptance/bundle/migrate/auto/delete-all/terraform.tfstate new file mode 100644 index 00000000000..80b55f14ce0 --- /dev/null +++ b/acceptance/bundle/migrate/auto/delete-all/terraform.tfstate @@ -0,0 +1,23 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "8557670a-8050-5a50-955e-10844b2bcc7a", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_a", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "__ID_resources.jobs.job_a__", + "name": "Job A" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/delete/output.txt b/acceptance/bundle/migrate/auto/delete/output.txt index 2dabba9adab..1e0e01385ac 100644 --- a/acceptance/bundle/migrate/auto/delete/output.txt +++ b/acceptance/bundle/migrate/auto/delete/output.txt @@ -1,11 +1,6 @@ -=== Initial deploy on terraform with two jobs ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.job_drop -Created jobs.job_keep -Files: 1 uploaded, 0 deleted -Resources: 2 created, 0 changed, 0 deleted, 0 unchanged +=== Seed a terraform-state fixture with two jobs +>>> seed_tfstate.py terraform.tfstate === Drop one job from config, then deploy on direct: migrate two, delete the dropped one >>> [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/delete/script b/acceptance/bundle/migrate/auto/delete/script index 39116c88f9e..89d348a0b35 100644 --- a/acceptance/bundle/migrate/auto/delete/script +++ b/acceptance/bundle/migrate/auto/delete/script @@ -1,7 +1,10 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform with two jobs" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +# The terraform engine was removed in v1.19.0, so seed the state from a fixture (a prior terraform +# deployment of two jobs) instead of a real terraform deploy. +title "Seed a terraform-state fixture with two jobs" +trace seed_tfstate.py terraform.tfstate +rm -f "$OUT_REQUESTS" # The migration seeds every terraform-state resource into the direct state, so the # first direct plan can delete the ones the config no longer declares. diff --git a/acceptance/bundle/migrate/auto/delete/terraform.tfstate b/acceptance/bundle/migrate/auto/delete/terraform.tfstate new file mode 100644 index 00000000000..b70b79994b8 --- /dev/null +++ b/acceptance/bundle/migrate/auto/delete/terraform.tfstate @@ -0,0 +1,38 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "e95dfc7b-251c-50cc-8a24-6250b7b6c4ad", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_keep", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "__ID_resources.jobs.job_keep__", + "name": "Keep Job" + } + } + ] + }, + { + "mode": "managed", + "type": "databricks_job", + "name": "job_drop", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "__ID_resources.jobs.job_drop__", + "name": "Drop Job" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/destroy/output.txt b/acceptance/bundle/migrate/auto/destroy/output.txt index 7e239d23866..d1429058310 100644 --- a/acceptance/bundle/migrate/auto/destroy/output.txt +++ b/acceptance/bundle/migrate/auto/destroy/output.txt @@ -1,10 +1,6 @@ -=== Initial deploy on terraform ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.job_a -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== Seed a terraform-state fixture from a prior terraform deployment +>>> seed_tfstate.py terraform.tfstate === Destroy without approval: migration prepared in memory then dropped, stays on terraform >>> musterr [CLI] bundle destroy @@ -19,7 +15,6 @@ To proceed, use --auto-approve. ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate === Destroy on direct: migrate then destroy >>> [CLI] bundle destroy --auto-approve diff --git a/acceptance/bundle/migrate/auto/destroy/script b/acceptance/bundle/migrate/auto/destroy/script index 8450b09ada2..d410c655ac0 100644 --- a/acceptance/bundle/migrate/auto/destroy/script +++ b/acceptance/bundle/migrate/auto/destroy/script @@ -5,8 +5,11 @@ export DATABRICKS_BUNDLE_ENGINE= # .terraform/. Paired with a remote listing of the state directory, this shows exactly which state # is present locally and remotely and proves nothing is left behind. -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +# The terraform engine was removed in v1.19.0, so seed the state from a fixture (a prior terraform +# deployment) instead of a real terraform deploy. +title "Seed a terraform-state fixture from a prior terraform deployment" +trace seed_tfstate.py terraform.tfstate +rm -f "$OUT_REQUESTS" title "Destroy without approval: migration prepared in memory then dropped, stays on terraform" # The migration is prepared in memory (in process.go) before the destroy phase asks for approval, diff --git a/acceptance/bundle/migrate/auto/destroy/terraform.tfstate b/acceptance/bundle/migrate/auto/destroy/terraform.tfstate new file mode 100644 index 00000000000..b9e019514a3 --- /dev/null +++ b/acceptance/bundle/migrate/auto/destroy/terraform.tfstate @@ -0,0 +1,23 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "4c3342ea-72fa-58d4-ab31-edfdb3a70789", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_a", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "__ID_resources.jobs.job_a__", + "name": "Job A" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/direct-only-envvar/output.txt b/acceptance/bundle/migrate/auto/direct-only-envvar/output.txt index 9ac13f5e368..14b7c706bcd 100644 --- a/acceptance/bundle/migrate/auto/direct-only-envvar/output.txt +++ b/acceptance/bundle/migrate/auto/direct-only-envvar/output.txt @@ -1,10 +1,6 @@ -=== Deploy with terraform (instance_pools is commented out; terraform cannot deploy it) ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.job_a -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== Seed a terraform-state fixture (only job_a; instance_pools is commented out) +>>> seed_tfstate.py terraform.tfstate === Add a direct-only resource to the config >>> update_file.py databricks.yml #instance_pools instance_pools diff --git a/acceptance/bundle/migrate/auto/direct-only-envvar/script b/acceptance/bundle/migrate/auto/direct-only-envvar/script index d927be0e482..22de294814f 100644 --- a/acceptance/bundle/migrate/auto/direct-only-envvar/script +++ b/acceptance/bundle/migrate/auto/direct-only-envvar/script @@ -1,7 +1,10 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Deploy with terraform (instance_pools is commented out; terraform cannot deploy it)" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +# The terraform engine was removed in v1.19.0, so seed the state from a fixture instead of a real +# terraform deploy. instance_pools is commented out at seed time (terraform could not deploy it), +# so seed_tfstate.py's direct deploy creates only job_a, and the fixture holds only job_a. +title "Seed a terraform-state fixture (only job_a; instance_pools is commented out)" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" title "Add a direct-only resource to the config" diff --git a/acceptance/bundle/migrate/auto/direct-only-envvar/terraform.tfstate b/acceptance/bundle/migrate/auto/direct-only-envvar/terraform.tfstate new file mode 100644 index 00000000000..8a4e4d7afb0 --- /dev/null +++ b/acceptance/bundle/migrate/auto/direct-only-envvar/terraform.tfstate @@ -0,0 +1,23 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "7a0740e4-121f-5712-b75c-81351171196b", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_a", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "__ID_resources.jobs.job_a__", + "name": "Job A" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/direct-only/output.txt b/acceptance/bundle/migrate/auto/direct-only/output.txt index ed4e64d0137..cf4a98dee45 100644 --- a/acceptance/bundle/migrate/auto/direct-only/output.txt +++ b/acceptance/bundle/migrate/auto/direct-only/output.txt @@ -1,10 +1,6 @@ -=== Deploy with terraform (instance_pools is commented out; terraform cannot deploy it) ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.job_a -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== Seed a terraform-state fixture (only job_a; instance_pools is commented out) +>>> seed_tfstate.py terraform.tfstate === Add a direct-only resource and opt in to the direct engine via config >>> update_file.py databricks.yml #instance_pools instance_pools @@ -34,7 +30,6 @@ json.plan.resources.instance_pools.pool.new_state.value.node_type_id = "Standard ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate === Deploy commits the migration and creates the direct-only resource >>> [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/direct-only/script b/acceptance/bundle/migrate/auto/direct-only/script index 1d01ce69df1..8de7a6359f3 100644 --- a/acceptance/bundle/migrate/auto/direct-only/script +++ b/acceptance/bundle/migrate/auto/direct-only/script @@ -1,7 +1,10 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Deploy with terraform (instance_pools is commented out; terraform cannot deploy it)" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +# The terraform engine was removed in v1.19.0, so seed the state from a fixture instead of a real +# terraform deploy. instance_pools is commented out at seed time (terraform could not deploy it), +# so seed_tfstate.py's direct deploy creates only job_a, and the fixture holds only job_a. +title "Seed a terraform-state fixture (only job_a; instance_pools is commented out)" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" title "Add a direct-only resource and opt in to the direct engine via config" diff --git a/acceptance/bundle/migrate/auto/direct-only/terraform.tfstate b/acceptance/bundle/migrate/auto/direct-only/terraform.tfstate new file mode 100644 index 00000000000..accc00a6c72 --- /dev/null +++ b/acceptance/bundle/migrate/auto/direct-only/terraform.tfstate @@ -0,0 +1,23 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "4e17859f-afc8-5c12-a1ba-df2a3ed0cef9", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_a", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "__ID_resources.jobs.job_a__", + "name": "Job A" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/dms-migration/output.txt b/acceptance/bundle/migrate/auto/dms-migration/output.txt index 404c9d0078a..de5584c7d74 100644 --- a/acceptance/bundle/migrate/auto/dms-migration/output.txt +++ b/acceptance/bundle/migrate/auto/dms-migration/output.txt @@ -1,10 +1,6 @@ -=== Initial deploy on terraform ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.test_job -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== Seed a terraform-state fixture from a prior terraform deployment +>>> seed_tfstate.py terraform.tfstate === Direct + deployment-history requested against a terraform state is rejected before commit >>> DATABRICKS_BUNDLE_ENGINE=direct DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY=true errcode [CLI] bundle deploy @@ -23,4 +19,3 @@ Exit code: 1 ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate diff --git a/acceptance/bundle/migrate/auto/dms-migration/script b/acceptance/bundle/migrate/auto/dms-migration/script index ccd5eeecdb8..0564d148b7a 100644 --- a/acceptance/bundle/migrate/auto/dms-migration/script +++ b/acceptance/bundle/migrate/auto/dms-migration/script @@ -1,7 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +title "Seed a terraform-state fixture from a prior terraform deployment" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" title "Direct + deployment-history requested against a terraform state is rejected before commit" diff --git a/acceptance/bundle/migrate/auto/dms-migration/terraform.tfstate b/acceptance/bundle/migrate/auto/dms-migration/terraform.tfstate new file mode 100644 index 00000000000..beaf11e7115 --- /dev/null +++ b/acceptance/bundle/migrate/auto/dms-migration/terraform.tfstate @@ -0,0 +1,17 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Auto-Migrate DMS"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/envvar/output.txt b/acceptance/bundle/migrate/auto/envvar/output.txt index bfc4e1b677e..e98af293107 100644 --- a/acceptance/bundle/migrate/auto/envvar/output.txt +++ b/acceptance/bundle/migrate/auto/envvar/output.txt @@ -1,14 +1,6 @@ -=== Initial deploy uses terraform engine ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.test_job -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged - ->>> print_migration_telemetry -direct_drymigrate_success true -direct_drymigrate_warnings false +=== Seed a terraform-state fixture from a prior terraform deployment +>>> seed_tfstate.py terraform.tfstate === Opt in via env var only (no bundle.engine in config): auto-migration triggers >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/envvar/script b/acceptance/bundle/migrate/auto/envvar/script index 8fa8c03f8f7..63c031749e8 100644 --- a/acceptance/bundle/migrate/auto/envvar/script +++ b/acceptance/bundle/migrate/auto/envvar/script @@ -1,8 +1,10 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy uses terraform engine" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy -trace print_migration_telemetry +# The terraform engine was removed in v1.19.0, so seed the state from a fixture (a prior terraform +# deployment) instead of a real terraform deploy. seed_tfstate.py deploys on direct to create +# matching backend resources, threads their ids into the fixture, and drops the direct state. +title "Seed a terraform-state fixture from a prior terraform deployment" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" title "Opt in via env var only (no bundle.engine in config): auto-migration triggers" diff --git a/acceptance/bundle/migrate/auto/envvar/terraform.tfstate b/acceptance/bundle/migrate/auto/envvar/terraform.tfstate new file mode 100644 index 00000000000..21f839bbb17 --- /dev/null +++ b/acceptance/bundle/migrate/auto/envvar/terraform.tfstate @@ -0,0 +1,23 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "7e43a260-1ff1-5392-94c4-3892bf4f965a", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "__ID_resources.jobs.test_job__", + "name": "Test Auto-Migrate Job" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/pipeline-storage-change/output.txt b/acceptance/bundle/migrate/auto/pipeline-storage-change/output.txt index d5b768da87a..81bd814e10b 100644 --- a/acceptance/bundle/migrate/auto/pipeline-storage-change/output.txt +++ b/acceptance/bundle/migrate/auto/pipeline-storage-change/output.txt @@ -1,10 +1,6 @@ -=== Deploy the pipeline on terraform ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files... -Created pipelines.my_pipeline -Files: 3 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== A prior terraform deployment created the pipeline (seed the fixture) +>>> seed_tfstate.py terraform.tfstate === Change immutable storage. Without --auto-approve the recreate is refused >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/pipeline-storage-change/script b/acceptance/bundle/migrate/auto/pipeline-storage-change/script index c673a1071ce..2deb01e3c19 100644 --- a/acceptance/bundle/migrate/auto/pipeline-storage-change/script +++ b/acceptance/bundle/migrate/auto/pipeline-storage-change/script @@ -1,4 +1,5 @@ envsubst < databricks.yml.tmpl > databricks.yml +envsubst < terraform.tfstate.tmpl > terraform.tfstate && rm terraform.tfstate.tmpl cleanup() { title "Cleanup" @@ -6,8 +7,8 @@ cleanup() { } trap cleanup EXIT -title "Deploy the pipeline on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +title "A prior terraform deployment created the pipeline (seed the fixture)" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" title "Change immutable storage. Without --auto-approve the recreate is refused" diff --git a/acceptance/bundle/migrate/auto/pipeline-storage-change/terraform.tfstate.tmpl b/acceptance/bundle/migrate/auto/pipeline-storage-change/terraform.tfstate.tmpl new file mode 100644 index 00000000000..a051bb6f646 --- /dev/null +++ b/acceptance/bundle/migrate/auto/pipeline-storage-change/terraform.tfstate.tmpl @@ -0,0 +1,22 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_pipeline", + "name": "my_pipeline", + "instances": [ + { + "attributes": { + "id": "__ID_resources.pipelines.my_pipeline__", + "name": "pipeline-$UNIQUE_NAME", + "storage": "dbfs:/pipelines/$UNIQUE_NAME-init" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/plan-failure/output.txt b/acceptance/bundle/migrate/auto/plan-failure/output.txt index c5f24186a4d..039fddc040a 100644 --- a/acceptance/bundle/migrate/auto/plan-failure/output.txt +++ b/acceptance/bundle/migrate/auto/plan-failure/output.txt @@ -1,14 +1,6 @@ -=== Initial deploy on terraform ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.test_job -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged - ->>> print_migration_telemetry -direct_drymigrate_success true -direct_drymigrate_warnings false +=== Seed a terraform-state fixture from a prior terraform deployment +>>> seed_tfstate.py terraform.tfstate === Inject GET failure so the plan check blocks the migration >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy @@ -18,8 +10,9 @@ API error_code: INJECTED API message: Fault injected by test. Warn: migration to the direct engine failed its plan check; deploying on terraform this time: planning failed Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Updated jobs.test_job Files: 0 uploaded, 0 deleted -Resources: 0 created, 0 changed, 0 deleted, 1 unchanged +Resources: 0 created, 1 changed, 0 deleted, 0 unchanged >>> print_migration_telemetry direct_migrate_plan_error true @@ -27,6 +20,7 @@ direct_migrate_plan_error true === Local state was NOT rewritten (still terraform) >>> find.py \.databricks/.*(\.tfstate|resources.*\.json|\.wal) .databricks/bundle/default/terraform/terraform.tfstate +.databricks/bundle/default/terraform/terraform.tfstate.backup >>> MSYS_NO_PATHCONV=1 [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state ID Type Language Path diff --git a/acceptance/bundle/migrate/auto/plan-failure/script b/acceptance/bundle/migrate/auto/plan-failure/script index 55369b0aa28..6f7699276bc 100644 --- a/acceptance/bundle/migrate/auto/plan-failure/script +++ b/acceptance/bundle/migrate/auto/plan-failure/script @@ -1,17 +1,15 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy -trace print_migration_telemetry +title "Seed a terraform-state fixture from a prior terraform deployment" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" title "Inject GET failure so the plan check blocks the migration" -# The plan check calls GET /api/2.2/jobs/get for each resource to compare -# local config against remote state. A 403 (non-retryable) causes the plan -# to fail → the migration is abandoned and the bundle stays on terraform. -# The migration runs before any terraform plan, so the plan check's DoRead is -# the first GET here; OFFSET=0 fails it, and TIMES=1 lets terraform's later -# read through so the fallback deploy succeeds. +# The plan check calls GET /api/2.2/jobs/get for each resource to compare local config against +# remote state. A 403 (non-retryable) causes the plan to fail, so the migration is abandoned and +# the bundle stays on terraform. The migration runs before any terraform plan, so the plan check's +# DoRead is the first GET here; OFFSET=0 fails it, and TIMES=1 lets terraform's later read through +# so the fallback deploy succeeds. fault.py "GET /api/2.2/jobs/get*" 403 0 1 trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy trace print_migration_telemetry diff --git a/acceptance/bundle/migrate/auto/plan-failure/terraform.tfstate b/acceptance/bundle/migrate/auto/plan-failure/terraform.tfstate new file mode 100644 index 00000000000..528149b00a8 --- /dev/null +++ b/acceptance/bundle/migrate/auto/plan-failure/terraform.tfstate @@ -0,0 +1,17 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Auto-Migrate Plan Failure"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/plan-missing/output.txt b/acceptance/bundle/migrate/auto/plan-missing/output.txt index 4fd5003d991..9f59bf8e384 100644 --- a/acceptance/bundle/migrate/auto/plan-missing/output.txt +++ b/acceptance/bundle/migrate/auto/plan-missing/output.txt @@ -1,13 +1,9 @@ -=== Initial deploy on terraform ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.test_job -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== Seed a terraform-state fixture from a prior terraform deployment +>>> seed_tfstate.py terraform.tfstate === deploy --plan with a missing plan file fails after the migration prepared the direct state ->>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy --plan does-not-exist.json +>>> errcode [CLI] bundle deploy --plan does-not-exist.json Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). Error: reading plan file: open does-not-exist.json: no such file or directory @@ -22,10 +18,18 @@ Exit code: 1 ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate -=== A plain deploy still runs on terraform (the engine was not silently switched) ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy +=== A plain deploy migrates the still-terraform state (nothing was silently switched before) +>>> [CLI] bundle deploy +Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Migrated 1 resource to direct deployment engine. Files: 0 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged + +>>> print_migration_telemetry +direct_migrated_via_default true + +>>> find.py \.databricks/.*(\.tfstate|resources.*\.json|\.wal) +.databricks/bundle/default/resources.json +.databricks/bundle/default/terraform/terraform.tfstate.backup diff --git a/acceptance/bundle/migrate/auto/plan-missing/script b/acceptance/bundle/migrate/auto/plan-missing/script index 88deeee43d2..b08af6de0e4 100644 --- a/acceptance/bundle/migrate/auto/plan-missing/script +++ b/acceptance/bundle/migrate/auto/plan-missing/script @@ -1,17 +1,21 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +title "Seed a terraform-state fixture from a prior terraform deployment" +trace seed_tfstate.py terraform.tfstate +rm -f "$OUT_REQUESTS" title "deploy --plan with a missing plan file fails after the migration prepared the direct state" # The migration runs in memory (nothing is written) before the saved plan is loaded, so a missing # plan file fails before approval, and before CommitMigration would make it durable. A failed # command changes nothing: the in-memory migration is dropped and the bundle stays on terraform. -trace DATABRICKS_BUNDLE_ENGINE=direct errcode $CLI bundle deploy --plan does-not-exist.json +trace errcode $CLI bundle deploy --plan does-not-exist.json title "State is still terraform - the migration was never committed" trace find.py '\.databricks/.*(\.tfstate|resources.*\.json|\.wal)' trace MSYS_NO_PATHCONV=1 $CLI workspace list "/Workspace/Users/${CURRENT_USER_NAME}/.bundle/test-bundle/default/state" -title "A plain deploy still runs on terraform (the engine was not silently switched)" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +title "A plain deploy migrates the still-terraform state (nothing was silently switched before)" +trace $CLI bundle deploy +trace print_migration_telemetry +rm -f "$OUT_REQUESTS" +trace find.py '\.databricks/.*(\.tfstate|resources.*\.json|\.wal)' diff --git a/acceptance/bundle/migrate/auto/plan-missing/terraform.tfstate b/acceptance/bundle/migrate/auto/plan-missing/terraform.tfstate new file mode 100644 index 00000000000..34850502550 --- /dev/null +++ b/acceptance/bundle/migrate/auto/plan-missing/terraform.tfstate @@ -0,0 +1,17 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Auto-Migrate Plan Missing"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/push-failure/output.txt b/acceptance/bundle/migrate/auto/push-failure/output.txt index 30207ed86b4..2f2bc1da86f 100644 --- a/acceptance/bundle/migrate/auto/push-failure/output.txt +++ b/acceptance/bundle/migrate/auto/push-failure/output.txt @@ -1,14 +1,6 @@ -=== Initial deploy on terraform ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.test_job -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged - ->>> print_migration_telemetry -direct_drymigrate_success true -direct_drymigrate_warnings false +=== Seed a terraform-state fixture from a prior terraform deployment +>>> seed_tfstate.py terraform.tfstate === Opt in via env var; inject 403 on the resources.json push so the deploy fails >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy @@ -37,7 +29,6 @@ Exit code: 1 ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate === Retry: the local direct state is used (no re-migration) and the push completes >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy @@ -58,4 +49,3 @@ ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate.backup diff --git a/acceptance/bundle/migrate/auto/push-failure/script b/acceptance/bundle/migrate/auto/push-failure/script index 58e76ba9574..d911f32ea6d 100644 --- a/acceptance/bundle/migrate/auto/push-failure/script +++ b/acceptance/bundle/migrate/auto/push-failure/script @@ -1,13 +1,12 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy -trace print_migration_telemetry +title "Seed a terraform-state fixture from a prior terraform deployment" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" title "Opt in via env var; inject 403 on the resources.json push so the deploy fails" # The migration prepares the direct state in memory and in the local state file; the approved -# deploy (deployCore) pushes resources.json to the workspace. A 403 (non-retryable) on that +# deploy (CommitMigration) pushes resources.json to the workspace. A 403 (non-retryable) on that # push fails the deploy - unlike a declined deploy, the migration is not discarded, so the # local direct state remains and a retry finishes the push. (A push failure is a hard error on # any direct deploy, not just a migrating one.) diff --git a/acceptance/bundle/migrate/auto/push-failure/terraform.tfstate b/acceptance/bundle/migrate/auto/push-failure/terraform.tfstate new file mode 100644 index 00000000000..bc811f3b9d5 --- /dev/null +++ b/acceptance/bundle/migrate/auto/push-failure/terraform.tfstate @@ -0,0 +1,17 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Auto-Migrate Push Failure"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/registered-model-catalog-change/output.txt b/acceptance/bundle/migrate/auto/registered-model-catalog-change/output.txt index b49eb6e3004..9ca35cb8aa5 100644 --- a/acceptance/bundle/migrate/auto/registered-model-catalog-change/output.txt +++ b/acceptance/bundle/migrate/auto/registered-model-catalog-change/output.txt @@ -4,12 +4,8 @@ "name": "othercat_[UNIQUE_NAME]" } -=== Deploy the model on terraform in catalog 'main' ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files... -Created registered_models.my_model -Files: 2 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== A prior terraform deployment left the model in catalog 'main' (seed the fixture) +>>> seed_tfstate.py terraform.tfstate === Move the model to another catalog and deploy on direct >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/registered-model-catalog-change/script b/acceptance/bundle/migrate/auto/registered-model-catalog-change/script index 48f70c61175..5cc773e7c41 100644 --- a/acceptance/bundle/migrate/auto/registered-model-catalog-change/script +++ b/acceptance/bundle/migrate/auto/registered-model-catalog-change/script @@ -13,8 +13,8 @@ cleanup() { } trap cleanup EXIT -title "Deploy the model on terraform in catalog 'main'" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +title "A prior terraform deployment left the model in catalog 'main' (seed the fixture)" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" title "Move the model to another catalog and deploy on direct" diff --git a/acceptance/bundle/migrate/auto/registered-model-catalog-change/terraform.tfstate b/acceptance/bundle/migrate/auto/registered-model-catalog-change/terraform.tfstate new file mode 100644 index 00000000000..80a4289a1d6 --- /dev/null +++ b/acceptance/bundle/migrate/auto/registered-model-catalog-change/terraform.tfstate @@ -0,0 +1,22 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_registered_model", + "name": "my_model", + "instances": [ + { + "attributes": { + "id": "__ID_resources.registered_models.my_model__", + "catalog_name": "main", + "schema_name": "default" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/registered-model-rename/output.txt b/acceptance/bundle/migrate/auto/registered-model-rename/output.txt index f374e9dcb16..2a7b22f3b28 100644 --- a/acceptance/bundle/migrate/auto/registered-model-rename/output.txt +++ b/acceptance/bundle/migrate/auto/registered-model-rename/output.txt @@ -1,11 +1,6 @@ -=== Deploy the schema and registered model on terraform ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files... -Created registered_models.my_model -Created schemas.parent -Files: 2 uploaded, 0 deleted -Resources: 2 created, 0 changed, 0 deleted, 0 unchanged +=== A prior terraform deployment created the schema and model (seed the fixture) +>>> seed_tfstate.py terraform.tfstate === Rename the model (an immutable id field) and deploy on direct >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/registered-model-rename/script b/acceptance/bundle/migrate/auto/registered-model-rename/script index e1278fab249..e9d1763e9d8 100644 --- a/acceptance/bundle/migrate/auto/registered-model-rename/script +++ b/acceptance/bundle/migrate/auto/registered-model-rename/script @@ -1,4 +1,5 @@ envsubst < databricks.yml.tmpl > databricks.yml +envsubst < terraform.tfstate.tmpl > terraform.tfstate && rm terraform.tfstate.tmpl cleanup() { title "Cleanup" @@ -6,8 +7,8 @@ cleanup() { } trap cleanup EXIT -title "Deploy the schema and registered model on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +title "A prior terraform deployment created the schema and model (seed the fixture)" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" title "Rename the model (an immutable id field) and deploy on direct" diff --git a/acceptance/bundle/migrate/auto/registered-model-rename/terraform.tfstate.tmpl b/acceptance/bundle/migrate/auto/registered-model-rename/terraform.tfstate.tmpl new file mode 100644 index 00000000000..9aef45fe87f --- /dev/null +++ b/acceptance/bundle/migrate/auto/registered-model-rename/terraform.tfstate.tmpl @@ -0,0 +1,36 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_schema", + "name": "parent", + "instances": [ + { + "attributes": { + "id": "__ID_resources.schemas.parent__", + "catalog_name": "main" + } + } + ] + }, + { + "mode": "managed", + "type": "databricks_registered_model", + "name": "my_model", + "instances": [ + { + "attributes": { + "id": "__ID_resources.registered_models.my_model__", + "name": "themodel-$UNIQUE_NAME", + "catalog_name": "main", + "schema_name": "mschema-$UNIQUE_NAME" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/run-no-commit/output.txt b/acceptance/bundle/migrate/auto/run-no-commit/output.txt index 8c2bf28a470..46ade8beba6 100644 --- a/acceptance/bundle/migrate/auto/run-no-commit/output.txt +++ b/acceptance/bundle/migrate/auto/run-no-commit/output.txt @@ -1,10 +1,6 @@ -=== Initial deploy on terraform ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.test_job -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== Seed a terraform-state fixture from a prior terraform deployment +>>> seed_tfstate.py terraform.tfstate === bundle run on direct migrates the terraform state IN MEMORY (no commit) to resolve the job >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle run test_job --no-wait @@ -23,4 +19,3 @@ Run URL: [DATABRICKS_URL]/jobs/[NUMID]/runs/[NUMID]?o=[NUMID] ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate diff --git a/acceptance/bundle/migrate/auto/run-no-commit/script b/acceptance/bundle/migrate/auto/run-no-commit/script index c1e275ff819..0373bd070e3 100644 --- a/acceptance/bundle/migrate/auto/run-no-commit/script +++ b/acceptance/bundle/migrate/auto/run-no-commit/script @@ -1,7 +1,10 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +# The terraform engine was removed in v1.19.0, so seed the state from a fixture (a prior terraform +# deployment) instead of a real terraform deploy. seed_tfstate.py deploys on direct to create the +# job, threads its id into the fixture, and drops the direct state so the bundle is on terraform. +title "Seed a terraform-state fixture from a prior terraform deployment" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" title "bundle run on direct migrates the terraform state IN MEMORY (no commit) to resolve the job" diff --git a/acceptance/bundle/migrate/auto/run-no-commit/terraform.tfstate b/acceptance/bundle/migrate/auto/run-no-commit/terraform.tfstate new file mode 100644 index 00000000000..a5b4cfe3935 --- /dev/null +++ b/acceptance/bundle/migrate/auto/run-no-commit/terraform.tfstate @@ -0,0 +1,23 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "f44d407f-f606-56f7-bc0e-0cfc5b893a4a", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "__ID_resources.jobs.test_job__", + "name": "Test Auto-Migrate Run" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/schema-catalog-change/output.txt b/acceptance/bundle/migrate/auto/schema-catalog-change/output.txt index 388e7977655..6f144756daa 100644 --- a/acceptance/bundle/migrate/auto/schema-catalog-change/output.txt +++ b/acceptance/bundle/migrate/auto/schema-catalog-change/output.txt @@ -4,12 +4,8 @@ "name": "othercat_[UNIQUE_NAME]" } -=== Deploy the schema on terraform in catalog 'main' ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files... -Created schemas.my_schema -Files: 2 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== A prior terraform deployment left the schema in catalog 'main' (seed the fixture) +>>> seed_tfstate.py terraform.tfstate === Move the schema to another catalog. Without --auto-approve the recreate is refused >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/schema-catalog-change/script b/acceptance/bundle/migrate/auto/schema-catalog-change/script index 52aa01327d2..726f7f05a8e 100644 --- a/acceptance/bundle/migrate/auto/schema-catalog-change/script +++ b/acceptance/bundle/migrate/auto/schema-catalog-change/script @@ -13,8 +13,8 @@ cleanup() { } trap cleanup EXIT -title "Deploy the schema on terraform in catalog 'main'" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +title "A prior terraform deployment left the schema in catalog 'main' (seed the fixture)" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" title "Move the schema to another catalog. Without --auto-approve the recreate is refused" diff --git a/acceptance/bundle/migrate/auto/schema-catalog-change/terraform.tfstate b/acceptance/bundle/migrate/auto/schema-catalog-change/terraform.tfstate new file mode 100644 index 00000000000..582a576caa1 --- /dev/null +++ b/acceptance/bundle/migrate/auto/schema-catalog-change/terraform.tfstate @@ -0,0 +1,21 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_schema", + "name": "my_schema", + "instances": [ + { + "attributes": { + "id": "__ID_resources.schemas.my_schema__", + "catalog_name": "main" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/schema-name-normalized/output.txt b/acceptance/bundle/migrate/auto/schema-name-normalized/output.txt index 301f156c314..7e11c96463f 100644 --- a/acceptance/bundle/migrate/auto/schema-name-normalized/output.txt +++ b/acceptance/bundle/migrate/auto/schema-name-normalized/output.txt @@ -1,10 +1,6 @@ -=== Deploy on terraform; UC lowercases the schema name ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files... -Created schemas.my_schema -Files: 2 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== A prior terraform deployment stored the lowercased schema name (seed the fixture) +>>> seed_tfstate.py terraform.tfstate === Migrate to direct with the same config (mixed-case name unchanged) >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/schema-name-normalized/script b/acceptance/bundle/migrate/auto/schema-name-normalized/script index 72607f2d689..cadc5ec635c 100644 --- a/acceptance/bundle/migrate/auto/schema-name-normalized/script +++ b/acceptance/bundle/migrate/auto/schema-name-normalized/script @@ -1,4 +1,5 @@ envsubst < databricks.yml.tmpl > databricks.yml +envsubst < terraform.tfstate.tmpl > terraform.tfstate && rm terraform.tfstate.tmpl cleanup() { title "Cleanup" @@ -9,10 +10,11 @@ trap cleanup EXIT # The config uses a mixed-case schema name; UC lowercases the stored name, so the deployed id # differs from config by case only, without the user changing anything. reconcileIDFields # treats a case-only difference as backend normalization and keeps the config value, so the -# migration proceeds with no warning and the plan converges. +# migration proceeds with no warning and the plan converges. The fixture holds the lowercased +# (deployed) name to mirror what a terraform deployment would have recorded. -title "Deploy on terraform; UC lowercases the schema name" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +title "A prior terraform deployment stored the lowercased schema name (seed the fixture)" +trace seed_tfstate.py terraform.tfstate title "Migrate to direct with the same config (mixed-case name unchanged)" trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy diff --git a/acceptance/bundle/migrate/auto/schema-name-normalized/terraform.tfstate.tmpl b/acceptance/bundle/migrate/auto/schema-name-normalized/terraform.tfstate.tmpl new file mode 100644 index 00000000000..2f88ccf0058 --- /dev/null +++ b/acceptance/bundle/migrate/auto/schema-name-normalized/terraform.tfstate.tmpl @@ -0,0 +1,22 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_schema", + "name": "my_schema", + "instances": [ + { + "attributes": { + "id": "__ID_resources.schemas.my_schema__", + "name": "myschema-$UNIQUE_NAME", + "catalog_name": "main" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/schema-rename/output.txt b/acceptance/bundle/migrate/auto/schema-rename/output.txt index 3b81286a990..927b31f0bb0 100644 --- a/acceptance/bundle/migrate/auto/schema-rename/output.txt +++ b/acceptance/bundle/migrate/auto/schema-rename/output.txt @@ -1,10 +1,6 @@ -=== Deploy the schema on terraform ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files... -Created schemas.my_schema -Files: 2 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== A prior terraform deployment created the schema (seed the fixture) +>>> seed_tfstate.py terraform.tfstate === Rename the schema (an immutable id field). Without --auto-approve the recreate is refused >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/schema-rename/script b/acceptance/bundle/migrate/auto/schema-rename/script index e5b93830f28..953e5371a9a 100644 --- a/acceptance/bundle/migrate/auto/schema-rename/script +++ b/acceptance/bundle/migrate/auto/schema-rename/script @@ -1,4 +1,5 @@ envsubst < databricks.yml.tmpl > databricks.yml +envsubst < terraform.tfstate.tmpl > terraform.tfstate && rm terraform.tfstate.tmpl cleanup() { title "Cleanup" @@ -6,8 +7,8 @@ cleanup() { } trap cleanup EXIT -title "Deploy the schema on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +title "A prior terraform deployment created the schema (seed the fixture)" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" title "Rename the schema (an immutable id field). Without --auto-approve the recreate is refused" diff --git a/acceptance/bundle/migrate/auto/schema-rename/terraform.tfstate.tmpl b/acceptance/bundle/migrate/auto/schema-rename/terraform.tfstate.tmpl new file mode 100644 index 00000000000..2f88ccf0058 --- /dev/null +++ b/acceptance/bundle/migrate/auto/schema-rename/terraform.tfstate.tmpl @@ -0,0 +1,22 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_schema", + "name": "my_schema", + "instances": [ + { + "attributes": { + "id": "__ID_resources.schemas.my_schema__", + "name": "myschema-$UNIQUE_NAME", + "catalog_name": "main" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/schema-storage-change/output.txt b/acceptance/bundle/migrate/auto/schema-storage-change/output.txt index 6201c860667..4875e8bda85 100644 --- a/acceptance/bundle/migrate/auto/schema-storage-change/output.txt +++ b/acceptance/bundle/migrate/auto/schema-storage-change/output.txt @@ -1,14 +1,6 @@ -=== Initial deploy on terraform with storage_root s3://mybucket/init ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created schemas.my_schema -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged - ->>> print_migration_telemetry -direct_drymigrate_success true -direct_drymigrate_warnings false +=== A prior terraform deployment left the schema with storage_root s3://mybucket/init (seed the fixture) +>>> seed_tfstate.py terraform.tfstate === Change immutable storage_root; without --auto-approve the recreate is refused >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy @@ -37,7 +29,6 @@ direct_migrate_recreate_planned true ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate === With --auto-approve the migration commits and the recreate is applied on direct >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy --auto-approve diff --git a/acceptance/bundle/migrate/auto/schema-storage-change/script b/acceptance/bundle/migrate/auto/schema-storage-change/script index 5c793b9d929..ab5d241da90 100644 --- a/acceptance/bundle/migrate/auto/schema-storage-change/script +++ b/acceptance/bundle/migrate/auto/schema-storage-change/script @@ -4,9 +4,8 @@ export DATABRICKS_BUNDLE_ENGINE= # workspace, so this is not Cloud-enabled. The recreate/refusal class it covers is verified # on cloud by schema-rename and pipeline-storage-change. -title "Initial deploy on terraform with storage_root s3://mybucket/init" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy -trace print_migration_telemetry +title "A prior terraform deployment left the schema with storage_root s3://mybucket/init (seed the fixture)" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" title "Change immutable storage_root; without --auto-approve the recreate is refused" diff --git a/acceptance/bundle/migrate/auto/schema-storage-change/terraform.tfstate b/acceptance/bundle/migrate/auto/schema-storage-change/terraform.tfstate new file mode 100644 index 00000000000..66020f66167 --- /dev/null +++ b/acceptance/bundle/migrate/auto/schema-storage-change/terraform.tfstate @@ -0,0 +1,23 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_schema", + "name": "my_schema", + "instances": [ + { + "attributes": { + "id": "__ID_resources.schemas.my_schema__", + "name": "myschema", + "catalog_name": "main", + "storage_root": "s3://mybucket/init" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/schema-storage-normalized/output.txt b/acceptance/bundle/migrate/auto/schema-storage-normalized/output.txt index 2a05926d403..05cf6445bcd 100644 --- a/acceptance/bundle/migrate/auto/schema-storage-normalized/output.txt +++ b/acceptance/bundle/migrate/auto/schema-storage-normalized/output.txt @@ -1,10 +1,6 @@ -=== Deploy on terraform; UC strips the trailing slash from storage_root ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created schemas.my_schema -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== A prior terraform deployment stored storage_root with the trailing slash stripped (seed the fixture) +>>> seed_tfstate.py terraform.tfstate === Migrate to direct with the same config (storage_root still has the trailing slash) >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/schema-storage-normalized/script b/acceptance/bundle/migrate/auto/schema-storage-normalized/script index ad6ccc2bb64..a9f3efea6b9 100644 --- a/acceptance/bundle/migrate/auto/schema-storage-normalized/script +++ b/acceptance/bundle/migrate/auto/schema-storage-normalized/script @@ -9,8 +9,8 @@ export DATABRICKS_BUNDLE_ENGINE= # ("s3://bucket/path"), a difference the user did not make. normalize_slash absorbs it, so the # migration proceeds with no warning or recreate and the plan converges. -title "Deploy on terraform; UC strips the trailing slash from storage_root" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +title "A prior terraform deployment stored storage_root with the trailing slash stripped (seed the fixture)" +trace seed_tfstate.py terraform.tfstate title "Migrate to direct with the same config (storage_root still has the trailing slash)" trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy diff --git a/acceptance/bundle/migrate/auto/schema-storage-normalized/terraform.tfstate b/acceptance/bundle/migrate/auto/schema-storage-normalized/terraform.tfstate new file mode 100644 index 00000000000..c03b350ff23 --- /dev/null +++ b/acceptance/bundle/migrate/auto/schema-storage-normalized/terraform.tfstate @@ -0,0 +1,23 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_schema", + "name": "my_schema", + "instances": [ + { + "attributes": { + "id": "__ID_resources.schemas.my_schema__", + "name": "myschema", + "catalog_name": "main", + "storage_root": "s3://bucket/path" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/tfbackup-failure/output.txt b/acceptance/bundle/migrate/auto/tfbackup-failure/output.txt index ff2808ee6cb..a57a81b1250 100644 --- a/acceptance/bundle/migrate/auto/tfbackup-failure/output.txt +++ b/acceptance/bundle/migrate/auto/tfbackup-failure/output.txt @@ -1,14 +1,6 @@ -=== Initial deploy on terraform ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.test_job -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged - ->>> print_migration_telemetry -direct_drymigrate_success true -direct_drymigrate_warnings false +=== Seed a terraform-state fixture from a prior terraform deployment +>>> seed_tfstate.py terraform.tfstate === Opt in via env var; inject 403 on the DELETE of remote terraform.tfstate >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/tfbackup-failure/script b/acceptance/bundle/migrate/auto/tfbackup-failure/script index 11a74c93106..86031a4e683 100644 --- a/acceptance/bundle/migrate/auto/tfbackup-failure/script +++ b/acceptance/bundle/migrate/auto/tfbackup-failure/script @@ -1,17 +1,19 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy -trace print_migration_telemetry +title "Seed a terraform-state fixture from a prior terraform deployment" +trace seed_tfstate.py terraform.tfstate +# A real terraform deployment also pushes its state to the workspace; the seed writes only the +# local copy, so push a remote terraform.tfstate too, giving CommitMigration a remote state to +# back up and delete (the delete is what we fault below). +MSYS_NO_PATHCONV=1 $CLI workspace import "/Workspace/Users/${CURRENT_USER_NAME}/.bundle/test-bundle/default/state/terraform.tfstate" --file .databricks/bundle/default/terraform/terraform.tfstate --format AUTO rm -f "$OUT_REQUESTS" title "Opt in via env var; inject 403 on the DELETE of remote terraform.tfstate" -# The approved deploy commits the migration (CommitMigration): it pushes resources.json, then -# best-effort backs up and deletes the remote terraform.tfstate. That delete is the SECOND -# workspace/delete of the run - the first is the artifacts/.internal cleanup - so OFFSET=1 faults -# it. The delete failure is best-effort (resources.json already outranks the terraform state by -# serial), so the migration succeeds with a warning and the remote terraform.tfstate and its -# .backup both remain. +# CommitMigration pushes resources.json, then best-effort backs up and deletes the remote +# terraform.tfstate. That delete is the SECOND workspace/delete of the run - the first is the +# artifacts/.internal cleanup - so OFFSET=1 faults it. The delete failure is best-effort +# (resources.json already outranks the terraform state by serial), so the migration succeeds with +# a warning and the remote terraform.tfstate and its .backup both remain. fault.py "POST /api/2.0/workspace/delete" 403 1 1 trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy trace print_migration_telemetry diff --git a/acceptance/bundle/migrate/auto/tfbackup-failure/terraform.tfstate b/acceptance/bundle/migrate/auto/tfbackup-failure/terraform.tfstate new file mode 100644 index 00000000000..853f76c1815 --- /dev/null +++ b/acceptance/bundle/migrate/auto/tfbackup-failure/terraform.tfstate @@ -0,0 +1,17 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Auto-Migrate Backup Failure"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/volume-name-normalized/output.txt b/acceptance/bundle/migrate/auto/volume-name-normalized/output.txt index 9730b1ffc61..54efdf0a228 100644 --- a/acceptance/bundle/migrate/auto/volume-name-normalized/output.txt +++ b/acceptance/bundle/migrate/auto/volume-name-normalized/output.txt @@ -1,10 +1,6 @@ -=== Deploy on terraform; UC lowercases the volume name ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files... -Created volumes.my_volume -Files: 2 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== A prior terraform deployment stored the lowercased volume name (seed the fixture) +>>> seed_tfstate.py terraform.tfstate === Migrate to direct with the same config (mixed-case name unchanged) >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/volume-name-normalized/script b/acceptance/bundle/migrate/auto/volume-name-normalized/script index c9a14dab412..1c3766d5558 100644 --- a/acceptance/bundle/migrate/auto/volume-name-normalized/script +++ b/acceptance/bundle/migrate/auto/volume-name-normalized/script @@ -1,4 +1,5 @@ envsubst < databricks.yml.tmpl > databricks.yml +envsubst < terraform.tfstate.tmpl > terraform.tfstate && rm terraform.tfstate.tmpl cleanup() { title "Cleanup" @@ -9,10 +10,11 @@ trap cleanup EXIT # name is an immutable provided id field. UC lowercases it, so the deployed id differs from # config by case only, without the user changing anything. reconcileIDFields treats the # case-only difference as backend normalization and keeps the config value, so the migration -# proceeds with no warning and the plan converges. +# proceeds with no warning and the plan converges. The fixture holds the lowercased (deployed) +# name to mirror what a terraform deployment would have recorded. -title "Deploy on terraform; UC lowercases the volume name" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +title "A prior terraform deployment stored the lowercased volume name (seed the fixture)" +trace seed_tfstate.py terraform.tfstate title "Migrate to direct with the same config (mixed-case name unchanged)" trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy diff --git a/acceptance/bundle/migrate/auto/volume-name-normalized/terraform.tfstate.tmpl b/acceptance/bundle/migrate/auto/volume-name-normalized/terraform.tfstate.tmpl new file mode 100644 index 00000000000..2546eca5d42 --- /dev/null +++ b/acceptance/bundle/migrate/auto/volume-name-normalized/terraform.tfstate.tmpl @@ -0,0 +1,24 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_volume", + "name": "my_volume", + "instances": [ + { + "attributes": { + "id": "__ID_resources.volumes.my_volume__", + "name": "myvolume-$UNIQUE_NAME", + "catalog_name": "main", + "schema_name": "default", + "volume_type": "MANAGED" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/volume-rename/output.txt b/acceptance/bundle/migrate/auto/volume-rename/output.txt index 477b35d68c3..e9b354dd9a6 100644 --- a/acceptance/bundle/migrate/auto/volume-rename/output.txt +++ b/acceptance/bundle/migrate/auto/volume-rename/output.txt @@ -1,11 +1,6 @@ -=== Deploy the schema and volume on terraform ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files... -Created schemas.parent -Created volumes.my_volume -Files: 2 uploaded, 0 deleted -Resources: 2 created, 0 changed, 0 deleted, 0 unchanged +=== A prior terraform deployment created the schema and volume (seed the fixture) +>>> seed_tfstate.py terraform.tfstate === Rename the volume (an updatable id field) and deploy on direct >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/volume-rename/script b/acceptance/bundle/migrate/auto/volume-rename/script index 9d2a5f62f09..75edae5c2f7 100644 --- a/acceptance/bundle/migrate/auto/volume-rename/script +++ b/acceptance/bundle/migrate/auto/volume-rename/script @@ -1,4 +1,5 @@ envsubst < databricks.yml.tmpl > databricks.yml +envsubst < terraform.tfstate.tmpl > terraform.tfstate && rm terraform.tfstate.tmpl cleanup() { title "Cleanup" @@ -6,8 +7,8 @@ cleanup() { } trap cleanup EXIT -title "Deploy the schema and volume on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +title "A prior terraform deployment created the schema and volume (seed the fixture)" +trace seed_tfstate.py terraform.tfstate title "Rename the volume (an updatable id field) and deploy on direct" # Unlike a schema (whose name recreates), a volume name is an updatable id field: it is diff --git a/acceptance/bundle/migrate/auto/volume-rename/terraform.tfstate.tmpl b/acceptance/bundle/migrate/auto/volume-rename/terraform.tfstate.tmpl new file mode 100644 index 00000000000..496c2211e2f --- /dev/null +++ b/acceptance/bundle/migrate/auto/volume-rename/terraform.tfstate.tmpl @@ -0,0 +1,37 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_schema", + "name": "parent", + "instances": [ + { + "attributes": { + "id": "__ID_resources.schemas.parent__", + "catalog_name": "main" + } + } + ] + }, + { + "mode": "managed", + "type": "databricks_volume", + "name": "my_volume", + "instances": [ + { + "attributes": { + "id": "__ID_resources.volumes.my_volume__", + "name": "thevolume-$UNIQUE_NAME", + "catalog_name": "main", + "schema_name": "pschema-$UNIQUE_NAME", + "volume_type": "MANAGED" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/auto/volume-type-change/output.txt b/acceptance/bundle/migrate/auto/volume-type-change/output.txt index 9c4a10b92fc..d641dcd4677 100644 --- a/acceptance/bundle/migrate/auto/volume-type-change/output.txt +++ b/acceptance/bundle/migrate/auto/volume-type-change/output.txt @@ -1,10 +1,6 @@ -=== Deploy on terraform with volume_type MANAGED ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created volumes.my_volume -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== A prior terraform deployment left the volume with volume_type MANAGED (seed the fixture) +>>> seed_tfstate.py terraform.tfstate === Change volume_type (immutable); without --auto-approve the recreate is refused >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/volume-type-change/script b/acceptance/bundle/migrate/auto/volume-type-change/script index 26b253f2d59..c3a78b57c77 100644 --- a/acceptance/bundle/migrate/auto/volume-type-change/script +++ b/acceptance/bundle/migrate/auto/volume-type-change/script @@ -9,8 +9,8 @@ export DATABRICKS_BUNDLE_ENGINE= # are in the destructive-approval group, so without --auto-approve the deploy refuses the # recreate (exit 1) and the migration is not committed. -title "Deploy on terraform with volume_type MANAGED" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +title "A prior terraform deployment left the volume with volume_type MANAGED (seed the fixture)" +trace seed_tfstate.py terraform.tfstate rm -f "$OUT_REQUESTS" title "Change volume_type (immutable); without --auto-approve the recreate is refused" diff --git a/acceptance/bundle/migrate/auto/volume-type-change/terraform.tfstate b/acceptance/bundle/migrate/auto/volume-type-change/terraform.tfstate new file mode 100644 index 00000000000..5bbe7a49199 --- /dev/null +++ b/acceptance/bundle/migrate/auto/volume-type-change/terraform.tfstate @@ -0,0 +1,24 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "resources": [ + { + "mode": "managed", + "type": "databricks_volume", + "name": "my_volume", + "instances": [ + { + "attributes": { + "id": "__ID_resources.volumes.my_volume__", + "name": "myvolume", + "catalog_name": "main", + "schema_name": "default", + "volume_type": "MANAGED" + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/command/added-direct-only/output.txt b/acceptance/bundle/migrate/command/added-direct-only/output.txt index b9042b01cc3..1551130fcd6 100644 --- a/acceptance/bundle/migrate/command/added-direct-only/output.txt +++ b/acceptance/bundle/migrate/command/added-direct-only/output.txt @@ -1,23 +1,10 @@ -=== Deploy with terraform (instance_pools is commented out; terraform cannot deploy it) ->>> [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created jobs.job_a -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +=== Seed a terraform deployment of job_a only +>>> seed_tfstate.py terraform.tfstate -=== Add a direct-only resource to the config without deploying it +=== Add a direct-only resource to the config >>> update_file.py databricks.yml #instance_pools instance_pools -=== Deploying on terraform rejects it, which is what sends the user to migrate ->>> musterr [CLI] bundle deploy -Error: Instance Pool resources are only supported with direct deployment mode - in databricks.yml:5:19 - -Instance Pool resources require direct deployment mode. Please set the DATABRICKS_BUNDLE_ENGINE environment variable to 'direct' or set 'bundle.engine: direct' in your databricks.yml to use instance_pool resources. -Learn more at https://docs.databricks.com/dev-tools/bundles/direct - - === Migration ignores the direct-only resource; it will be created on the next deploy >>> [CLI] bundle deployment migrate Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json @@ -30,13 +17,13 @@ To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/default/resource === After migration: plan shows the direct-only resource as "to add" ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan +>>> [CLI] bundle plan create instance_pools.pool Plan: 1 to add, 0 to change, 0 to delete, 1 unchanged === Deploy creates it; verify via recorded requests ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy +>>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... Created instance_pools.pool Files: 1 uploaded, 0 deleted @@ -59,5 +46,5 @@ Resources: 1 created, 0 changed, 0 deleted, 1 unchanged } === No further actions planned ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan +>>> [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged diff --git a/acceptance/bundle/migrate/command/added-direct-only/script b/acceptance/bundle/migrate/command/added-direct-only/script index e500a603b6d..d6ddc5ee959 100644 --- a/acceptance/bundle/migrate/command/added-direct-only/script +++ b/acceptance/bundle/migrate/command/added-direct-only/script @@ -1,26 +1,25 @@ -export DATABRICKS_BUNDLE_ENGINE=terraform +export DATABRICKS_BUNDLE_ENGINE= -title "Deploy with terraform (instance_pools is commented out; terraform cannot deploy it)" -trace $CLI bundle deploy +# Seed a prior terraform deployment of job_a (instance_pools is commented out, so the +# terraform deployment never had it). +title "Seed a terraform deployment of job_a only" +trace seed_tfstate.py terraform.tfstate -title "Add a direct-only resource to the config without deploying it" +title "Add a direct-only resource to the config" trace update_file.py databricks.yml "#instance_pools" "instance_pools" -title "Deploying on terraform rejects it, which is what sends the user to migrate" -trace musterr $CLI bundle deploy - title "Migration ignores the direct-only resource; it will be created on the next deploy" trace $CLI bundle deployment migrate title "After migration: plan shows the direct-only resource as \"to add\"" -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan +trace $CLI bundle plan title "Deploy creates it; verify via recorded requests" rm "$OUT_REQUESTS" -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy +trace $CLI bundle deploy trace print_requests.py //instance-pools/create title "No further actions planned" -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan +trace $CLI bundle plan rm "$OUT_REQUESTS" diff --git a/acceptance/bundle/migrate/command/added-direct-only/terraform.tfstate b/acceptance/bundle/migrate/command/added-direct-only/terraform.tfstate new file mode 100644 index 00000000000..c8134a2d900 --- /dev/null +++ b/acceptance/bundle/migrate/command/added-direct-only/terraform.tfstate @@ -0,0 +1,17 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "a1b2c3d4-0000-4000-8000-000000000003", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_a", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.job_a__", "name": "Job A"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/command/added/output.txt b/acceptance/bundle/migrate/command/added/output.txt index 99fad42f750..0a9651c9b13 100644 --- a/acceptance/bundle/migrate/command/added/output.txt +++ b/acceptance/bundle/migrate/command/added/output.txt @@ -1,9 +1,5 @@ ->>> [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-added-test/default/files... -Created jobs.job_a -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +>>> seed_tfstate.py terraform.tfstate >>> [CLI] bundle deployment migrate Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json @@ -15,12 +11,12 @@ The state file is not synchronized to the workspace yet. To do that and finalize To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/default/resources.json and rename [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate.backup to [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan +>>> [CLI] bundle plan create jobs.job_b Plan: 1 to add, 0 to change, 0 to delete, 1 unchanged ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy +>>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-added-test/default/files... Created jobs.job_b Files: 1 uploaded, 0 deleted @@ -50,5 +46,5 @@ Resources: 1 created, 0 changed, 0 deleted, 1 unchanged } } ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan +>>> [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged diff --git a/acceptance/bundle/migrate/command/added/script b/acceptance/bundle/migrate/command/added/script index 78846a084bf..69f7ec3c938 100644 --- a/acceptance/bundle/migrate/command/added/script +++ b/acceptance/bundle/migrate/command/added/script @@ -1,23 +1,23 @@ -export DATABRICKS_BUNDLE_ENGINE=terraform +export DATABRICKS_BUNDLE_ENGINE= -# Deploy with terraform (only job_a; job_b is commented out) -trace $CLI bundle deploy +# Seed a prior terraform deployment of job_a (job_b is commented out in config). +trace seed_tfstate.py terraform.tfstate # Uncomment job_b (add it to config without deploying) update_file.py databricks.yml "#job_b" "job_b" -# job_b skipped, will be created on next deploy +# job_b is not in the terraform state, so the migration skips it; it is created on next deploy trace $CLI bundle deployment migrate # After migration: plan shows job_b as "to add" -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "1 to add" +trace $CLI bundle plan | contains.py "1 to add" # Deploy creates job_b; verify via recorded requests rm "$OUT_REQUESTS" -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy +trace $CLI bundle deploy trace print_requests.py //jobs/create # No further actions planned -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "2 unchanged" +trace $CLI bundle plan | contains.py "2 unchanged" rm "$OUT_REQUESTS" diff --git a/acceptance/bundle/migrate/command/added/terraform.tfstate b/acceptance/bundle/migrate/command/added/terraform.tfstate new file mode 100644 index 00000000000..d26774ad8e1 --- /dev/null +++ b/acceptance/bundle/migrate/command/added/terraform.tfstate @@ -0,0 +1,17 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "a1b2c3d4-0000-4000-8000-000000000001", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_a", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.job_a__", "name": "Job A"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/command/basic/out.new_state.json b/acceptance/bundle/migrate/command/basic/out.new_state.json index e924cb4d005..a310fbf1dc4 100644 --- a/acceptance/bundle/migrate/command/basic/out.new_state.json +++ b/acceptance/bundle/migrate/command/basic/out.new_state.json @@ -2,7 +2,7 @@ "state_version": 3, "cli_version": "[CLI_VERSION]", "lineage": "[UUID]", - "serial": 6, + "serial": 7, "state": { "resources.jobs.test_job": { "__id__": "[NUMID]", diff --git a/acceptance/bundle/migrate/command/basic/out.original_state.json b/acceptance/bundle/migrate/command/basic/out.original_state.json index 147893321a1..4ff1d824f05 100644 --- a/acceptance/bundle/migrate/command/basic/out.original_state.json +++ b/acceptance/bundle/migrate/command/basic/out.original_state.json @@ -1,9 +1,8 @@ { "version": 4, "terraform_version": "1.5.5", - "serial": 4, + "serial": 5, "lineage": "[UUID]", - "outputs": {}, "resources": [ { "mode": "managed", @@ -11,281 +10,26 @@ "name": "test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 2, - "attributes": { - "always_running": false, - "budget_policy_id": null, - "continuous": [], - "control_run_state": false, - "dbt_task": [], - "deployment": [ - { - "deployment_id": "", - "kind": "BUNDLE", - "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/state/metadata.json", - "version_id": "" - } - ], - "description": null, - "edit_mode": "UI_LOCKED", - "email_notifications": [ - { - "no_alert_for_skipped_runs": false, - "on_duration_warning_threshold_exceeded": [], - "on_failure": [], - "on_start": [], - "on_streaming_backlog_exceeded": [], - "on_success": [] - } - ], - "environment": [], - "existing_cluster_id": null, - "format": "MULTI_TASK", - "git_source": [], - "health": [], - "id": "[NUMID]", - "job_cluster": [], - "library": [], - "max_concurrent_runs": 1, - "max_retries": 0, - "min_retry_interval_millis": 0, - "name": "Test Migration Job", - "new_cluster": [], - "notebook_task": [], - "notification_settings": [], - "parameter": [], - "parent_path": null, - "performance_target": null, - "pipeline_task": [], - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "python_wheel_task": [], - "queue": [ - { - "enabled": true - } - ], - "retry_on_timeout": false, - "run_as": [ - { - "group_name": "", - "service_principal_name": "", - "user_name": "[USERNAME]" - } - ], - "run_job_task": [], - "schedule": [], - "spark_jar_task": [], - "spark_python_task": [], - "spark_submit_task": [], - "tags": null, - "task": [ - { - "ai_runtime_task": [], - "alert_task": [], - "clean_rooms_notebook_task": [], - "compute": [], - "condition_task": [], - "dashboard_task": [], - "dbt_cloud_task": [], - "dbt_platform_task": [], - "dbt_task": [], - "depends_on": [], - "description": "", - "disable_auto_optimization": false, - "disabled": false, - "email_notifications": [ - { - "no_alert_for_skipped_runs": false, - "on_duration_warning_threshold_exceeded": [], - "on_failure": [], - "on_start": [], - "on_streaming_backlog_exceeded": [], - "on_success": [] - } - ], - "environment_key": "", - "existing_cluster_id": "", - "for_each_task": [], - "gen_ai_compute_task": [], - "health": [], - "job_cluster_key": "", - "library": [], - "max_retries": 0, - "min_retry_interval_millis": 0, - "new_cluster": [], - "notebook_task": [ - { - "base_parameters": null, - "notebook_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files/notebook", - "source": "WORKSPACE", - "warehouse_id": "" - } - ], - "notification_settings": [], - "pipeline_task": [], - "power_bi_task": [], - "python_operator_task": [], - "python_wheel_task": [], - "retry_on_timeout": false, - "run_if": "ALL_SUCCESS", - "run_job_task": [], - "spark_jar_task": [], - "spark_python_task": [], - "spark_submit_task": [], - "sql_task": [], - "task_key": "main", - "timeout_seconds": 0, - "webhook_notifications": [] - } - ], - "timeout_seconds": 0, - "timeouts": null, - "trigger": [], - "triggers": [], - "url": "[DATABRICKS_URL]/#job/[NUMID]", - "usage_policy_id": null, - "webhook_notifications": [ - { - "on_duration_warning_threshold_exceeded": [], - "on_failure": [], - "on_start": [], - "on_streaming_backlog_exceeded": [], - "on_success": [] - } - ] - }, - "sensitive_attributes": [], - "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" - } + {"schema_version": 2, "attributes": {"id": "[NUMID]", "name": "Test Migration Job", "timeout_seconds": 0}} ] }, { "mode": "managed", - "type": "databricks_pipeline", - "name": "test_pipeline", + "type": "databricks_volume", + "name": "test_volume", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 0, - "attributes": { - "allow_duplicate_names": false, - "budget_policy_id": null, - "catalog": null, - "cause": null, - "channel": "CURRENT", - "cluster": [], - "cluster_id": null, - "configuration": null, - "continuous": false, - "creator_user_name": "[USERNAME]", - "deployment": [ - { - "deployment_id": "", - "kind": "BUNDLE", - "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/state/metadata.json", - "version_id": "" - } - ], - "development": false, - "edition": "ADVANCED", - "environment": [], - "event_log": [], - "expected_last_modified": 0, - "filters": [], - "gateway_definition": [], - "health": null, - "id": "[UUID]", - "ingestion_definition": [], - "last_modified": [UNIX_TIME_MILLIS], - "latest_updates": null, - "library": [ - { - "file": [], - "glob": [], - "jar": "", - "maven": [], - "notebook": [ - { - "path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files/pipeline" - } - ], - "whl": "" - } - ], - "name": "Test Migration Pipeline", - "notification": [], - "photon": false, - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "restart_window": [], - "root_path": null, - "run_as": [], - "run_as_user_name": "[USERNAME]", - "schema": null, - "serverless": false, - "serverless_compute_id": null, - "state": "IDLE", - "storage": "dbfs:/pipelines/[UUID]", - "tags": { - "myjob_id": "[NUMID]", - "myjob_name": "Test Migration Job", - "myjob_timeout": "0", - "myvolume_id": "mycat.myschema.myvol", - "volume_catalog_name": "mycat", - "volume_storage_location": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]" - }, - "target": null, - "timeouts": null, - "trigger": [], - "url": "[DATABRICKS_URL]/#joblist/pipelines/[UUID]", - "usage_policy_id": null - }, - "sensitive_attributes": [], - "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19", - "dependencies": [ - "databricks_job.test_job", - "databricks_volume.test_volume" - ] - } + {"schema_version": 0, "attributes": {"id": "mycat.myschema.myvol", "name": "myvol", "catalog_name": "mycat", "schema_name": "myschema", "volume_type": "MANAGED", "storage_location": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]"}} ] }, { "mode": "managed", - "type": "databricks_volume", - "name": "test_volume", + "type": "databricks_pipeline", + "name": "test_pipeline", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 0, - "attributes": { - "catalog_name": "mycat", - "comment": null, - "id": "mycat.myschema.myvol", - "name": "myvol", - "owner": "[USERNAME]", - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "schema_name": "myschema", - "storage_location": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]", - "volume_path": "/Volumes/mycat/myschema/myvol", - "volume_type": "MANAGED" - }, - "sensitive_attributes": [], - "private": "bnVsbA==" - } + {"schema_version": 0, "attributes": {"id": "[UUID]", "name": "Test Migration Pipeline"}} ] } - ], - "check_results": null + ] } diff --git a/acceptance/bundle/migrate/command/basic/out.plan_update.json b/acceptance/bundle/migrate/command/basic/out.plan_update.json index 0d3be4aacaa..3fb9efb9d5d 100644 --- a/acceptance/bundle/migrate/command/basic/out.plan_update.json +++ b/acceptance/bundle/migrate/command/basic/out.plan_update.json @@ -2,7 +2,7 @@ "plan_version": [PLAN_VERSION], "cli_version": "[CLI_VERSION]", "lineage": "[UUID]", - "serial": 6, + "serial": 7, "plan": { "resources.jobs.test_job": { "action": "update", diff --git a/acceptance/bundle/migrate/command/basic/output.txt b/acceptance/bundle/migrate/command/basic/output.txt index 255894ca479..428f6e2b128 100644 --- a/acceptance/bundle/migrate/command/basic/output.txt +++ b/acceptance/bundle/migrate/command/basic/output.txt @@ -4,13 +4,7 @@ Error: This command migrates the existing Terraform state file (terraform.tfstat To start using direct engine, set "engine: direct" under bundle in your databricks.yml or deploy with DATABRICKS_BUNDLE_ENGINE=direct env var set. ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files... -Created jobs.test_job -Created pipelines.test_pipeline -Created volumes.test_volume -Files: 3 uploaded, 0 deleted -Resources: 3 created, 0 changed, 0 deleted, 0 unchanged +>>> seed_tfstate.py terraform.tfstate >>> [CLI] bundle deployment migrate Success! Migrated 3 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json @@ -27,23 +21,12 @@ To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/dev/resources.js >>> jq .state."resources.pipelines.test_pipeline".state.tags.volume_storage_location out.new_state.json "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]" ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged - ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files... -Files: 2 uploaded, 0 deleted -Resources: 0 created, 0 changed, 0 deleted, 3 unchanged - === Should show that it's already migrated >>> musterr [CLI] bundle deployment migrate Error: already using direct engine -Details: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=6 lineage="[UUID]" - ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged +Details: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=7 lineage="[UUID]" ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan +>>> [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged >>> print_requests.py --get //jobs/get @@ -59,22 +42,10 @@ Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged "job_id": "[NUMID]" } } -{ - "headers": { - "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" - ] - }, - "method": "GET", - "path": "/api/2.2/jobs/get", - "q": { - "job_id": "[NUMID]" - } -} ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deploy +>>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files... -Files: 0 uploaded, 0 deleted +Files: 2 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 3 unchanged >>> print_requests.py --get //jobs/get @@ -84,50 +55,42 @@ Resources: 0 created, 0 changed, 0 deleted, 3 unchanged === Should show that it's already migrated >>> musterr [CLI] bundle deployment migrate Error: already using direct engine -Details: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=6 lineage="[UUID]" +Details: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=7 lineage="[UUID]" ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states -[TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=6 lineage="[UUID]" +>>> [CLI] bundle debug states +[TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=7 lineage="[UUID]" ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states --force-pull -resources.json: remote direct state serial=6 lineage="[UUID]" -[TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=6 lineage="[UUID]" +>>> [CLI] bundle debug states --force-pull +resources.json: remote direct state serial=7 lineage="[UUID]" +[TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=7 lineage="[UUID]" === Extra plan: should have no drift ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan +>>> [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged === Update databricks.yml, run plan & update >>> update_file.py databricks.yml Migration Migrated ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan +>>> [CLI] bundle plan update jobs.test_job update pipelines.test_pipeline Plan: 0 to add, 2 to change, 0 to delete, 1 unchanged ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan -o json +>>> [CLI] bundle plan -o json ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deploy +>>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files... Updated jobs.test_job Updated pipelines.test_pipeline Files: 2 uploaded, 0 deleted Resources: 0 created, 2 changed, 0 deleted, 1 unchanged -=== Different target, still on terraform ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -t prod -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/prod/files... -Created jobs.test_job -Created pipelines.test_pipeline -Created schemas.test_schema -Created volumes.test_volume -Files: 6 uploaded, 0 deleted -Resources: 4 created, 0 changed, 0 deleted, 0 unchanged - ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states -t prod -[TEST_TMP_DIR]/.databricks/bundle/prod/terraform/terraform.tfstate: local terraform state serial=5 lineage="[UUID]" - ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states -t prod --force-pull -terraform.tfstate: remote terraform state serial=5 lineage="[UUID]" -[TEST_TMP_DIR]/.databricks/bundle/prod/terraform/terraform.tfstate: local terraform state serial=5 lineage="[UUID]" +=== Different target: seed prod (a schema) as its own terraform deployment +>>> seed_tfstate.py terraform-prod.tfstate -t prod + +>>> [CLI] bundle debug states -t prod +[TEST_TMP_DIR]/.databricks/bundle/prod/terraform/terraform.tfstate: local terraform state serial=1 lineage="[UUID]" + +>>> [CLI] bundle debug states -t prod --force-pull +[TEST_TMP_DIR]/.databricks/bundle/prod/terraform/terraform.tfstate: local terraform state serial=1 lineage="[UUID]" diff --git a/acceptance/bundle/migrate/command/basic/script b/acceptance/bundle/migrate/command/basic/script index a9944a5a4d8..a0b330620b0 100755 --- a/acceptance/bundle/migrate/command/basic/script +++ b/acceptance/bundle/migrate/command/basic/script @@ -2,7 +2,14 @@ export DATABRICKS_BUNDLE_ENGINE= # Migrating without state, should print a message about missing state. trace musterr $CLI bundle deployment migrate -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +trace seed_tfstate.py terraform.tfstate + +# The pipeline tags reference the volume's remote-computed storage_location, which the direct +# state does not persist; read it from the backend and inject it into the seeded terraform state, +# as a real terraform state would carry it, so the migration resolves the tag to the deployed value. +VOL_SL=$($CLI volumes read mycat.myschema.myvol | jq -r .storage_location) +update_file.py .databricks/bundle/dev/terraform/terraform.tfstate __VOLUME_SL__ "$VOL_SL" + print_state.py -t dev > out.original_state.json trace $CLI bundle deployment migrate 2>&1 | contains.py 'Migrated 3 resources' @@ -14,41 +21,36 @@ rm out.backup_state.json # check that this is stored as resolved value, not as reference: trace jq '.state."resources.pipelines.test_pipeline".state.tags.volume_storage_location' out.new_state.json | contains.py 's3://' -# this is expected to warn because state does not match env var, but still succeed using state engine -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle plan -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy - title "Should show that it's already migrated" trace musterr $CLI bundle deployment migrate rm "$OUT_REQUESTS" -# Both DATABRICKS_BUNDLE_ENGINE=direct and DATABRICKS_BUNDLE_ENGINE= work -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "3 unchanged" -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan | contains.py "3 unchanged" +# The migrated deploy runs on the direct engine whether or not DATABRICKS_BUNDLE_ENGINE is set. +trace $CLI bundle plan | contains.py "3 unchanged" trace print_requests.py --get //jobs/get | contains.py 'engine/direct' -trace DATABRICKS_BUNDLE_ENGINE="" $CLI bundle deploy +trace $CLI bundle deploy trace print_requests.py --get //jobs/get | jq '.headers["User-Agent"][0]' | contains.py 'engine/direct' title "Should show that it's already migrated" trace musterr $CLI bundle deployment migrate -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states --force-pull +trace $CLI bundle debug states +trace $CLI bundle debug states --force-pull title "Extra plan: should have no drift" -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan | contains.py "3 unchanged" +trace $CLI bundle plan | contains.py "3 unchanged" rm "$OUT_REQUESTS" title "Update databricks.yml, run plan & update" trace update_file.py databricks.yml Migration Migrated -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan -o json | nostamp > out.plan_update.json -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle deploy - -title "Different target, still on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy -t prod -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states -t prod -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states -t prod --force-pull +trace $CLI bundle plan +trace $CLI bundle plan -o json | nostamp > out.plan_update.json +trace $CLI bundle deploy + +title "Different target: seed prod (a schema) as its own terraform deployment" +trace seed_tfstate.py terraform-prod.tfstate -t prod +trace $CLI bundle debug states -t prod +trace $CLI bundle debug states -t prod --force-pull rm "$OUT_REQUESTS" diff --git a/acceptance/bundle/migrate/command/basic/terraform-prod.tfstate b/acceptance/bundle/migrate/command/basic/terraform-prod.tfstate new file mode 100644 index 00000000000..de89d7d08de --- /dev/null +++ b/acceptance/bundle/migrate/command/basic/terraform-prod.tfstate @@ -0,0 +1,17 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "a1b2c3d4-0000-4000-8000-00000000000b", + "resources": [ + { + "mode": "managed", + "type": "databricks_schema", + "name": "test_schema", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.schemas.test_schema__", "name": "myschema", "catalog_name": "mycat"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/command/basic/terraform.tfstate b/acceptance/bundle/migrate/command/basic/terraform.tfstate new file mode 100644 index 00000000000..98f479aabf1 --- /dev/null +++ b/acceptance/bundle/migrate/command/basic/terraform.tfstate @@ -0,0 +1,35 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 5, + "lineage": "a1b2c3d4-0000-4000-8000-00000000000a", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 2, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Migration Job", "timeout_seconds": 0}} + ] + }, + { + "mode": "managed", + "type": "databricks_volume", + "name": "test_volume", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.volumes.test_volume__", "name": "myvol", "catalog_name": "mycat", "schema_name": "myschema", "volume_type": "MANAGED", "storage_location": "__VOLUME_SL__"}} + ] + }, + { + "mode": "managed", + "type": "databricks_pipeline", + "name": "test_pipeline", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.pipelines.test_pipeline__", "name": "Test Migration Pipeline"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/command/dashboards/out.new_state.json b/acceptance/bundle/migrate/command/dashboards/out.new_state.json index c1bdc4c7b78..1f4a4cbbceb 100644 --- a/acceptance/bundle/migrate/command/dashboards/out.new_state.json +++ b/acceptance/bundle/migrate/command/dashboards/out.new_state.json @@ -2,7 +2,7 @@ "state_version": 3, "cli_version": "[CLI_VERSION]", "lineage": "[UUID]", - "serial": 3, + "serial": 5, "state": { "resources.dashboards.dashboard1": { "__id__": "[DASHBOARD1_ID]", diff --git a/acceptance/bundle/migrate/command/dashboards/out.original_state.json b/acceptance/bundle/migrate/command/dashboards/out.original_state.json index 588895fb3c5..e7cb38b3344 100644 --- a/acceptance/bundle/migrate/command/dashboards/out.original_state.json +++ b/acceptance/bundle/migrate/command/dashboards/out.original_state.json @@ -1,9 +1,8 @@ { "version": 4, "terraform_version": "1.5.5", - "serial": 1, + "serial": 3, "lineage": "[UUID]", - "outputs": {}, "resources": [ { "mode": "managed", @@ -14,34 +13,14 @@ { "schema_version": 0, "attributes": { - "create_time": "[TIMESTAMP]", - "dashboard_change_detected": false, - "dashboard_id": "[DASHBOARD1_ID]", - "dataset_catalog": null, - "dataset_schema": null, - "display_name": "my dashboard", - "embed_credentials": true, - "etag": "[NUMID]", - "file_path": null, "id": "[DASHBOARD1_ID]", - "lifecycle_state": "ACTIVE", - "md5": "b4ab6aee48485b0b5e980761d3efe936", + "display_name": "my dashboard", "parent_path": "/Users/[USERNAME]", - "path": "/Users/[USERNAME]/my dashboard.lvdash.json", - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "serialized_dashboard": "{\"pages\":[{\"displayName\":\"Dashboard test bundle-deploy-dashboard\",\"name\":\"02724bf2\",\"pageType\":\"PAGE_TYPE_CANVAS\"}]}\n", - "update_time": "[TIMESTAMP]", - "warehouse_id": "123456" - }, - "sensitive_attributes": [], - "private": "bnVsbA==" + "warehouse_id": "123456", + "etag": "[NUMID]" + } } ] } - ], - "check_results": null + ] } diff --git a/acceptance/bundle/migrate/command/dashboards/out.plan_after_migrate.json b/acceptance/bundle/migrate/command/dashboards/out.plan_after_migrate.json index 37124a4c407..5daff995d26 100644 --- a/acceptance/bundle/migrate/command/dashboards/out.plan_after_migrate.json +++ b/acceptance/bundle/migrate/command/dashboards/out.plan_after_migrate.json @@ -2,7 +2,7 @@ "plan_version": [PLAN_VERSION], "cli_version": "[CLI_VERSION]", "lineage": "[UUID]", - "serial": 3, + "serial": 5, "plan": { "resources.dashboards.dashboard1": { "action": "skip", diff --git a/acceptance/bundle/migrate/command/dashboards/output.txt b/acceptance/bundle/migrate/command/dashboards/output.txt index a5960b911f5..8c201df2b7e 100644 --- a/acceptance/bundle/migrate/command/dashboards/output.txt +++ b/acceptance/bundle/migrate/command/dashboards/output.txt @@ -1,9 +1,5 @@ ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created dashboards.dashboard1 -Files: 2 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +>>> seed_tfstate.py terraform.tfstate >>> [CLI] bundle deployment migrate Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json @@ -15,39 +11,7 @@ The state file is not synchronized to the workspace yet. To do that and finalize To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/default/resources.json and rename [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate.backup to [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle plan +>>> [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Files: 2 uploaded, 0 deleted -Resources: 0 created, 0 changed, 0 deleted, 1 unchanged - ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged - ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged - ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan -o json - ->>> print_requests.py --get //dashboards - ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deploy --auto-approve -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Files: 1 uploaded, 0 deleted -Resources: 0 created, 0 changed, 0 deleted, 1 unchanged - ->>> print_requests.py --get //dashboards - -=== Should show that it's already migrated ->>> musterr [CLI] bundle deployment migrate -Error: already using direct engine -Details: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=3 lineage="[UUID]" - ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states -[TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=3 lineage="[UUID]" - ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states --force-pull -resources.json: remote direct state serial=3 lineage="[UUID]" -[TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=3 lineage="[UUID]" +>>> [CLI] bundle plan -o json diff --git a/acceptance/bundle/migrate/command/dashboards/script b/acceptance/bundle/migrate/command/dashboards/script index 68fc6883eb3..e12785cff1f 100755 --- a/acceptance/bundle/migrate/command/dashboards/script +++ b/acceptance/bundle/migrate/command/dashboards/script @@ -1,4 +1,5 @@ -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +export DATABRICKS_BUNDLE_ENGINE= +trace seed_tfstate.py terraform.tfstate # Add all resource IDs to runtime replacements to avoid pattern matching ambiguity replace_ids.py print_state.py > out.original_state.json @@ -6,33 +7,7 @@ print_state.py > out.original_state.json trace $CLI bundle deployment migrate 2>&1 | contains.py 'Migrated 1 resources' print_state.py > out.new_state.json -# this is expected to warn because state does not match env var, but still succeed using state engine -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle plan -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy - rm "$OUT_REQUESTS" -# Both DATABRICKS_BUNDLE_ENGINE=direct and DATABRICKS_BUNDLE_ENGINE= work # Badness: known issue with dashboards, will show up as 'recreate' see https://github.com/databricks/cli/pull/3966 -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "1 unchanged" -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan | contains.py "1 unchanged" -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan -o json | nostamp > out.plan_after_migrate.json -trace print_requests.py --get //dashboards | contains.py 'engine/direct' > /dev/null - -trace DATABRICKS_BUNDLE_ENGINE="" $CLI bundle deploy --auto-approve -trace print_requests.py --get //dashboards | jq '.headers["User-Agent"][0]' | contains.py 'engine/direct' > /dev/null - -title "Should show that it's already migrated" -trace musterr $CLI bundle deployment migrate -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states --force-pull - -rm "$OUT_REQUESTS" - -# Uncomment once 'recreate' bug is fixed -#title "Update databricks.yml, run plan & update" -#trace update_file.py databricks.yml dashboard DASHBOARD -#trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan -#trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan -o json | nostamp > out.plan_update.json -#trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle deploy - -#rm "$OUT_REQUESTS" +trace $CLI bundle plan | contains.py "1 unchanged" +trace $CLI bundle plan -o json | nostamp > out.plan_after_migrate.json diff --git a/acceptance/bundle/migrate/command/dashboards/terraform.tfstate b/acceptance/bundle/migrate/command/dashboards/terraform.tfstate new file mode 100644 index 00000000000..c7fd7f8f99a --- /dev/null +++ b/acceptance/bundle/migrate/command/dashboards/terraform.tfstate @@ -0,0 +1,26 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 3, + "lineage": "a1b2c3d4-0000-4000-8000-000000000009", + "resources": [ + { + "mode": "managed", + "type": "databricks_dashboard", + "name": "dashboard1", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "__ID_resources.dashboards.dashboard1__", + "display_name": "my dashboard", + "parent_path": "/Users/tester@databricks.com", + "warehouse_id": "123456", + "etag": __ATTR{resources.dashboards.dashboard1}{etag}__ + } + } + ] + } + ] +} diff --git a/acceptance/bundle/migrate/command/default-python/out.state_original.json b/acceptance/bundle/migrate/command/default-python/out.state_original.json index 1363591874f..2e027b7c2db 100644 --- a/acceptance/bundle/migrate/command/default-python/out.state_original.json +++ b/acceptance/bundle/migrate/command/default-python/out.state_original.json @@ -3,7 +3,6 @@ "terraform_version": "1.5.5", "serial": 3, "lineage": "[UUID]", - "outputs": {}, "resources": [ { "mode": "managed", @@ -11,395 +10,7 @@ "name": "sample_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 2, - "attributes": { - "always_running": false, - "budget_policy_id": null, - "continuous": [], - "control_run_state": false, - "dbt_task": [], - "deployment": [ - { - "deployment_id": "", - "kind": "BUNDLE", - "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/state/metadata.json", - "version_id": "" - } - ], - "description": null, - "edit_mode": "UI_LOCKED", - "email_notifications": [ - { - "no_alert_for_skipped_runs": false, - "on_duration_warning_threshold_exceeded": [], - "on_failure": [], - "on_start": [], - "on_streaming_backlog_exceeded": [], - "on_success": [] - } - ], - "environment": [], - "existing_cluster_id": null, - "format": "MULTI_TASK", - "git_source": [], - "health": [], - "id": "[NUMID]", - "job_cluster": [ - { - "job_cluster_key": "job_cluster", - "new_cluster": [ - { - "__apply_policy_default_values_allow_list": null, - "apply_policy_default_values": false, - "autoscale": [ - { - "max_workers": 4, - "min_workers": 1 - } - ], - "aws_attributes": [], - "azure_attributes": [], - "cluster_id": "", - "cluster_log_conf": [], - "cluster_mount_info": [], - "cluster_name": "", - "custom_tags": null, - "data_security_mode": "DATA_SECURITY_MODE_AUTO", - "dependency_mode": "", - "docker_image": [], - "driver_instance_pool_id": "", - "driver_node_type_flexibility": [], - "driver_node_type_id": "", - "enable_elastic_disk": false, - "enable_local_disk_encryption": false, - "gcp_attributes": [], - "idempotency_token": "", - "init_scripts": [], - "instance_pool_id": "", - "is_single_node": false, - "kind": "", - "library": [], - "node_type_id": "[NODE_TYPE_ID]", - "num_workers": 0, - "policy_id": "", - "provider_config": [], - "remote_disk_throughput": 0, - "runtime_engine": "", - "single_user_name": "", - "spark_conf": null, - "spark_env_vars": null, - "spark_version": "16.4.x-scala2.12", - "ssh_public_keys": null, - "total_initial_remote_disk_size": 0, - "use_ml_runtime": false, - "worker_node_type_flexibility": [], - "workload_type": [] - } - ], - "serverless_compute_id": "" - } - ], - "library": [], - "max_concurrent_runs": 4, - "max_retries": 0, - "min_retry_interval_millis": 0, - "name": "[dev [USERNAME]] sample_job", - "new_cluster": [], - "notebook_task": [], - "notification_settings": [], - "parameter": [ - { - "default": "hive_metastore", - "name": "catalog" - }, - { - "default": "[USERNAME]", - "name": "schema" - } - ], - "parent_path": null, - "performance_target": null, - "pipeline_task": [], - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "python_wheel_task": [], - "queue": [ - { - "enabled": true - } - ], - "retry_on_timeout": false, - "run_as": [ - { - "group_name": "", - "service_principal_name": "", - "user_name": "[USERNAME]" - } - ], - "run_job_task": [], - "schedule": [], - "spark_jar_task": [], - "spark_python_task": [], - "spark_submit_task": [], - "tags": { - "dev": "[USERNAME]" - }, - "task": [ - { - "ai_runtime_task": [], - "alert_task": [], - "clean_rooms_notebook_task": [], - "compute": [], - "condition_task": [], - "dashboard_task": [], - "dbt_cloud_task": [], - "dbt_platform_task": [], - "dbt_task": [], - "depends_on": [], - "description": "", - "disable_auto_optimization": false, - "disabled": false, - "email_notifications": [ - { - "no_alert_for_skipped_runs": false, - "on_duration_warning_threshold_exceeded": [], - "on_failure": [], - "on_start": [], - "on_streaming_backlog_exceeded": [], - "on_success": [] - } - ], - "environment_key": "", - "existing_cluster_id": "", - "for_each_task": [], - "gen_ai_compute_task": [], - "health": [], - "job_cluster_key": "job_cluster", - "library": [ - { - "cran": [], - "egg": "", - "jar": "", - "maven": [], - "provider_config": [], - "pypi": [], - "requirements": "", - "whl": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl" - } - ], - "max_retries": 0, - "min_retry_interval_millis": 0, - "new_cluster": [], - "notebook_task": [ - { - "base_parameters": null, - "notebook_path": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/files/src/sample_notebook", - "source": "WORKSPACE", - "warehouse_id": "" - } - ], - "notification_settings": [], - "pipeline_task": [], - "power_bi_task": [], - "python_operator_task": [], - "python_wheel_task": [], - "retry_on_timeout": false, - "run_if": "ALL_SUCCESS", - "run_job_task": [], - "spark_jar_task": [], - "spark_python_task": [], - "spark_submit_task": [], - "sql_task": [], - "task_key": "notebook_task", - "timeout_seconds": 0, - "webhook_notifications": [] - }, - { - "ai_runtime_task": [], - "alert_task": [], - "clean_rooms_notebook_task": [], - "compute": [], - "condition_task": [], - "dashboard_task": [], - "dbt_cloud_task": [], - "dbt_platform_task": [], - "dbt_task": [], - "depends_on": [ - { - "outcome": "", - "task_key": "notebook_task" - } - ], - "description": "", - "disable_auto_optimization": false, - "disabled": false, - "email_notifications": [ - { - "no_alert_for_skipped_runs": false, - "on_duration_warning_threshold_exceeded": [], - "on_failure": [], - "on_start": [], - "on_streaming_backlog_exceeded": [], - "on_success": [] - } - ], - "environment_key": "", - "existing_cluster_id": "", - "for_each_task": [], - "gen_ai_compute_task": [], - "health": [], - "job_cluster_key": "job_cluster", - "library": [ - { - "cran": [], - "egg": "", - "jar": "", - "maven": [], - "provider_config": [], - "pypi": [], - "requirements": "", - "whl": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl" - } - ], - "max_retries": 0, - "min_retry_interval_millis": 0, - "new_cluster": [], - "notebook_task": [], - "notification_settings": [], - "pipeline_task": [], - "power_bi_task": [], - "python_operator_task": [], - "python_wheel_task": [ - { - "entry_point": "main", - "named_parameters": null, - "package_name": "my_default_python", - "parameters": [ - "--catalog", - "hive_metastore", - "--schema", - "[USERNAME]" - ] - } - ], - "retry_on_timeout": false, - "run_if": "ALL_SUCCESS", - "run_job_task": [], - "spark_jar_task": [], - "spark_python_task": [], - "spark_submit_task": [], - "sql_task": [], - "task_key": "python_wheel_task", - "timeout_seconds": 0, - "webhook_notifications": [] - }, - { - "ai_runtime_task": [], - "alert_task": [], - "clean_rooms_notebook_task": [], - "compute": [], - "condition_task": [], - "dashboard_task": [], - "dbt_cloud_task": [], - "dbt_platform_task": [], - "dbt_task": [], - "depends_on": [ - { - "outcome": "", - "task_key": "notebook_task" - } - ], - "description": "", - "disable_auto_optimization": false, - "disabled": false, - "email_notifications": [ - { - "no_alert_for_skipped_runs": false, - "on_duration_warning_threshold_exceeded": [], - "on_failure": [], - "on_start": [], - "on_streaming_backlog_exceeded": [], - "on_success": [] - } - ], - "environment_key": "", - "existing_cluster_id": "", - "for_each_task": [], - "gen_ai_compute_task": [], - "health": [], - "job_cluster_key": "", - "library": [], - "max_retries": 0, - "min_retry_interval_millis": 0, - "new_cluster": [], - "notebook_task": [], - "notification_settings": [], - "pipeline_task": [ - { - "full_refresh": false, - "full_refresh_selection": null, - "parameters": null, - "pipeline_id": "[UUID]", - "refresh_flow_selection": null, - "refresh_selection": null, - "reset_checkpoint_selection": null - } - ], - "power_bi_task": [], - "python_operator_task": [], - "python_wheel_task": [], - "retry_on_timeout": false, - "run_if": "ALL_SUCCESS", - "run_job_task": [], - "spark_jar_task": [], - "spark_python_task": [], - "spark_submit_task": [], - "sql_task": [], - "task_key": "refresh_pipeline", - "timeout_seconds": 0, - "webhook_notifications": [] - } - ], - "timeout_seconds": 0, - "timeouts": null, - "trigger": [ - { - "file_arrival": [], - "model": [], - "pause_status": "PAUSED", - "periodic": [ - { - "interval": 1, - "unit": "DAYS" - } - ], - "sql_condition": [], - "table_update": [] - } - ], - "triggers": [], - "url": "[DATABRICKS_URL]/#job/[NUMID]", - "usage_policy_id": null, - "webhook_notifications": [ - { - "on_duration_warning_threshold_exceeded": [], - "on_failure": [], - "on_start": [], - "on_streaming_backlog_exceeded": [], - "on_success": [] - } - ] - }, - "sensitive_attributes": [], - "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==", - "dependencies": [ - "databricks_pipeline.my_default_python_etl" - ] - } + {"schema_version": 2, "attributes": {"id": "[NUMID]", "name": "sample_job"}} ] }, { @@ -408,91 +19,8 @@ "name": "my_default_python_etl", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 0, - "attributes": { - "allow_duplicate_names": false, - "budget_policy_id": null, - "catalog": null, - "cause": null, - "channel": "CURRENT", - "cluster": [], - "cluster_id": null, - "configuration": null, - "continuous": false, - "creator_user_name": "[USERNAME]", - "deployment": [ - { - "deployment_id": "", - "kind": "BUNDLE", - "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/state/metadata.json", - "version_id": "" - } - ], - "development": true, - "edition": "ADVANCED", - "environment": [ - { - "dependencies": [ - "--editable /Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/files" - ], - "environment_version": "" - } - ], - "event_log": [], - "expected_last_modified": 0, - "filters": [], - "gateway_definition": [], - "health": null, - "id": "[UUID]", - "ingestion_definition": [], - "last_modified": [UNIX_TIME_MILLIS], - "latest_updates": null, - "library": [ - { - "file": [], - "glob": [ - { - "include": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/files/src/my_default_python_etl/transformations/**" - } - ], - "jar": "", - "maven": [], - "notebook": [], - "whl": "" - } - ], - "name": "[dev [USERNAME]] my_default_python_etl", - "notification": [], - "photon": false, - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "restart_window": [], - "root_path": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/files/src/my_default_python_etl", - "run_as": [], - "run_as_user_name": "[USERNAME]", - "schema": "[USERNAME]", - "serverless": false, - "serverless_compute_id": null, - "state": "IDLE", - "storage": "dbfs:/pipelines/[UUID]", - "tags": { - "dev": "[USERNAME]" - }, - "target": null, - "timeouts": null, - "trigger": [], - "url": "[DATABRICKS_URL]/#joblist/pipelines/[UUID]", - "usage_policy_id": null - }, - "sensitive_attributes": [], - "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19" - } + {"schema_version": 0, "attributes": {"id": "[UUID]", "name": "my_default_python_etl"}} ] } - ], - "check_results": null + ] } diff --git a/acceptance/bundle/migrate/command/default-python/output.txt b/acceptance/bundle/migrate/command/default-python/output.txt index 14fc40642c7..409384c510f 100644 --- a/acceptance/bundle/migrate/command/default-python/output.txt +++ b/acceptance/bundle/migrate/command/default-python/output.txt @@ -12,14 +12,7 @@ Note that [DATABRICKS_URL] is used for initialization. To get started, refer to the project README.md file and the documentation at https://docs.databricks.com/dev-tools/bundles/index.html. ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Building python_artifact... -Uploading .databricks/bundle/dev/patched_wheels/python_artifact_my_default_python/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl... -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/files... -Created jobs.sample_job -Created pipelines.my_default_python_etl -Files: 21 uploaded, 0 deleted -Resources: 2 created, 0 changed, 0 deleted, 0 unchanged +>>> seed_tfstate.py ../terraform.tfstate >>> print_state.py @@ -39,12 +32,12 @@ To undo the migration, remove [TEST_TMP_DIR]/my_default_python/.databricks/bundl >>> jq .. | .libraries? | select(.) ../out.state_after_migration.json [ { - "whl": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][1]-py3-none-any.whl" + "whl": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl" } ] [ { - "whl": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][1]-py3-none-any.whl" + "whl": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl" } ] [ @@ -55,13 +48,13 @@ To undo the migration, remove [TEST_TMP_DIR]/my_default_python/.databricks/bundl } ] ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan +>>> [CLI] bundle plan Building python_artifact... update jobs.sample_job Plan: 0 to add, 1 to change, 0 to delete, 1 unchanged ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan -o json +>>> [CLI] bundle plan -o json Building python_artifact... >>> jq .plan[] | .changes ../out.plan_after_migration.json @@ -78,9 +71,9 @@ Building python_artifact... }, "tasks[task_key='notebook_task'].libraries[0].whl": { "action": "update", - "old": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][1]-py3-none-any.whl", - "new": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][2]-py3-none-any.whl", - "remote": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl" + "old": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl", + "new": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][1]-py3-none-any.whl", + "remote": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][2]-py3-none-any.whl" }, "tasks[task_key='notebook_task'].notebook_task.source": { "action": "skip", @@ -104,9 +97,9 @@ Building python_artifact... }, "tasks[task_key='python_wheel_task'].libraries[0].whl": { "action": "update", - "old": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][1]-py3-none-any.whl", - "new": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][2]-py3-none-any.whl", - "remote": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl" + "old": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl", + "new": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][1]-py3-none-any.whl", + "remote": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][2]-py3-none-any.whl" }, "tasks[task_key='python_wheel_task'].run_if": { "action": "skip", @@ -152,7 +145,7 @@ Building python_artifact... } } ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deploy +>>> [CLI] bundle deploy Building python_artifact... Uploading .databricks/bundle/dev/patched_wheels/python_artifact_my_default_python/my_default_python-0.0.1+[UNIX_TIME_NANOS][3]-py3-none-any.whl... Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/files... @@ -174,13 +167,13 @@ Resources: 0 created, 1 changed, 0 deleted, 1 unchanged "resources.jobs.sample_job": { === Extra plan: should have no drift ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan +>>> [CLI] bundle plan Building python_artifact... update jobs.sample_job Plan: 0 to add, 1 to change, 0 to delete, 1 unchanged ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan -o json +>>> [CLI] bundle plan -o json Building python_artifact... >>> jq .plan[] | .changes ../out.plan_after_migration.json @@ -197,9 +190,9 @@ Building python_artifact... }, "tasks[task_key='notebook_task'].libraries[0].whl": { "action": "update", - "old": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][1]-py3-none-any.whl", - "new": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][2]-py3-none-any.whl", - "remote": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl" + "old": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl", + "new": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][1]-py3-none-any.whl", + "remote": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][2]-py3-none-any.whl" }, "tasks[task_key='notebook_task'].notebook_task.source": { "action": "skip", @@ -223,9 +216,9 @@ Building python_artifact... }, "tasks[task_key='python_wheel_task'].libraries[0].whl": { "action": "update", - "old": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][1]-py3-none-any.whl", - "new": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][2]-py3-none-any.whl", - "remote": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl" + "old": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl", + "new": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][1]-py3-none-any.whl", + "remote": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][2]-py3-none-any.whl" }, "tasks[task_key='python_wheel_task'].run_if": { "action": "skip", diff --git a/acceptance/bundle/migrate/command/default-python/script b/acceptance/bundle/migrate/command/default-python/script index f3a4ca0c37c..9c5e0c1f6d5 100755 --- a/acceptance/bundle/migrate/command/default-python/script +++ b/acceptance/bundle/migrate/command/default-python/script @@ -2,7 +2,8 @@ export DATABRICKS_BUNDLE_ENGINE= trace $CLI bundle init default-python --config-file ./input.json cd my_default_python -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +# Seed a prior terraform deployment of the generated template (job + pipeline). +trace seed_tfstate.py ../terraform.tfstate trace print_state.py > ../out.state_original.json trace $CLI bundle deployment migrate @@ -10,16 +11,16 @@ trace $CLI bundle deployment migrate trace print_state.py > ../out.state_after_migration.json trace jq '.. | .libraries? | select(.)' ../out.state_after_migration.json -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan -o json | nostamp > ../out.plan_after_migration.json +trace $CLI bundle plan +trace $CLI bundle plan -o json | nostamp > ../out.plan_after_migration.json trace jq '.plan[] | .changes' ../out.plan_after_migration.json # Badness: contains changes for whl and num_workers -trace DATABRICKS_BUNDLE_ENGINE="" $CLI bundle deploy +trace $CLI bundle deploy trace print_state.py > ../out.state_after_deploy.json trace diff.py ../out.state_after_migration.json ../out.state_after_deploy.json rm ../out.state_after_deploy.json title "Extra plan: should have no drift" -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan -o json | nostamp > ../out.plan_after_deploy.json +trace $CLI bundle plan +trace $CLI bundle plan -o json | nostamp > ../out.plan_after_deploy.json trace jq '.plan[] | .changes' ../out.plan_after_migration.json # Badness: contains changes for whl diff --git a/acceptance/bundle/migrate/command/default-python/terraform.tfstate b/acceptance/bundle/migrate/command/default-python/terraform.tfstate new file mode 100644 index 00000000000..082728721e6 --- /dev/null +++ b/acceptance/bundle/migrate/command/default-python/terraform.tfstate @@ -0,0 +1,26 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 3, + "lineage": "a1b2c3d4-0000-4000-8000-00000000000d", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "sample_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 2, "attributes": {"id": "__ID_resources.jobs.sample_job__", "name": "sample_job"}} + ] + }, + { + "mode": "managed", + "type": "databricks_pipeline", + "name": "my_default_python_etl", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.pipelines.my_default_python_etl__", "name": "my_default_python_etl"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/command/grants/out.original_state.json b/acceptance/bundle/migrate/command/grants/out.original_state.json index 8aee4f3e101..ff5cdf4d58a 100644 --- a/acceptance/bundle/migrate/command/grants/out.original_state.json +++ b/acceptance/bundle/migrate/command/grants/out.original_state.json @@ -3,263 +3,60 @@ "terraform_version": "1.5.5", "serial": 7, "lineage": "[UUID]", - "outputs": {}, "resources": [ { "mode": "managed", - "type": "databricks_grants", - "name": "registered_model_my_registered_model", + "type": "databricks_schema", + "name": "my_schema", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 0, - "attributes": { - "catalog": null, - "credential": null, - "external_location": null, - "foreign_connection": null, - "function": "main.schema_grants.mymodel", - "grant": [ - { - "principal": "deco-test-user@databricks.com", - "privileges": [ - "APPLY_TAG" - ] - } - ], - "id": "function/main.schema_grants.mymodel", - "mcp_service": null, - "metastore": null, - "model": null, - "model_provider_service": null, - "model_service": null, - "pipeline": null, - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "recipient": null, - "schema": null, - "secret": null, - "share": null, - "storage_credential": null, - "table": null, - "volume": null - }, - "sensitive_attributes": [], - "private": "bnVsbA==", - "dependencies": [ - "databricks_registered_model.my_registered_model", - "databricks_schema.my_schema" - ] - } + {"schema_version": 0, "attributes": {"id": "main.schema_grants", "name": "schema_grants", "catalog_name": "main"}} ] }, { "mode": "managed", - "type": "databricks_grants", - "name": "schema_my_schema", + "type": "databricks_volume", + "name": "my_volume", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 0, - "attributes": { - "catalog": null, - "credential": null, - "external_location": null, - "foreign_connection": null, - "function": null, - "grant": [ - { - "principal": "deco-test-user@databricks.com", - "privileges": [ - "CREATE_TABLE", - "USE_SCHEMA" - ] - } - ], - "id": "schema/main.schema_grants", - "mcp_service": null, - "metastore": null, - "model": null, - "model_provider_service": null, - "model_service": null, - "pipeline": null, - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "recipient": null, - "schema": "main.schema_grants", - "secret": null, - "share": null, - "storage_credential": null, - "table": null, - "volume": null - }, - "sensitive_attributes": [], - "private": "bnVsbA==", - "dependencies": [ - "databricks_schema.my_schema" - ] - } + {"schema_version": 0, "attributes": {"id": "main.schema_grants.volume_name", "name": "volume_name", "catalog_name": "main", "schema_name": "schema_grants"}} ] }, { "mode": "managed", - "type": "databricks_grants", - "name": "volume_my_volume", + "type": "databricks_registered_model", + "name": "my_registered_model", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 0, - "attributes": { - "catalog": null, - "credential": null, - "external_location": null, - "foreign_connection": null, - "function": null, - "grant": [ - { - "principal": "deco-test-user@databricks.com", - "privileges": [ - "READ_VOLUME", - "WRITE_VOLUME" - ] - } - ], - "id": "volume/main.schema_grants.volume_name", - "mcp_service": null, - "metastore": null, - "model": null, - "model_provider_service": null, - "model_service": null, - "pipeline": null, - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "recipient": null, - "schema": null, - "secret": null, - "share": null, - "storage_credential": null, - "table": null, - "volume": "main.schema_grants.volume_name" - }, - "sensitive_attributes": [], - "private": "bnVsbA==", - "dependencies": [ - "databricks_schema.my_schema", - "databricks_volume.my_volume" - ] - } + {"schema_version": 0, "attributes": {"id": "main.schema_grants.mymodel", "name": "mymodel", "catalog_name": "main", "schema_name": "schema_grants"}} ] }, { "mode": "managed", - "type": "databricks_registered_model", - "name": "my_registered_model", + "type": "databricks_grants", + "name": "schema_my_schema", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 0, - "attributes": { - "aliases": [], - "browse_only": false, - "catalog_name": "main", - "comment": "mycomment", - "created_at": [UNIX_TIME_MILLIS][0], - "created_by": "[USERNAME]", - "full_name": "main.schema_grants.mymodel", - "id": "main.schema_grants.mymodel", - "metastore_id": "[UUID]", - "name": "mymodel", - "owner": "[USERNAME]", - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "schema_name": "schema_grants", - "storage_location": null, - "updated_at": [UNIX_TIME_MILLIS][0], - "updated_by": "[USERNAME]" - }, - "sensitive_attributes": [], - "private": "bnVsbA==", - "dependencies": [ - "databricks_schema.my_schema" - ] - } + {"schema_version": 0, "attributes": {"id": "schema/main.schema_grants"}} ] }, { "mode": "managed", - "type": "databricks_schema", - "name": "my_schema", + "type": "databricks_grants", + "name": "volume_my_volume", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 0, - "attributes": { - "catalog_name": "main", - "comment": null, - "enable_predictive_optimization": "INHERIT", - "force_destroy": true, - "id": "main.schema_grants", - "metastore_id": "[UUID]", - "name": "schema_grants", - "owner": "[USERNAME]", - "properties": null, - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "schema_id": "[UUID]", - "storage_root": null - }, - "sensitive_attributes": [], - "private": "bnVsbA==" - } + {"schema_version": 0, "attributes": {"id": "volume/main.schema_grants.volume_name"}} ] }, { "mode": "managed", - "type": "databricks_volume", - "name": "my_volume", + "type": "databricks_grants", + "name": "registered_model_my_registered_model", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 0, - "attributes": { - "catalog_name": "main", - "comment": null, - "id": "main.schema_grants.volume_name", - "name": "volume_name", - "owner": "[USERNAME]", - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "schema_name": "schema_grants", - "storage_location": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]", - "volume_path": "/Volumes/main/schema_grants/volume_name", - "volume_type": "MANAGED" - }, - "sensitive_attributes": [], - "private": "bnVsbA==", - "dependencies": [ - "databricks_schema.my_schema" - ] - } + {"schema_version": 0, "attributes": {"id": "function/main.schema_grants.mymodel"}} ] } - ], - "check_results": null + ] } diff --git a/acceptance/bundle/migrate/command/grants/output.txt b/acceptance/bundle/migrate/command/grants/output.txt index c83d3d548be..a60965e5a34 100644 --- a/acceptance/bundle/migrate/command/grants/output.txt +++ b/acceptance/bundle/migrate/command/grants/output.txt @@ -1,14 +1,5 @@ ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Created registered_models.my_registered_model -Created registered_models.my_registered_model.grants -Created schemas.my_schema -Created schemas.my_schema.grants -Created volumes.my_volume -Created volumes.my_volume.grants -Files: 1 uploaded, 0 deleted -Resources: 6 created, 0 changed, 0 deleted, 0 unchanged +>>> seed_tfstate.py terraform.tfstate >>> [CLI] bundle deployment migrate Success! Migrated 6 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json @@ -20,25 +11,14 @@ The state file is not synchronized to the workspace yet. To do that and finalize To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/default/resources.json and rename [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate.backup to [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 6 unchanged - ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Files: 2 uploaded, 0 deleted -Resources: 0 created, 0 changed, 0 deleted, 6 unchanged - ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 6 unchanged - ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan +>>> [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 6 unchanged >>> print_requests.py --get //unity-catalog/permissions ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deploy +>>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Files: 0 uploaded, 0 deleted +Files: 2 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 6 unchanged >>> print_requests.py --get //unity-catalog/permissions @@ -48,9 +28,9 @@ Resources: 0 created, 0 changed, 0 deleted, 6 unchanged Error: already using direct engine Details: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=9 lineage="[UUID]" ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states +>>> [CLI] bundle debug states [TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=9 lineage="[UUID]" ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states --force-pull +>>> [CLI] bundle debug states --force-pull resources.json: remote direct state serial=9 lineage="[UUID]" [TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=9 lineage="[UUID]" diff --git a/acceptance/bundle/migrate/command/grants/script b/acceptance/bundle/migrate/command/grants/script index f53b567d1e2..35033b34f0b 100755 --- a/acceptance/bundle/migrate/command/grants/script +++ b/acceptance/bundle/migrate/command/grants/script @@ -1,26 +1,20 @@ export DATABRICKS_BUNDLE_ENGINE= -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +trace seed_tfstate.py terraform.tfstate print_state.py > out.original_state.json trace $CLI bundle deployment migrate 2>&1 | contains.py 'Migrated 6 resources' print_state.py > out.new_state.json -# this is expected to warn because state does not match env var, but still succeed using state engine -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle plan -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy - rm "$OUT_REQUESTS" -# Both DATABRICKS_BUNDLE_ENGINE=direct and DATABRICKS_BUNDLE_ENGINE= work -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "6 unchanged" -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan | contains.py "6 unchanged" +trace $CLI bundle plan | contains.py "6 unchanged" trace print_requests.py --get //unity-catalog/permissions | contains.py 'engine/direct' > /dev/null -trace DATABRICKS_BUNDLE_ENGINE="" $CLI bundle deploy +trace $CLI bundle deploy trace print_requests.py --get //unity-catalog/permissions | jq '.headers["User-Agent"][0]' | contains.py 'engine/direct' > LOG.requests_deploy.txt title "Should show that it's already migrated" trace musterr $CLI bundle deployment migrate -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states --force-pull +trace $CLI bundle debug states +trace $CLI bundle debug states --force-pull rm "$OUT_REQUESTS" diff --git a/acceptance/bundle/migrate/command/grants/terraform.tfstate b/acceptance/bundle/migrate/command/grants/terraform.tfstate new file mode 100644 index 00000000000..fc6ea0a27f1 --- /dev/null +++ b/acceptance/bundle/migrate/command/grants/terraform.tfstate @@ -0,0 +1,62 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 7, + "lineage": "a1b2c3d4-0000-4000-8000-000000000008", + "resources": [ + { + "mode": "managed", + "type": "databricks_schema", + "name": "my_schema", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.schemas.my_schema__", "name": "schema_grants", "catalog_name": "main"}} + ] + }, + { + "mode": "managed", + "type": "databricks_volume", + "name": "my_volume", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.volumes.my_volume__", "name": "volume_name", "catalog_name": "main", "schema_name": "schema_grants"}} + ] + }, + { + "mode": "managed", + "type": "databricks_registered_model", + "name": "my_registered_model", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.registered_models.my_registered_model__", "name": "mymodel", "catalog_name": "main", "schema_name": "schema_grants"}} + ] + }, + { + "mode": "managed", + "type": "databricks_grants", + "name": "schema_my_schema", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.schemas.my_schema.grants__"}} + ] + }, + { + "mode": "managed", + "type": "databricks_grants", + "name": "volume_my_volume", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.volumes.my_volume.grants__"}} + ] + }, + { + "mode": "managed", + "type": "databricks_grants", + "name": "registered_model_my_registered_model", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.registered_models.my_registered_model.grants__"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/command/permissions/out.original_state.json b/acceptance/bundle/migrate/command/permissions/out.original_state.json index c7341d0ea88..35c9367c288 100644 --- a/acceptance/bundle/migrate/command/permissions/out.original_state.json +++ b/acceptance/bundle/migrate/command/permissions/out.original_state.json @@ -3,7 +3,6 @@ "terraform_version": "1.5.5", "serial": 5, "lineage": "[UUID]", - "outputs": {}, "resources": [ { "mode": "managed", @@ -11,377 +10,35 @@ "name": "test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 2, - "attributes": { - "always_running": false, - "budget_policy_id": null, - "continuous": [], - "control_run_state": false, - "dbt_task": [], - "deployment": [ - { - "deployment_id": "", - "kind": "BUNDLE", - "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/default/state/metadata.json", - "version_id": "" - } - ], - "description": null, - "edit_mode": "UI_LOCKED", - "email_notifications": [ - { - "no_alert_for_skipped_runs": false, - "on_duration_warning_threshold_exceeded": [], - "on_failure": [], - "on_start": [], - "on_streaming_backlog_exceeded": [], - "on_success": [] - } - ], - "environment": [], - "existing_cluster_id": null, - "format": "MULTI_TASK", - "git_source": [], - "health": [], - "id": "[NUMID]", - "job_cluster": [], - "library": [], - "max_concurrent_runs": 1, - "max_retries": 0, - "min_retry_interval_millis": 0, - "name": "Test Migration Job", - "new_cluster": [], - "notebook_task": [], - "notification_settings": [], - "parameter": [], - "parent_path": null, - "performance_target": null, - "pipeline_task": [], - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "python_wheel_task": [], - "queue": [ - { - "enabled": true - } - ], - "retry_on_timeout": false, - "run_as": [ - { - "group_name": "", - "service_principal_name": "", - "user_name": "[USERNAME]" - } - ], - "run_job_task": [], - "schedule": [], - "spark_jar_task": [], - "spark_python_task": [], - "spark_submit_task": [], - "tags": null, - "task": [ - { - "ai_runtime_task": [], - "alert_task": [], - "clean_rooms_notebook_task": [], - "compute": [], - "condition_task": [], - "dashboard_task": [], - "dbt_cloud_task": [], - "dbt_platform_task": [], - "dbt_task": [], - "depends_on": [], - "description": "", - "disable_auto_optimization": false, - "disabled": false, - "email_notifications": [ - { - "no_alert_for_skipped_runs": false, - "on_duration_warning_threshold_exceeded": [], - "on_failure": [], - "on_start": [], - "on_streaming_backlog_exceeded": [], - "on_success": [] - } - ], - "environment_key": "", - "existing_cluster_id": "", - "for_each_task": [], - "gen_ai_compute_task": [], - "health": [], - "job_cluster_key": "", - "library": [], - "max_retries": 0, - "min_retry_interval_millis": 0, - "new_cluster": [], - "notebook_task": [ - { - "base_parameters": null, - "notebook_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/default/files/notebook", - "source": "WORKSPACE", - "warehouse_id": "" - } - ], - "notification_settings": [], - "pipeline_task": [], - "power_bi_task": [], - "python_operator_task": [], - "python_wheel_task": [], - "retry_on_timeout": false, - "run_if": "ALL_SUCCESS", - "run_job_task": [], - "spark_jar_task": [], - "spark_python_task": [], - "spark_submit_task": [], - "sql_task": [], - "task_key": "main", - "timeout_seconds": 0, - "webhook_notifications": [] - } - ], - "timeout_seconds": 0, - "timeouts": null, - "trigger": [], - "triggers": [], - "url": "[DATABRICKS_URL]/#job/[NUMID]", - "usage_policy_id": null, - "webhook_notifications": [ - { - "on_duration_warning_threshold_exceeded": [], - "on_failure": [], - "on_start": [], - "on_streaming_backlog_exceeded": [], - "on_success": [] - } - ] - }, - "sensitive_attributes": [], - "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" - } + {"schema_version": 2, "attributes": {"id": "[NUMID]", "name": "Test Migration Job"}} ] }, { "mode": "managed", - "type": "databricks_permissions", - "name": "job_test_job", + "type": "databricks_pipeline", + "name": "test_pipeline", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 0, - "attributes": { - "access_control": [ - { - "group_name": "", - "permission_level": "CAN_VIEW", - "service_principal_name": "", - "user_name": "viewer@databricks.com" - }, - { - "group_name": "", - "permission_level": "IS_OWNER", - "service_principal_name": "", - "user_name": "[USERNAME]" - } - ], - "alert_v2_id": null, - "app_name": null, - "authorization": null, - "cluster_id": null, - "cluster_policy_id": null, - "dashboard_id": null, - "database_instance_name": null, - "database_project_name": null, - "directory_id": null, - "directory_path": null, - "experiment_id": null, - "id": "/jobs/[NUMID]", - "instance_pool_id": null, - "job_id": "[NUMID]", - "knowledge_assistant_id": null, - "notebook_id": null, - "notebook_path": null, - "object_type": "job", - "pipeline_id": null, - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "registered_model_id": null, - "repo_id": null, - "repo_path": null, - "serving_endpoint_id": null, - "sql_alert_id": null, - "sql_dashboard_id": null, - "sql_endpoint_id": null, - "sql_query_id": null, - "supervisor_agent_id": null, - "vector_search_endpoint_id": null, - "workspace_file_id": null, - "workspace_file_path": null - }, - "sensitive_attributes": [], - "private": "bnVsbA==", - "dependencies": [ - "databricks_job.test_job" - ] - } + {"schema_version": 0, "attributes": {"id": "[UUID]", "name": "Test Migration Pipeline"}} ] }, { "mode": "managed", "type": "databricks_permissions", - "name": "pipeline_test_pipeline", + "name": "job_test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 0, - "attributes": { - "access_control": [ - { - "group_name": "", - "permission_level": "CAN_MANAGE", - "service_principal_name": "", - "user_name": "manager@databricks.com" - }, - { - "group_name": "", - "permission_level": "IS_OWNER", - "service_principal_name": "", - "user_name": "[USERNAME]" - } - ], - "alert_v2_id": null, - "app_name": null, - "authorization": null, - "cluster_id": null, - "cluster_policy_id": null, - "dashboard_id": null, - "database_instance_name": null, - "database_project_name": null, - "directory_id": null, - "directory_path": null, - "experiment_id": null, - "id": "/pipelines/[UUID]", - "instance_pool_id": null, - "job_id": null, - "knowledge_assistant_id": null, - "notebook_id": null, - "notebook_path": null, - "object_type": "pipelines", - "pipeline_id": "[UUID]", - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "registered_model_id": null, - "repo_id": null, - "repo_path": null, - "serving_endpoint_id": null, - "sql_alert_id": null, - "sql_dashboard_id": null, - "sql_endpoint_id": null, - "sql_query_id": null, - "supervisor_agent_id": null, - "vector_search_endpoint_id": null, - "workspace_file_id": null, - "workspace_file_path": null - }, - "sensitive_attributes": [], - "private": "bnVsbA==", - "dependencies": [ - "databricks_pipeline.test_pipeline" - ] - } + {"schema_version": 0, "attributes": {"id": "/jobs/[NUMID]"}} ] }, { "mode": "managed", - "type": "databricks_pipeline", - "name": "test_pipeline", + "type": "databricks_permissions", + "name": "pipeline_test_pipeline", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 0, - "attributes": { - "allow_duplicate_names": false, - "budget_policy_id": null, - "catalog": null, - "cause": null, - "channel": "CURRENT", - "cluster": [], - "cluster_id": null, - "configuration": null, - "continuous": false, - "creator_user_name": "[USERNAME]", - "deployment": [ - { - "deployment_id": "", - "kind": "BUNDLE", - "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/default/state/metadata.json", - "version_id": "" - } - ], - "development": false, - "edition": "ADVANCED", - "environment": [], - "event_log": [], - "expected_last_modified": 0, - "filters": [], - "gateway_definition": [], - "health": null, - "id": "[UUID]", - "ingestion_definition": [], - "last_modified": [UNIX_TIME_MILLIS], - "latest_updates": null, - "library": [ - { - "file": [], - "glob": [], - "jar": "", - "maven": [], - "notebook": [ - { - "path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/default/files/pipeline" - } - ], - "whl": "" - } - ], - "name": "Test Migration Pipeline", - "notification": [], - "photon": false, - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "restart_window": [], - "root_path": null, - "run_as": [], - "run_as_user_name": "[USERNAME]", - "schema": null, - "serverless": false, - "serverless_compute_id": null, - "state": "IDLE", - "storage": "dbfs:/pipelines/[UUID]", - "tags": null, - "target": null, - "timeouts": null, - "trigger": [], - "url": "[DATABRICKS_URL]/#joblist/pipelines/[UUID]", - "usage_policy_id": null - }, - "sensitive_attributes": [], - "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19" - } + {"schema_version": 0, "attributes": {"id": "/pipelines/[UUID]"}} ] } - ], - "check_results": null + ] } diff --git a/acceptance/bundle/migrate/command/permissions/output.txt b/acceptance/bundle/migrate/command/permissions/output.txt index ce6d0272e4e..4d1af36e99c 100644 --- a/acceptance/bundle/migrate/command/permissions/output.txt +++ b/acceptance/bundle/migrate/command/permissions/output.txt @@ -1,12 +1,5 @@ ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/default/files... -Created jobs.test_job -Created jobs.test_job.permissions -Created pipelines.test_pipeline -Created pipelines.test_pipeline.permissions -Files: 3 uploaded, 0 deleted -Resources: 4 created, 0 changed, 0 deleted, 0 unchanged +>>> seed_tfstate.py terraform.tfstate >>> [CLI] bundle deployment migrate Success! Migrated 4 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json @@ -18,9 +11,6 @@ The state file is not synchronized to the workspace yet. To do that and finalize To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/default/resources.json and rename [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate.backup to [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 4 unchanged - >>> [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 4 unchanged @@ -37,18 +27,6 @@ Plan: 0 to add, 0 to change, 0 to delete, 4 unchanged "job_id": "[NUMID]" } } -{ - "headers": { - "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" - ] - }, - "method": "GET", - "path": "/api/2.2/jobs/get", - "q": { - "job_id": "[NUMID]" - } -} >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/default/files... diff --git a/acceptance/bundle/migrate/command/permissions/script b/acceptance/bundle/migrate/command/permissions/script index f2ef76cc34d..a9441bd2475 100755 --- a/acceptance/bundle/migrate/command/permissions/script +++ b/acceptance/bundle/migrate/command/permissions/script @@ -1,14 +1,11 @@ -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +export DATABRICKS_BUNDLE_ENGINE= +trace seed_tfstate.py terraform.tfstate print_state.py > out.original_state.json trace $CLI bundle deployment migrate 2>&1 | contains.py 'Migrated 4 resources' print_state.py > out.new_state.json -export DATABRICKS_BUNDLE_ENGINE= - rm "$OUT_REQUESTS" -# Both DATABRICKS_BUNDLE_ENGINE=direct and DATABRICKS_BUNDLE_ENGINE= work -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "4 unchanged" trace $CLI bundle plan | contains.py "4 unchanged" trace print_requests.py --get //jobs/get | contains.py 'engine/direct' diff --git a/acceptance/bundle/migrate/command/permissions/terraform.tfstate b/acceptance/bundle/migrate/command/permissions/terraform.tfstate new file mode 100644 index 00000000000..82f69dca2b8 --- /dev/null +++ b/acceptance/bundle/migrate/command/permissions/terraform.tfstate @@ -0,0 +1,44 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 5, + "lineage": "a1b2c3d4-0000-4000-8000-000000000007", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 2, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Migration Job"}} + ] + }, + { + "mode": "managed", + "type": "databricks_pipeline", + "name": "test_pipeline", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.pipelines.test_pipeline__", "name": "Test Migration Pipeline"}} + ] + }, + { + "mode": "managed", + "type": "databricks_permissions", + "name": "job_test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job.permissions__"}} + ] + }, + { + "mode": "managed", + "type": "databricks_permissions", + "name": "pipeline_test_pipeline", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.pipelines.test_pipeline.permissions__"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/command/profile_arg/output.txt b/acceptance/bundle/migrate/command/profile_arg/output.txt index 01cb9b893c4..637b09ed7b1 100644 --- a/acceptance/bundle/migrate/command/profile_arg/output.txt +++ b/acceptance/bundle/migrate/command/profile_arg/output.txt @@ -1,9 +1,5 @@ ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files... -Created jobs.test_job -Files: 3 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +>>> seed_tfstate.py terraform.tfstate >>> [CLI] bundle deployment migrate -p non_existent321 Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json @@ -15,15 +11,10 @@ The state file is not synchronized to the workspace yet. To do that and finalize To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json and rename [TEST_TMP_DIR]/.databricks/bundle/dev/terraform/terraform.tfstate.backup to [TEST_TMP_DIR]/.databricks/bundle/dev/terraform/terraform.tfstate ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -t prod -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/prod/files... -Created jobs.test_job -Created schemas.test_schema -Files: 3 uploaded, 0 deleted -Resources: 2 created, 0 changed, 0 deleted, 0 unchanged +>>> seed_tfstate.py terraform-prod.tfstate -t prod >>> [CLI] bundle deployment migrate -p non_existent321 -t prod -Success! Migrated 2 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/prod/resources.json +Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/prod/resources.json Validate the migration by running "databricks bundle plan -t prod -p non_existent321", there should be no actions planned. diff --git a/acceptance/bundle/migrate/command/profile_arg/script b/acceptance/bundle/migrate/command/profile_arg/script index 9e3c242cf1e..31ad0a9df85 100755 --- a/acceptance/bundle/migrate/command/profile_arg/script +++ b/acceptance/bundle/migrate/command/profile_arg/script @@ -1,7 +1,11 @@ -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +export DATABRICKS_BUNDLE_ENGINE= + +# Seed a terraform deployment of the dev target, then migrate with a bogus profile. +trace seed_tfstate.py terraform.tfstate # only interested in output here; for some reason in test env -p is not validated trace $CLI bundle deployment migrate -p non_existent321 -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy -t prod +# Same for the prod target (a schema). +trace seed_tfstate.py terraform-prod.tfstate -t prod trace $CLI bundle deployment migrate -p non_existent321 -t prod diff --git a/acceptance/bundle/migrate/command/profile_arg/terraform-prod.tfstate b/acceptance/bundle/migrate/command/profile_arg/terraform-prod.tfstate new file mode 100644 index 00000000000..785e6c62cd5 --- /dev/null +++ b/acceptance/bundle/migrate/command/profile_arg/terraform-prod.tfstate @@ -0,0 +1,17 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "a1b2c3d4-0000-4000-8000-000000000006", + "resources": [ + { + "mode": "managed", + "type": "databricks_schema", + "name": "test_schema", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.schemas.test_schema__", "name": "myschema", "catalog_name": "mycat"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/command/profile_arg/terraform.tfstate b/acceptance/bundle/migrate/command/profile_arg/terraform.tfstate new file mode 100644 index 00000000000..58fb3601318 --- /dev/null +++ b/acceptance/bundle/migrate/command/profile_arg/terraform.tfstate @@ -0,0 +1,17 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "a1b2c3d4-0000-4000-8000-000000000005", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Migration Job"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/command/removed/output.txt b/acceptance/bundle/migrate/command/removed/output.txt index 0450ff7b7aa..f530fea106a 100644 --- a/acceptance/bundle/migrate/command/removed/output.txt +++ b/acceptance/bundle/migrate/command/removed/output.txt @@ -1,10 +1,5 @@ ->>> [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-removed-test/default/files... -Created jobs.job_a -Created jobs.job_b -Files: 1 uploaded, 0 deleted -Resources: 2 created, 0 changed, 0 deleted, 0 unchanged +>>> seed_tfstate.py terraform.tfstate >>> [CLI] bundle deployment migrate Success! Migrated 2 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json @@ -16,12 +11,12 @@ The state file is not synchronized to the workspace yet. To do that and finalize To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/default/resources.json and rename [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate.backup to [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan +>>> [CLI] bundle plan delete jobs.job_b Plan: 0 to add, 0 to change, 1 to delete, 1 unchanged ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy +>>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-removed-test/default/files... Deleted jobs.job_b Files: 1 uploaded, 0 deleted @@ -41,5 +36,5 @@ Resources: 0 created, 0 changed, 1 deleted, 1 unchanged } } ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan +>>> [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged diff --git a/acceptance/bundle/migrate/command/removed/script b/acceptance/bundle/migrate/command/removed/script index 9e53c7991b6..9b0b737d904 100644 --- a/acceptance/bundle/migrate/command/removed/script +++ b/acceptance/bundle/migrate/command/removed/script @@ -1,7 +1,7 @@ -export DATABRICKS_BUNDLE_ENGINE=terraform +export DATABRICKS_BUNDLE_ENGINE= -# Deploy with terraform (both job_a and job_b) -trace $CLI bundle deploy +# Seed a prior terraform deployment of both job_a and job_b. +trace seed_tfstate.py terraform.tfstate # Remove job_b from config without deploying the deletion grep -v job_b databricks.yml > databricks_tmp.yml && mv databricks_tmp.yml databricks.yml @@ -10,14 +10,14 @@ grep -v job_b databricks.yml > databricks_tmp.yml && mv databricks_tmp.yml datab trace $CLI bundle deployment migrate # After migration: plan shows job_b as "to delete" -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "1 to delete" +trace $CLI bundle plan | contains.py "1 to delete" # Deploy deletes job_b; verify via recorded requests rm "$OUT_REQUESTS" -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy +trace $CLI bundle deploy trace print_requests.py //jobs/delete # No further actions planned -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "1 unchanged" +trace $CLI bundle plan | contains.py "1 unchanged" rm "$OUT_REQUESTS" diff --git a/acceptance/bundle/migrate/command/removed/terraform.tfstate b/acceptance/bundle/migrate/command/removed/terraform.tfstate new file mode 100644 index 00000000000..c340aa5d9bb --- /dev/null +++ b/acceptance/bundle/migrate/command/removed/terraform.tfstate @@ -0,0 +1,26 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "a1b2c3d4-0000-4000-8000-000000000002", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_a", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.job_a__", "name": "Job A"}} + ] + }, + { + "mode": "managed", + "type": "databricks_job", + "name": "job_b", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.job_b__", "name": "Job B"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/command/runas/out.create_requests.json b/acceptance/bundle/migrate/command/runas/out.create_requests.json index 2a195b271c4..ba069feb467 100644 --- a/acceptance/bundle/migrate/command/runas/out.create_requests.json +++ b/acceptance/bundle/migrate/command/runas/out.create_requests.json @@ -1,7 +1,7 @@ { "headers": { "User-Agent": [ - "databricks-tf-provider/[TF_PROVIDER_VERSION] databricks-sdk-go/[SDK_VERSION] go/1.25.8 os/[OS] cli/[CLI_VERSION] terraform/1.5.5 sdk/sdkv2 resource/pipeline auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" ] }, "method": "POST", @@ -32,7 +32,7 @@ { "headers": { "User-Agent": [ - "databricks-tf-provider/[TF_PROVIDER_VERSION] databricks-sdk-go/[SDK_VERSION] go/1.25.8 os/[OS] cli/[CLI_VERSION] terraform/1.5.5 sdk/sdkv2 resource/permissions auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" ] }, "method": "PUT", diff --git a/acceptance/bundle/migrate/command/runas/out.old_state.json b/acceptance/bundle/migrate/command/runas/out.old_state.json index 1fa79c0b405..1f0b028d919 100644 --- a/acceptance/bundle/migrate/command/runas/out.old_state.json +++ b/acceptance/bundle/migrate/command/runas/out.old_state.json @@ -3,164 +3,24 @@ "terraform_version": "1.5.5", "serial": 3, "lineage": "[UUID]", - "outputs": {}, "resources": [ { "mode": "managed", - "type": "databricks_permissions", - "name": "pipeline_foo", + "type": "databricks_pipeline", + "name": "foo", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 0, - "attributes": { - "access_control": [ - { - "group_name": "", - "permission_level": "IS_OWNER", - "service_principal_name": "", - "user_name": "[USERNAME]" - }, - { - "group_name": "users", - "permission_level": "CAN_VIEW", - "service_principal_name": "", - "user_name": "" - } - ], - "alert_v2_id": null, - "app_name": null, - "authorization": null, - "cluster_id": null, - "cluster_policy_id": null, - "dashboard_id": null, - "database_instance_name": null, - "database_project_name": null, - "directory_id": null, - "directory_path": null, - "experiment_id": null, - "id": "/pipelines/[UUID]", - "instance_pool_id": null, - "job_id": null, - "knowledge_assistant_id": null, - "notebook_id": null, - "notebook_path": null, - "object_type": "pipelines", - "pipeline_id": "[UUID]", - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "registered_model_id": null, - "repo_id": null, - "repo_path": null, - "serving_endpoint_id": null, - "sql_alert_id": null, - "sql_dashboard_id": null, - "sql_endpoint_id": null, - "sql_query_id": null, - "supervisor_agent_id": null, - "vector_search_endpoint_id": null, - "workspace_file_id": null, - "workspace_file_path": null - }, - "sensitive_attributes": [], - "private": "bnVsbA==", - "dependencies": [ - "databricks_pipeline.foo" - ] - } + {"schema_version": 0, "attributes": {"id": "[UUID]", "name": "DABs Revenue Pipeline"}} ] }, { "mode": "managed", - "type": "databricks_pipeline", - "name": "foo", + "type": "databricks_permissions", + "name": "pipeline_foo", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - { - "schema_version": 0, - "attributes": { - "allow_duplicate_names": false, - "budget_policy_id": null, - "catalog": "main", - "cause": null, - "channel": "CURRENT", - "cluster": [], - "cluster_id": null, - "configuration": null, - "continuous": false, - "creator_user_name": "[USERNAME]", - "deployment": [ - { - "deployment_id": "", - "kind": "BUNDLE", - "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/dabs_revenue-[UNIQUE_NAME]/production/state/metadata.json", - "version_id": "" - } - ], - "development": false, - "edition": "ADVANCED", - "environment": [], - "event_log": [], - "expected_last_modified": 0, - "filters": [], - "gateway_definition": [], - "health": null, - "id": "[UUID]", - "ingestion_definition": [], - "last_modified": [UNIX_TIME_MILLIS], - "latest_updates": null, - "library": [ - { - "file": [], - "glob": [], - "jar": "", - "maven": [], - "notebook": [ - { - "path": "/Workspace/Users/[USERNAME]/.bundle/dabs_revenue-[UNIQUE_NAME]/production/files/sql" - } - ], - "whl": "" - } - ], - "name": "DABs Revenue Pipeline", - "notification": [], - "photon": false, - "provider_config": [ - { - "workspace_id": "[NUMID]" - } - ], - "restart_window": [], - "root_path": null, - "run_as": [ - { - "group_name": "", - "service_principal_name": "[UUID]", - "user_name": "" - } - ], - "run_as_user_name": "[USERNAME]", - "schema": null, - "serverless": true, - "serverless_compute_id": null, - "state": "IDLE", - "storage": null, - "tags": null, - "target": "team_eng_deco", - "timeouts": null, - "trigger": [], - "url": "[DATABRICKS_URL]/#joblist/pipelines/[UUID]", - "usage_policy_id": null - }, - "sensitive_attributes": [], - "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19" - } + {"schema_version": 0, "attributes": {"id": "/pipelines/[UUID]"}} ] } - ], - "check_results": null + ] } diff --git a/acceptance/bundle/migrate/command/runas/output.txt b/acceptance/bundle/migrate/command/runas/output.txt index acc0bd399a9..c6beb8083e3 100644 --- a/acceptance/bundle/migrate/command/runas/output.txt +++ b/acceptance/bundle/migrate/command/runas/output.txt @@ -1,40 +1,5 @@ ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle plan -Recommendation: permissions section should explicitly include the current deployment identity '[USERNAME]' or one of its groups -If it is not included, CAN_MANAGE permissions are only applied if the present identity is used to deploy. - -Consider using a adding a top-level permissions section such as the following: - - permissions: - - user_name: [USERNAME] - level: CAN_MANAGE - -See https://docs.databricks.com/dev-tools/bundles/permissions.html to learn more about permission configuration. - in databricks.yml:5:3 - -create pipelines.foo -create pipelines.foo.permissions - -Plan: 2 to add, 0 to change, 0 to delete, 0 unchanged - ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy -Recommendation: permissions section should explicitly include the current deployment identity '[USERNAME]' or one of its groups -If it is not included, CAN_MANAGE permissions are only applied if the present identity is used to deploy. - -Consider using a adding a top-level permissions section such as the following: - - permissions: - - user_name: [USERNAME] - level: CAN_MANAGE - -See https://docs.databricks.com/dev-tools/bundles/permissions.html to learn more about permission configuration. - in databricks.yml:5:3 - -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/dabs_revenue-[UNIQUE_NAME]/production/files... -Created pipelines.foo -Created pipelines.foo.permissions -Files: 3 uploaded, 0 deleted -Resources: 2 created, 0 changed, 0 deleted, 0 unchanged +>>> seed_tfstate.py terraform.tfstate >>> print_requests.py //pipelines @@ -55,22 +20,7 @@ Notice: migrating your bundle to direct deployment engine (https://github.com/da >>> [CLI] pipelines get [UUID] ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle plan -Recommendation: permissions section should explicitly include the current deployment identity '[USERNAME]' or one of its groups -If it is not included, CAN_MANAGE permissions are only applied if the present identity is used to deploy. - -Consider using a adding a top-level permissions section such as the following: - - permissions: - - user_name: [USERNAME] - level: CAN_MANAGE - -See https://docs.databricks.com/dev-tools/bundles/permissions.html to learn more about permission configuration. - in databricks.yml:5:3 - -Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged - ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deployment migrate +>>> [CLI] bundle deployment migrate Recommendation: permissions section should explicitly include the current deployment identity '[USERNAME]' or one of its groups If it is not included, CAN_MANAGE permissions are only applied if the present identity is used to deploy. @@ -94,7 +44,7 @@ To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/production/resou >>> print_state.py ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan +>>> [CLI] bundle plan Recommendation: permissions section should explicitly include the current deployment identity '[USERNAME]' or one of its groups If it is not included, CAN_MANAGE permissions are only applied if the present identity is used to deploy. @@ -109,7 +59,7 @@ See https://docs.databricks.com/dev-tools/bundles/permissions.html to learn more Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan -o json +>>> [CLI] bundle plan -o json Recommendation: permissions section should explicitly include the current deployment identity '[USERNAME]' or one of its groups If it is not included, CAN_MANAGE permissions are only applied if the present identity is used to deploy. @@ -123,7 +73,7 @@ See https://docs.databricks.com/dev-tools/bundles/permissions.html to learn more in databricks.yml:5:3 ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle destroy --auto-approve +>>> [CLI] bundle destroy --auto-approve Recommendation: permissions section should explicitly include the current deployment identity '[USERNAME]' or one of its groups If it is not included, CAN_MANAGE permissions are only applied if the present identity is used to deploy. diff --git a/acceptance/bundle/migrate/command/runas/script b/acceptance/bundle/migrate/command/runas/script index c852cbfb865..7659c426cd5 100644 --- a/acceptance/bundle/migrate/command/runas/script +++ b/acceptance/bundle/migrate/command/runas/script @@ -3,24 +3,24 @@ if [ -z "${TEST_SP_APPLICATION_ID+x}" ]; then fi envsubst < databricks.yml.tmpl > databricks.yml -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle plan +export DATABRICKS_BUNDLE_ENGINE= cleanup() { - trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle destroy --auto-approve + trace $CLI bundle destroy --auto-approve rm -f "$OUT_REQUESTS" } trap cleanup EXIT -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +# Seed a prior terraform deployment of the run-as pipeline. +trace seed_tfstate.py terraform.tfstate trace print_requests.py //pipelines > out.create_requests.json trace print_state.py > out.old_state.json -pipeline_id=$(DATABRICKS_BUNDLE_ENGINE= $CLI bundle summary --output json | jq -r '.resources.pipelines.foo.id') +pipeline_id=$($CLI bundle summary --output json | jq -r '.resources.pipelines.foo.id') trace $CLI pipelines get $pipeline_id > out.pipelines_get.json -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle plan -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle deployment migrate +trace $CLI bundle deployment migrate trace print_state.py > out.new_state.json -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan -o json | nostamp > out.plan.json +trace $CLI bundle plan +trace $CLI bundle plan -o json | nostamp > out.plan.json diff --git a/acceptance/bundle/migrate/command/runas/terraform.tfstate b/acceptance/bundle/migrate/command/runas/terraform.tfstate new file mode 100644 index 00000000000..ce4a94ffa49 --- /dev/null +++ b/acceptance/bundle/migrate/command/runas/terraform.tfstate @@ -0,0 +1,26 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 3, + "lineage": "a1b2c3d4-0000-4000-8000-00000000000c", + "resources": [ + { + "mode": "managed", + "type": "databricks_pipeline", + "name": "foo", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.pipelines.foo__", "name": "DABs Revenue Pipeline"}} + ] + }, + { + "mode": "managed", + "type": "databricks_permissions", + "name": "pipeline_foo", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.pipelines.foo.permissions__"}} + ] + } + ] +} diff --git a/acceptance/bundle/migrate/command/var_arg/output.txt b/acceptance/bundle/migrate/command/var_arg/output.txt index 620f8994f9b..5817be84a28 100644 --- a/acceptance/bundle/migrate/command/var_arg/output.txt +++ b/acceptance/bundle/migrate/command/var_arg/output.txt @@ -1,9 +1,5 @@ ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy --var=job_name=Custom Job Name -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-var-test/dev/files... -Created jobs.test_job -Files: 2 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +>>> seed_tfstate.py terraform.tfstate --var=job_name=Custom Job Name >>> [CLI] bundle deployment migrate --var=job_name=Custom Job Name Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json @@ -18,10 +14,10 @@ To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/dev/resources.js >>> print_state.py "Custom Job Name" ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan --var=job_name=Custom Job Name +>>> [CLI] bundle plan --var=job_name=Custom Job Name Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle destroy --var=job_name=Custom Job Name --auto-approve +>>> [CLI] bundle destroy --var=job_name=Custom Job Name --auto-approve The following resources will be deleted: delete resources.jobs.test_job @@ -29,11 +25,7 @@ All files and directories at the following location will be deleted: /Workspace/ Destroy: 1 deleted ->>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy --var job_name=Custom Job Name -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-var-test/dev/files... -Created jobs.test_job -Files: 2 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 0 unchanged +>>> seed_tfstate.py terraform.tfstate --var job_name=Custom Job Name >>> [CLI] bundle deployment migrate --var job_name=Custom Job Name Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json @@ -48,10 +40,10 @@ To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/dev/resources.js >>> print_state.py "Custom Job Name" ->>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan --var job_name=Custom Job Name +>>> [CLI] bundle plan --var job_name=Custom Job Name Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged ->>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle destroy --var=job_name=Custom Job Name --auto-approve +>>> [CLI] bundle destroy --var=job_name=Custom Job Name --auto-approve The following resources will be deleted: delete resources.jobs.test_job diff --git a/acceptance/bundle/migrate/command/var_arg/script b/acceptance/bundle/migrate/command/var_arg/script index 722b0527f86..f0aaa83dda5 100644 --- a/acceptance/bundle/migrate/command/var_arg/script +++ b/acceptance/bundle/migrate/command/var_arg/script @@ -1,15 +1,21 @@ -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy --var="job_name=Custom Job Name" +export DATABRICKS_BUNDLE_ENGINE= + +# seed_tfstate.py consumes (deletes) the fixture, and the second block re-seeds, so keep a copy. +FIXTURE=$(cat terraform.tfstate) + +# Seed a terraform deployment made with a variable, then migrate with the same '--var=X'. +trace seed_tfstate.py terraform.tfstate --var="job_name=Custom Job Name" trace $CLI bundle deployment migrate --var="job_name=Custom Job Name" 2>&1 | contains.py 'Migrated 1 resources' trace print_state.py | jq '.state."resources.jobs.test_job".state.name' -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan --var="job_name=Custom Job Name" | contains.py "1 unchanged" -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle destroy --var="job_name=Custom Job Name" --auto-approve +trace $CLI bundle plan --var="job_name=Custom Job Name" | contains.py "1 unchanged" +trace $CLI bundle destroy --var="job_name=Custom Job Name" --auto-approve # Try different syntax, '--var X', instead of '--var=X' rm -fr .databricks +echo "$FIXTURE" > terraform.tfstate -# Deploy with Terraform using a variable -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy --var "job_name=Custom Job Name" +trace seed_tfstate.py terraform.tfstate --var "job_name=Custom Job Name" trace $CLI bundle deployment migrate --var "job_name=Custom Job Name" 2>&1 | contains.py 'Migrated 1 resources' trace print_state.py | jq '.state."resources.jobs.test_job".state.name' -trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan --var "job_name=Custom Job Name" | contains.py "1 unchanged" -trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle destroy --var="job_name=Custom Job Name" --auto-approve +trace $CLI bundle plan --var "job_name=Custom Job Name" | contains.py "1 unchanged" +trace $CLI bundle destroy --var="job_name=Custom Job Name" --auto-approve diff --git a/acceptance/bundle/migrate/command/var_arg/terraform.tfstate b/acceptance/bundle/migrate/command/var_arg/terraform.tfstate new file mode 100644 index 00000000000..6ade3b70273 --- /dev/null +++ b/acceptance/bundle/migrate/command/var_arg/terraform.tfstate @@ -0,0 +1,17 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "a1b2c3d4-0000-4000-8000-000000000004", + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Custom Job Name"}} + ] + } + ] +} From 5507c4f97be00b439f1bc0569b8a79b84e63169c Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 28 Sep 2026 18:05:46 +0200 Subject: [PATCH 02/15] acceptance: record/replay proof for migrate/command/permissions Replace the direct-seed approach with record & replay for the permissions migrate test: check in the real terraform.tfstate + the terraform deploy's resource requests (captured from an actual terraform run), and replay the requests via `databricks api` so the backend holds real terraform-shaped resources, remapping recorded ids to the minted ones. The migrated state's out.original_state.json is now byte-identical to what terraform emits. Proof of the approach; the remaining migrate tests still use seed_tfstate.py and will be converted the same way. Co-authored-by: Isaac --- acceptance/bin/replay_tfstate.py | 95 +++++ .../permissions/out.original_state.json | 363 ++++++++++++++++- .../migrate/command/permissions/output.txt | 19 +- .../bundle/migrate/command/permissions/script | 11 +- .../permissions/terraform-requests.json | 80 ++++ .../command/permissions/terraform.tfstate | 365 +++++++++++++++++- 6 files changed, 908 insertions(+), 25 deletions(-) create mode 100644 acceptance/bin/replay_tfstate.py create mode 100644 acceptance/bundle/migrate/command/permissions/terraform-requests.json diff --git a/acceptance/bin/replay_tfstate.py b/acceptance/bin/replay_tfstate.py new file mode 100644 index 00000000000..8488d33e776 --- /dev/null +++ b/acceptance/bin/replay_tfstate.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 +""" +Reconstruct a terraform deployment for the migrate tests without the (removed) terraform engine. + +Given a checked-in terraform.tfstate and the resource-mutating requests the terraform deploy made +(both captured once from a real terraform run), replay the requests against the backend so it ends +up in the exact terraform-shaped state, then write the tfstate locally with each recorded resource +id rewritten to the one the backend just minted. The migrate step then reads a real terraform state +backed by real (terraform-shaped) resources. + +The requests carry the recorded ids; the backend mints fresh ones on replay. We learn each mapping +from the create responses (matching a create to its tfstate resource by name) and rewrite it into +every later request and into the tfstate, so cross-resource references stay consistent. + +Usage: replay_tfstate.py REQUESTS.json TFSTATE.json [-t TARGET] +""" + +import argparse +import json +import os +import subprocess +import sys + +CLI = os.environ["CLI"] + +# Per resource: which response field carries the new id. Terraform's tfstate stores the same value +# as the resource's `id`, keyed here by the create path so we can match a create to its tfstate entry. +ID_FIELDS = ["job_id", "pipeline_id", "id", "full_name", "name"] + + +def apply_map(text, id_map): + for old, new in id_map.items(): + text = text.replace(old, new) + return text + + +def api(method, path, body): + cmd = [CLI, "api", method.lower(), path, "--output", "json"] + if body is not None: + cmd += ["--json", json.dumps(body)] + r = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8") + if r.returncode != 0: + sys.exit(f"replay_tfstate.py: {method} {path} failed:\n{r.stdout}\n{r.stderr}") + return json.loads(r.stdout) if r.stdout.strip() else {} + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("requests") + parser.add_argument("tfstate") + parser.add_argument("-t", "--target", default="default") + args = parser.parse_args() + + requests = json.loads(open(args.requests).read()) + tfstate_raw = open(args.tfstate).read() + tfstate = json.loads(tfstate_raw) + + # Drop the fixtures from the bundle root so a later deploy does not sync them as bundle files. + os.remove(args.requests) + os.remove(args.tfstate) + + # name -> recorded resource id, from the tfstate managed resources. + name_to_id = {} + for r in tfstate["resources"]: + if r.get("mode") != "managed": + continue + attrs = r["instances"][0]["attributes"] + if "name" in attrs and "id" in attrs: + name_to_id[attrs["name"]] = str(attrs["id"]) + + id_map = {} + for req in requests: + path = apply_map(req["path"], id_map) + body = req.get("body") + if body is not None: + body = json.loads(apply_map(json.dumps(body), id_map)) + resp = api(req["method"], path, body) + + # A create (POST that returns a new id) whose config name matches a tfstate resource: + # map its recorded id to the freshly minted one. + if req["method"] == "POST" and isinstance(body, dict) and body.get("name") in name_to_id: + old_id = name_to_id[body["name"]] + new_id = next((str(resp[f]) for f in ID_FIELDS if f in resp), None) + if new_id is None: + sys.exit(f"replay_tfstate.py: no id in response to {req['path']}: {resp}") + id_map[old_id] = new_id + + out_dir = os.path.join(".databricks", "bundle", args.target, "terraform") + os.makedirs(out_dir, exist_ok=True) + with open(os.path.join(out_dir, "terraform.tfstate"), "w") as f: + f.write(apply_map(tfstate_raw, id_map)) + + +if __name__ == "__main__": + main() diff --git a/acceptance/bundle/migrate/command/permissions/out.original_state.json b/acceptance/bundle/migrate/command/permissions/out.original_state.json index 35c9367c288..c7341d0ea88 100644 --- a/acceptance/bundle/migrate/command/permissions/out.original_state.json +++ b/acceptance/bundle/migrate/command/permissions/out.original_state.json @@ -3,6 +3,7 @@ "terraform_version": "1.5.5", "serial": 5, "lineage": "[UUID]", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,35 +11,377 @@ "name": "test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 2, "attributes": {"id": "[NUMID]", "name": "Test Migration Job"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "[NUMID]", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Migration Job", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "[USERNAME]" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [ + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "", + "library": [], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [ + { + "base_parameters": null, + "notebook_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/default/files/notebook", + "source": "WORKSPACE", + "warehouse_id": "" + } + ], + "notification_settings": [], + "pipeline_task": [], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "main", + "timeout_seconds": 0, + "webhook_notifications": [] + } + ], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/[NUMID]", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] }, { "mode": "managed", - "type": "databricks_pipeline", - "name": "test_pipeline", + "type": "databricks_permissions", + "name": "job_test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "[UUID]", "name": "Test Migration Pipeline"}} + { + "schema_version": 0, + "attributes": { + "access_control": [ + { + "group_name": "", + "permission_level": "CAN_VIEW", + "service_principal_name": "", + "user_name": "viewer@databricks.com" + }, + { + "group_name": "", + "permission_level": "IS_OWNER", + "service_principal_name": "", + "user_name": "[USERNAME]" + } + ], + "alert_v2_id": null, + "app_name": null, + "authorization": null, + "cluster_id": null, + "cluster_policy_id": null, + "dashboard_id": null, + "database_instance_name": null, + "database_project_name": null, + "directory_id": null, + "directory_path": null, + "experiment_id": null, + "id": "/jobs/[NUMID]", + "instance_pool_id": null, + "job_id": "[NUMID]", + "knowledge_assistant_id": null, + "notebook_id": null, + "notebook_path": null, + "object_type": "job", + "pipeline_id": null, + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "registered_model_id": null, + "repo_id": null, + "repo_path": null, + "serving_endpoint_id": null, + "sql_alert_id": null, + "sql_dashboard_id": null, + "sql_endpoint_id": null, + "sql_query_id": null, + "supervisor_agent_id": null, + "vector_search_endpoint_id": null, + "workspace_file_id": null, + "workspace_file_path": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_job.test_job" + ] + } ] }, { "mode": "managed", "type": "databricks_permissions", - "name": "job_test_job", + "name": "pipeline_test_pipeline", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "/jobs/[NUMID]"}} + { + "schema_version": 0, + "attributes": { + "access_control": [ + { + "group_name": "", + "permission_level": "CAN_MANAGE", + "service_principal_name": "", + "user_name": "manager@databricks.com" + }, + { + "group_name": "", + "permission_level": "IS_OWNER", + "service_principal_name": "", + "user_name": "[USERNAME]" + } + ], + "alert_v2_id": null, + "app_name": null, + "authorization": null, + "cluster_id": null, + "cluster_policy_id": null, + "dashboard_id": null, + "database_instance_name": null, + "database_project_name": null, + "directory_id": null, + "directory_path": null, + "experiment_id": null, + "id": "/pipelines/[UUID]", + "instance_pool_id": null, + "job_id": null, + "knowledge_assistant_id": null, + "notebook_id": null, + "notebook_path": null, + "object_type": "pipelines", + "pipeline_id": "[UUID]", + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "registered_model_id": null, + "repo_id": null, + "repo_path": null, + "serving_endpoint_id": null, + "sql_alert_id": null, + "sql_dashboard_id": null, + "sql_endpoint_id": null, + "sql_query_id": null, + "supervisor_agent_id": null, + "vector_search_endpoint_id": null, + "workspace_file_id": null, + "workspace_file_path": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_pipeline.test_pipeline" + ] + } ] }, { "mode": "managed", - "type": "databricks_permissions", - "name": "pipeline_test_pipeline", + "type": "databricks_pipeline", + "name": "test_pipeline", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "/pipelines/[UUID]"}} + { + "schema_version": 0, + "attributes": { + "allow_duplicate_names": false, + "budget_policy_id": null, + "catalog": null, + "cause": null, + "channel": "CURRENT", + "cluster": [], + "cluster_id": null, + "configuration": null, + "continuous": false, + "creator_user_name": "[USERNAME]", + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/default/state/metadata.json", + "version_id": "" + } + ], + "development": false, + "edition": "ADVANCED", + "environment": [], + "event_log": [], + "expected_last_modified": 0, + "filters": [], + "gateway_definition": [], + "health": null, + "id": "[UUID]", + "ingestion_definition": [], + "last_modified": [UNIX_TIME_MILLIS], + "latest_updates": null, + "library": [ + { + "file": [], + "glob": [], + "jar": "", + "maven": [], + "notebook": [ + { + "path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/default/files/pipeline" + } + ], + "whl": "" + } + ], + "name": "Test Migration Pipeline", + "notification": [], + "photon": false, + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "restart_window": [], + "root_path": null, + "run_as": [], + "run_as_user_name": "[USERNAME]", + "schema": null, + "serverless": false, + "serverless_compute_id": null, + "state": "IDLE", + "storage": "dbfs:/pipelines/[UUID]", + "tags": null, + "target": null, + "timeouts": null, + "trigger": [], + "url": "[DATABRICKS_URL]/#joblist/pipelines/[UUID]", + "usage_policy_id": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/permissions/output.txt b/acceptance/bundle/migrate/command/permissions/output.txt index 4d1af36e99c..c3bcd4df436 100644 --- a/acceptance/bundle/migrate/command/permissions/output.txt +++ b/acceptance/bundle/migrate/command/permissions/output.txt @@ -1,5 +1,5 @@ ->>> seed_tfstate.py terraform.tfstate +>>> replay_tfstate.py terraform-requests.json terraform.tfstate >>> [CLI] bundle deployment migrate Success! Migrated 4 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json @@ -11,6 +11,9 @@ The state file is not synchronized to the workspace yet. To do that and finalize To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/default/resources.json and rename [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate.backup to [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 4 unchanged + >>> [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 4 unchanged @@ -27,10 +30,22 @@ Plan: 0 to add, 0 to change, 0 to delete, 4 unchanged "job_id": "[NUMID]" } } +{ + "headers": { + "User-Agent": [ + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" + ] + }, + "method": "GET", + "path": "/api/2.2/jobs/get", + "q": { + "job_id": "[NUMID]" + } +} >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/default/files... -Files: 2 uploaded, 0 deleted +Files: 5 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 4 unchanged >>> print_requests.py --get //jobs/get diff --git a/acceptance/bundle/migrate/command/permissions/script b/acceptance/bundle/migrate/command/permissions/script index a9441bd2475..75dcd39490b 100755 --- a/acceptance/bundle/migrate/command/permissions/script +++ b/acceptance/bundle/migrate/command/permissions/script @@ -1,11 +1,18 @@ -export DATABRICKS_BUNDLE_ENGINE= -trace seed_tfstate.py terraform.tfstate +# Replay the terraform deploy's resource requests (captured once from a real terraform run) so the +# backend holds the same terraform-shaped resources, and drop in the captured terraform.tfstate; +# this stands in for `DATABRICKS_BUNDLE_ENGINE=terraform bundle deploy` now that migrate tests must +# not deploy with terraform. +trace replay_tfstate.py terraform-requests.json terraform.tfstate print_state.py > out.original_state.json trace $CLI bundle deployment migrate 2>&1 | contains.py 'Migrated 4 resources' print_state.py > out.new_state.json +export DATABRICKS_BUNDLE_ENGINE= + rm "$OUT_REQUESTS" +# Both DATABRICKS_BUNDLE_ENGINE=direct and DATABRICKS_BUNDLE_ENGINE= work +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "4 unchanged" trace $CLI bundle plan | contains.py "4 unchanged" trace print_requests.py --get //jobs/get | contains.py 'engine/direct' diff --git a/acceptance/bundle/migrate/command/permissions/terraform-requests.json b/acceptance/bundle/migrate/command/permissions/terraform-requests.json new file mode 100644 index 00000000000..a8894d9f79a --- /dev/null +++ b/acceptance/bundle/migrate/command/permissions/terraform-requests.json @@ -0,0 +1,80 @@ +[ + { + "method": "POST", + "path": "/api/2.0/pipelines", + "body": { + "channel": "CURRENT", + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/default/state/metadata.json" + }, + "edition": "ADVANCED", + "libraries": [ + { + "notebook": { + "path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/default/files/pipeline" + } + } + ], + "name": "Test Migration Pipeline" + } + }, + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Migration Job", + "queue": { + "enabled": true + }, + "tasks": [ + { + "notebook_task": { + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/default/files/notebook", + "source": "WORKSPACE" + }, + "task_key": "main" + } + ] + } + }, + { + "method": "PUT", + "path": "/api/2.0/permissions/pipelines/79fe85ff-42ab-b5b8-79fe-85ff42abb5b9", + "body": { + "access_control_list": [ + { + "permission_level": "CAN_MANAGE", + "user_name": "manager@databricks.com" + }, + { + "permission_level": "IS_OWNER", + "user_name": "tester@databricks.com" + } + ] + } + }, + { + "method": "PUT", + "path": "/api/2.0/permissions/jobs/8790610854067598000", + "body": { + "access_control_list": [ + { + "permission_level": "CAN_VIEW", + "user_name": "viewer@databricks.com" + }, + { + "permission_level": "IS_OWNER", + "user_name": "tester@databricks.com" + } + ] + } + } +] diff --git a/acceptance/bundle/migrate/command/permissions/terraform.tfstate b/acceptance/bundle/migrate/command/permissions/terraform.tfstate index 82f69dca2b8..a1561224071 100644 --- a/acceptance/bundle/migrate/command/permissions/terraform.tfstate +++ b/acceptance/bundle/migrate/command/permissions/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 5, - "lineage": "a1b2c3d4-0000-4000-8000-000000000007", + "lineage": "a0fc6106-3686-738c-7a93-06c0a226574f", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,35 +11,377 @@ "name": "test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 2, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Migration Job"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790610854067598000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Migration Job", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [ + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "", + "library": [], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [ + { + "base_parameters": null, + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/default/files/notebook", + "source": "WORKSPACE", + "warehouse_id": "" + } + ], + "notification_settings": [], + "pipeline_task": [], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "main", + "timeout_seconds": 0, + "webhook_notifications": [] + } + ], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790610854067598000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] }, { "mode": "managed", - "type": "databricks_pipeline", - "name": "test_pipeline", + "type": "databricks_permissions", + "name": "job_test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.pipelines.test_pipeline__", "name": "Test Migration Pipeline"}} + { + "schema_version": 0, + "attributes": { + "access_control": [ + { + "group_name": "", + "permission_level": "CAN_VIEW", + "service_principal_name": "", + "user_name": "viewer@databricks.com" + }, + { + "group_name": "", + "permission_level": "IS_OWNER", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "alert_v2_id": null, + "app_name": null, + "authorization": null, + "cluster_id": null, + "cluster_policy_id": null, + "dashboard_id": null, + "database_instance_name": null, + "database_project_name": null, + "directory_id": null, + "directory_path": null, + "experiment_id": null, + "id": "/jobs/8790610854067598000", + "instance_pool_id": null, + "job_id": "8790610854067598000", + "knowledge_assistant_id": null, + "notebook_id": null, + "notebook_path": null, + "object_type": "job", + "pipeline_id": null, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "registered_model_id": null, + "repo_id": null, + "repo_path": null, + "serving_endpoint_id": null, + "sql_alert_id": null, + "sql_dashboard_id": null, + "sql_endpoint_id": null, + "sql_query_id": null, + "supervisor_agent_id": null, + "vector_search_endpoint_id": null, + "workspace_file_id": null, + "workspace_file_path": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_job.test_job" + ] + } ] }, { "mode": "managed", "type": "databricks_permissions", - "name": "job_test_job", + "name": "pipeline_test_pipeline", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job.permissions__"}} + { + "schema_version": 0, + "attributes": { + "access_control": [ + { + "group_name": "", + "permission_level": "CAN_MANAGE", + "service_principal_name": "", + "user_name": "manager@databricks.com" + }, + { + "group_name": "", + "permission_level": "IS_OWNER", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "alert_v2_id": null, + "app_name": null, + "authorization": null, + "cluster_id": null, + "cluster_policy_id": null, + "dashboard_id": null, + "database_instance_name": null, + "database_project_name": null, + "directory_id": null, + "directory_path": null, + "experiment_id": null, + "id": "/pipelines/79fe85ff-42ab-b5b8-79fe-85ff42abb5b9", + "instance_pool_id": null, + "job_id": null, + "knowledge_assistant_id": null, + "notebook_id": null, + "notebook_path": null, + "object_type": "pipelines", + "pipeline_id": "79fe85ff-42ab-b5b8-79fe-85ff42abb5b9", + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "registered_model_id": null, + "repo_id": null, + "repo_path": null, + "serving_endpoint_id": null, + "sql_alert_id": null, + "sql_dashboard_id": null, + "sql_endpoint_id": null, + "sql_query_id": null, + "supervisor_agent_id": null, + "vector_search_endpoint_id": null, + "workspace_file_id": null, + "workspace_file_path": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_pipeline.test_pipeline" + ] + } ] }, { "mode": "managed", - "type": "databricks_permissions", - "name": "pipeline_test_pipeline", + "type": "databricks_pipeline", + "name": "test_pipeline", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.pipelines.test_pipeline.permissions__"}} + { + "schema_version": 0, + "attributes": { + "allow_duplicate_names": false, + "budget_policy_id": null, + "catalog": null, + "cause": null, + "channel": "CURRENT", + "cluster": [], + "cluster_id": null, + "configuration": null, + "continuous": false, + "creator_user_name": "tester@databricks.com", + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/default/state/metadata.json", + "version_id": "" + } + ], + "development": false, + "edition": "ADVANCED", + "environment": [], + "event_log": [], + "expected_last_modified": 0, + "filters": [], + "gateway_definition": [], + "health": null, + "id": "79fe85ff-42ab-b5b8-79fe-85ff42abb5b9", + "ingestion_definition": [], + "last_modified": 1790610854055, + "latest_updates": null, + "library": [ + { + "file": [], + "glob": [], + "jar": "", + "maven": [], + "notebook": [ + { + "path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/default/files/pipeline" + } + ], + "whl": "" + } + ], + "name": "Test Migration Pipeline", + "notification": [], + "photon": false, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "restart_window": [], + "root_path": null, + "run_as": [], + "run_as_user_name": "tester@databricks.com", + "schema": null, + "serverless": false, + "serverless_compute_id": null, + "state": "IDLE", + "storage": "dbfs:/pipelines/79fe85ff-42ab-b5b8-79fe-85ff42abb5b9", + "tags": null, + "target": null, + "timeouts": null, + "trigger": [], + "url": "[DATABRICKS_URL]/#joblist/pipelines/79fe85ff-42ab-b5b8-79fe-85ff42abb5b9", + "usage_policy_id": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19" + } ] } - ] + ], + "check_results": null } From cd5ee43714f6a91d5de505f877258d08313783c4 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 28 Sep 2026 18:35:04 +0200 Subject: [PATCH 03/15] acceptance: capture_tfstate.py + record/replay for migrate/auto/default Add capture_tfstate.py (freezes a real terraform deploy's tfstate + resource requests into the test source dir, normalizing host and UNIQUE_NAME to placeholders) and harden replay_tfstate.py to restore those placeholders for the current run. Convert auto/default to record/replay as the simple single-job example (permissions is the multi-resource one). Co-authored-by: Isaac --- acceptance/bin/capture_tfstate.py | 75 ++++++++++++++ acceptance/bin/replay_tfstate.py | 15 ++- .../bundle/migrate/auto/default/output.txt | 10 +- acceptance/bundle/migrate/auto/default/script | 14 ++- .../auto/default/terraform-requests.json | 19 ++++ .../migrate/auto/default/terraform.tfstate | 99 +++++++++++++++++-- 6 files changed, 211 insertions(+), 21 deletions(-) create mode 100644 acceptance/bin/capture_tfstate.py create mode 100644 acceptance/bundle/migrate/auto/default/terraform-requests.json diff --git a/acceptance/bin/capture_tfstate.py b/acceptance/bin/capture_tfstate.py new file mode 100644 index 00000000000..a15d77567e9 --- /dev/null +++ b/acceptance/bin/capture_tfstate.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 +""" +Capture a terraform deployment's artifacts as migrate-test fixtures. Run ONCE, right after a +`DATABRICKS_BUNDLE_ENGINE=terraform bundle deploy`, while the terraform engine is still present. + +Writes into the test's SOURCE dir ($TESTDIR): + - terraform.tfstate the real terraform state + - terraform-requests.json the resource-mutating requests (with bodies) terraform issued + +replay_tfstate.py later replays the requests to reconstruct a real terraform-shaped backend and +drops in the (id-remapped) tfstate, so the migrate test starts from a real terraform deployment +without running the (removed) terraform engine. The capture-time host is normalized to +[DATABRICKS_URL] so the fixtures do not embed a per-run port. + +Usage: capture_tfstate.py [TARGET] (TARGET defaults to "default") +""" + +import json +import os +import re +import sys + +TESTDIR = os.environ["TESTDIR"] +HOST = os.environ.get("DATABRICKS_HOST", "").rstrip("/") +# Per-run values baked into the captured state/requests are normalized to placeholders so the +# fixtures are frozen; replay_tfstate.py substitutes the current run's values back in. +UNIQUE_NAME = os.environ.get("UNIQUE_NAME", "") + +# Requests that build backend resource state; everything else (file sync, state push, lock, +# telemetry, scim, mkdirs, deletes) is deploy plumbing the migrate test does not need reconstructed. +SKIP = re.compile(r"/api/2\.0/workspace(/|-files)|/telemetry|/scim|/\.well-known|/state/|/mkdirs") + + +def read_json_many(s): + dec = json.JSONDecoder() + out = [] + pos, n = 0, len(s) + while pos < n: + while pos < n and s[pos] in " \t\r\n": + pos += 1 + if pos >= n: + break + obj, pos = dec.raw_decode(s, pos) + out.append(obj) + return out + + +def norm(text): + if HOST: + text = text.replace(HOST, "[DATABRICKS_URL]") + # UNIQUE_NAME is a long random per-run token, so a plain replace is safe. + if len(UNIQUE_NAME) >= 8: + text = text.replace(UNIQUE_NAME, "[UNIQUE_NAME]") + return text + + +def main(): + target = sys.argv[1] if len(sys.argv) > 1 else "default" + tfstate_raw = open(f".databricks/bundle/{target}/terraform/terraform.tfstate").read() + requests = read_json_many(open(os.environ["OUT_REQUESTS"]).read()) + + kept = [ + {"method": r["method"], "path": r["path"], "body": r.get("body")} + for r in requests + if r.get("method") in ("POST", "PUT", "PATCH") and not SKIP.search(r.get("path", "")) + ] + + with open(os.path.join(TESTDIR, "terraform.tfstate"), "w") as f: + f.write(norm(tfstate_raw)) + with open(os.path.join(TESTDIR, "terraform-requests.json"), "w") as f: + f.write(norm(json.dumps(kept, indent=2)) + "\n") + + +if __name__ == "__main__": + main() diff --git a/acceptance/bin/replay_tfstate.py b/acceptance/bin/replay_tfstate.py index 8488d33e776..da09d9b35f9 100644 --- a/acceptance/bin/replay_tfstate.py +++ b/acceptance/bin/replay_tfstate.py @@ -22,6 +22,8 @@ import sys CLI = os.environ["CLI"] +HOST = os.environ.get("DATABRICKS_HOST", "").rstrip("/") +UNIQUE_NAME = os.environ.get("UNIQUE_NAME", "") # Per resource: which response field carries the new id. Terraform's tfstate stores the same value # as the resource's `id`, keyed here by the create path so we can match a create to its tfstate entry. @@ -51,8 +53,19 @@ def main(): parser.add_argument("-t", "--target", default="default") args = parser.parse_args() - requests = json.loads(open(args.requests).read()) + requests_raw = open(args.requests).read() tfstate_raw = open(args.tfstate).read() + + # Restore this run's values into the frozen fixtures. UNIQUE_NAME goes into both (resource + # names must match the current config); the host goes into the requests we issue, but the + # tfstate keeps [DATABRICKS_URL] so print_state's output matches the goldens. + if UNIQUE_NAME: + requests_raw = requests_raw.replace("[UNIQUE_NAME]", UNIQUE_NAME) + tfstate_raw = tfstate_raw.replace("[UNIQUE_NAME]", UNIQUE_NAME) + if HOST: + requests_raw = requests_raw.replace("[DATABRICKS_URL]", HOST) + + requests = json.loads(requests_raw) tfstate = json.loads(tfstate_raw) # Drop the fixtures from the bundle root so a later deploy does not sync them as bundle files. diff --git a/acceptance/bundle/migrate/auto/default/output.txt b/acceptance/bundle/migrate/auto/default/output.txt index 152a9bfc05d..e5a10caf919 100644 --- a/acceptance/bundle/migrate/auto/default/output.txt +++ b/acceptance/bundle/migrate/auto/default/output.txt @@ -1,13 +1,13 @@ -=== Seed a terraform-state fixture from a prior terraform deployment ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === 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). Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... Migrated 1 resource to direct deployment engine. -Files: 0 uploaded, 0 deleted +Files: 1 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged >>> print_migration_telemetry @@ -15,10 +15,8 @@ direct_migrated_via_default true === Direct-engine state is now in place; terraform state is backed up ->>> find .databricks/bundle -name resources.json -type f +>>> find.py \.databricks/.*(\.tfstate|resources.*\.json|\.wal) .databricks/bundle/default/resources.json - ->>> find .databricks/bundle -name terraform.tfstate* -type f .databricks/bundle/default/terraform/terraform.tfstate.backup === Remote state also reflects the migration (force-pull surfaces workspace state) diff --git a/acceptance/bundle/migrate/auto/default/script b/acceptance/bundle/migrate/auto/default/script index df531ba65f3..28f598a5dfc 100644 --- a/acceptance/bundle/migrate/auto/default/script +++ b/acceptance/bundle/migrate/auto/default/script @@ -1,11 +1,10 @@ export DATABRICKS_BUNDLE_ENGINE= -# A prior terraform deployment left this bundle on the terraform engine. The terraform engine was -# removed in v1.19.0, so seed its state from a fixture (seed_tfstate.py deploys on direct to create -# matching backend resources, threads their ids into the checked-in terraform.tfstate, and drops -# the direct state so the bundle resolves to terraform again) instead of a real terraform deploy. -title "Seed a terraform-state fixture from a prior terraform deployment" -trace seed_tfstate.py terraform.tfstate +# Replay a prior terraform deployment (its resource requests were captured from a real terraform +# run), standing in for `DATABRICKS_BUNDLE_ENGINE=terraform bundle deploy` now that migrate tests +# must not deploy with terraform. +title "Replay a prior terraform deployment" +trace replay_tfstate.py terraform-requests.json terraform.tfstate rm -f "$OUT_REQUESTS" title "Redeploy with nothing set: direct is the default, so auto-migration triggers" @@ -14,8 +13,7 @@ trace print_migration_telemetry rm -f "$OUT_REQUESTS" title "Direct-engine state is now in place; terraform state is backed up\n" -trace find .databricks/bundle -name "resources.json" -type f -trace find .databricks/bundle -name "terraform.tfstate*" -type f +trace find.py '\.databricks/.*(\.tfstate|resources.*\.json|\.wal)' title "Remote state also reflects the migration (force-pull surfaces workspace state)\n" trace $CLI bundle debug states --force-pull diff --git a/acceptance/bundle/migrate/auto/default/terraform-requests.json b/acceptance/bundle/migrate/auto/default/terraform-requests.json new file mode 100644 index 00000000000..6482593b189 --- /dev/null +++ b/acceptance/bundle/migrate/auto/default/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Auto-Migrate Job", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/auto/default/terraform.tfstate b/acceptance/bundle/migrate/auto/default/terraform.tfstate index 02a0a6d3d19..c04f332a595 100644 --- a/acceptance/bundle/migrate/auto/default/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/default/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "a1b2c3d4-0001-4aaa-8bbb-000000000001", + "lineage": "c39488aa-8f36-06fd-a7cb-3f0c95b4c506", + "outputs": {}, "resources": [ { "mode": "managed", @@ -11,13 +12,99 @@ "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { - "schema_version": 0, + "schema_version": 2, "attributes": { - "id": "__ID_resources.jobs.test_job__", - "name": "Test Auto-Migrate Job" - } + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790612527183335000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Auto-Migrate Job", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790612527183335000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" } ] } - ] + ], + "check_results": null } From 439082ec3d786719914c3f04352f7789ffeaefb9 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 28 Sep 2026 18:36:35 +0200 Subject: [PATCH 04/15] acceptance: broaden replay_tfstate.py id fields for UC/dashboard/experiment resources Co-authored-by: Isaac --- acceptance/bin/replay_tfstate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acceptance/bin/replay_tfstate.py b/acceptance/bin/replay_tfstate.py index da09d9b35f9..c25fb4bb8fa 100644 --- a/acceptance/bin/replay_tfstate.py +++ b/acceptance/bin/replay_tfstate.py @@ -27,7 +27,7 @@ # Per resource: which response field carries the new id. Terraform's tfstate stores the same value # as the resource's `id`, keyed here by the create path so we can match a create to its tfstate entry. -ID_FIELDS = ["job_id", "pipeline_id", "id", "full_name", "name"] +ID_FIELDS = ["job_id", "pipeline_id", "dashboard_id", "experiment_id", "full_name", "id", "name"] def apply_map(text, id_map): From 7f4a56025c938f293b0cf11c03006fe21cbf16eb Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 28 Sep 2026 18:50:09 +0200 Subject: [PATCH 05/15] acceptance: make capture_tfstate.py / replay_tfstate.py executable Committed 100644, so a fresh checkout (CI) fails every capture/replay with permission denied. Co-authored-by: Isaac --- acceptance/bin/capture_tfstate.py | 0 acceptance/bin/replay_tfstate.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 acceptance/bin/capture_tfstate.py mode change 100644 => 100755 acceptance/bin/replay_tfstate.py diff --git a/acceptance/bin/capture_tfstate.py b/acceptance/bin/capture_tfstate.py old mode 100644 new mode 100755 diff --git a/acceptance/bin/replay_tfstate.py b/acceptance/bin/replay_tfstate.py old mode 100644 new mode 100755 From 5bc14c52babf4a2979695238fa7424d69e2650cb Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 28 Sep 2026 18:49:11 +0200 Subject: [PATCH 06/15] acceptance: record/replay for the UC migrate tests (schema/volume/registered_model/pipeline) Convert the 11 UC id-field/normalization migrate tests to the record/replay pattern: check in the real terraform.tfstate + the terraform deploy's resource requests (captured from a real terraform run), replay the requests so the backend holds terraform-shaped resources, and migrate. The recreate/rename/normalize behavior is preserved and now exercised against a real terraform state (e.g. reconcileIDFields sees the real deployed catalog_name). Also mark capture_tfstate.py and replay_tfstate.py executable (they were committed 100644, which fails with Permission denied on a fresh checkout / CI). Co-authored-by: Isaac (cherry picked from commit 0718bfbad797955212b096d5e3f92190e85d0a76) --- .../auto/pipeline-storage-change/output.txt | 6 +- .../auto/pipeline-storage-change/script | 5 +- .../terraform-requests.json | 24 +++++ .../pipeline-storage-change/terraform.tfstate | 92 +++++++++++++++++++ .../terraform.tfstate.tmpl | 22 ----- .../output.txt | 6 +- .../registered-model-catalog-change/script | 4 +- .../terraform-requests.json | 18 ++++ .../terraform.tfstate | 33 ++++++- .../auto/registered-model-rename/output.txt | 6 +- .../auto/registered-model-rename/script | 5 +- .../terraform-requests.json | 19 ++++ .../registered-model-rename/terraform.tfstate | 79 ++++++++++++++++ .../terraform.tfstate.tmpl | 36 -------- .../auto/schema-catalog-change/output.txt | 6 +- .../migrate/auto/schema-catalog-change/script | 4 +- .../terraform-requests.json | 17 ++++ .../schema-catalog-change/terraform.tfstate | 30 +++++- .../auto/schema-name-normalized/output.txt | 6 +- .../auto/schema-name-normalized/script | 8 +- .../terraform-requests.json | 10 ++ .../schema-name-normalized/terraform.tfstate | 41 +++++++++ .../terraform.tfstate.tmpl | 22 ----- .../migrate/auto/schema-rename/output.txt | 6 +- .../bundle/migrate/auto/schema-rename/script | 5 +- .../schema-rename/terraform-requests.json | 10 ++ .../auto/schema-rename/terraform.tfstate | 41 +++++++++ .../auto/schema-rename/terraform.tfstate.tmpl | 22 ----- .../auto/schema-storage-change/output.txt | 7 +- .../migrate/auto/schema-storage-change/script | 5 +- .../terraform-requests.json | 11 +++ .../schema-storage-change/terraform.tfstate | 28 +++++- .../auto/schema-storage-normalized/output.txt | 6 +- .../auto/schema-storage-normalized/script | 4 +- .../terraform-requests.json | 11 +++ .../terraform.tfstate | 28 +++++- .../auto/volume-name-normalized/output.txt | 6 +- .../auto/volume-name-normalized/script | 8 +- .../terraform-requests.json | 12 +++ .../volume-name-normalized/terraform.tfstate | 39 ++++++++ .../terraform.tfstate.tmpl | 24 ----- .../migrate/auto/volume-rename/output.txt | 6 +- .../bundle/migrate/auto/volume-rename/script | 5 +- .../volume-rename/terraform-requests.json | 20 ++++ .../auto/volume-rename/terraform.tfstate | 73 +++++++++++++++ .../auto/volume-rename/terraform.tfstate.tmpl | 37 -------- .../auto/volume-type-change/output.txt | 4 +- .../migrate/auto/volume-type-change/script | 4 +- .../terraform-requests.json | 12 +++ .../auto/volume-type-change/terraform.tfstate | 25 ++++- 50 files changed, 706 insertions(+), 252 deletions(-) create mode 100644 acceptance/bundle/migrate/auto/pipeline-storage-change/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/pipeline-storage-change/terraform.tfstate delete mode 100644 acceptance/bundle/migrate/auto/pipeline-storage-change/terraform.tfstate.tmpl create mode 100644 acceptance/bundle/migrate/auto/registered-model-catalog-change/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/registered-model-rename/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/registered-model-rename/terraform.tfstate delete mode 100644 acceptance/bundle/migrate/auto/registered-model-rename/terraform.tfstate.tmpl create mode 100644 acceptance/bundle/migrate/auto/schema-catalog-change/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/schema-name-normalized/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/schema-name-normalized/terraform.tfstate delete mode 100644 acceptance/bundle/migrate/auto/schema-name-normalized/terraform.tfstate.tmpl create mode 100644 acceptance/bundle/migrate/auto/schema-rename/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/schema-rename/terraform.tfstate delete mode 100644 acceptance/bundle/migrate/auto/schema-rename/terraform.tfstate.tmpl create mode 100644 acceptance/bundle/migrate/auto/schema-storage-change/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/schema-storage-normalized/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/volume-name-normalized/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/volume-name-normalized/terraform.tfstate delete mode 100644 acceptance/bundle/migrate/auto/volume-name-normalized/terraform.tfstate.tmpl create mode 100644 acceptance/bundle/migrate/auto/volume-rename/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/volume-rename/terraform.tfstate delete mode 100644 acceptance/bundle/migrate/auto/volume-rename/terraform.tfstate.tmpl create mode 100644 acceptance/bundle/migrate/auto/volume-type-change/terraform-requests.json diff --git a/acceptance/bundle/migrate/auto/pipeline-storage-change/output.txt b/acceptance/bundle/migrate/auto/pipeline-storage-change/output.txt index 81bd814e10b..962614d258e 100644 --- a/acceptance/bundle/migrate/auto/pipeline-storage-change/output.txt +++ b/acceptance/bundle/migrate/auto/pipeline-storage-change/output.txt @@ -1,6 +1,6 @@ -=== A prior terraform deployment created the pipeline (seed the fixture) ->>> seed_tfstate.py terraform.tfstate +=== Replay the prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Change immutable storage. Without --auto-approve the recreate is refused >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy @@ -17,7 +17,7 @@ Error: the deployment requires destructive actions, but the current console does Deleting data assets such as schemas, pipelines, or volumes may cause permanent data loss and should be carefully reviewed. To proceed, use --auto-approve after reviewing the plan above. -Files: 1 uploaded, 0 deleted +Files: 3 uploaded, 0 deleted Exit code: 1 diff --git a/acceptance/bundle/migrate/auto/pipeline-storage-change/script b/acceptance/bundle/migrate/auto/pipeline-storage-change/script index 2deb01e3c19..7f1172b1ad2 100644 --- a/acceptance/bundle/migrate/auto/pipeline-storage-change/script +++ b/acceptance/bundle/migrate/auto/pipeline-storage-change/script @@ -1,5 +1,4 @@ envsubst < databricks.yml.tmpl > databricks.yml -envsubst < terraform.tfstate.tmpl > terraform.tfstate && rm terraform.tfstate.tmpl cleanup() { title "Cleanup" @@ -7,8 +6,8 @@ cleanup() { } trap cleanup EXIT -title "A prior terraform deployment created the pipeline (seed the fixture)" -trace seed_tfstate.py terraform.tfstate +title "Replay the prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate rm -f "$OUT_REQUESTS" title "Change immutable storage. Without --auto-approve the recreate is refused" diff --git a/acceptance/bundle/migrate/auto/pipeline-storage-change/terraform-requests.json b/acceptance/bundle/migrate/auto/pipeline-storage-change/terraform-requests.json new file mode 100644 index 00000000000..5297a9d03dd --- /dev/null +++ b/acceptance/bundle/migrate/auto/pipeline-storage-change/terraform-requests.json @@ -0,0 +1,24 @@ +[ + { + "method": "POST", + "path": "/api/2.0/pipelines", + "body": { + "channel": "CURRENT", + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/[UNIQUE_NAME]/state/metadata.json" + }, + "development": true, + "edition": "ADVANCED", + "libraries": [ + { + "notebook": { + "path": "/Workspace/Users/tester@databricks.com/.bundle/[UNIQUE_NAME]/files/nb" + } + } + ], + "name": "pipeline-[UNIQUE_NAME]", + "storage": "dbfs:/pipelines/[UNIQUE_NAME]-init" + } + } +] diff --git a/acceptance/bundle/migrate/auto/pipeline-storage-change/terraform.tfstate b/acceptance/bundle/migrate/auto/pipeline-storage-change/terraform.tfstate new file mode 100644 index 00000000000..472777cce39 --- /dev/null +++ b/acceptance/bundle/migrate/auto/pipeline-storage-change/terraform.tfstate @@ -0,0 +1,92 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "fd53c428-e47e-504a-18bc-74d100d9f9ab", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_pipeline", + "name": "my_pipeline", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "allow_duplicate_names": false, + "budget_policy_id": null, + "catalog": null, + "cause": null, + "channel": "CURRENT", + "cluster": [], + "cluster_id": null, + "configuration": null, + "continuous": false, + "creator_user_name": "tester@databricks.com", + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/[UNIQUE_NAME]/state/metadata.json", + "version_id": "" + } + ], + "development": true, + "edition": "ADVANCED", + "environment": [], + "event_log": [], + "expected_last_modified": 0, + "filters": [], + "gateway_definition": [], + "health": null, + "id": "79fe88b1-3ff7-b470-79fe-88b13ff7b471", + "ingestion_definition": [], + "last_modified": 1790613817537, + "latest_updates": null, + "library": [ + { + "file": [], + "glob": [], + "jar": "", + "maven": [], + "notebook": [ + { + "path": "/Workspace/Users/tester@databricks.com/.bundle/[UNIQUE_NAME]/files/nb" + } + ], + "whl": "" + } + ], + "name": "pipeline-[UNIQUE_NAME]", + "notification": [], + "photon": false, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "restart_window": [], + "root_path": null, + "run_as": [], + "run_as_user_name": "tester@databricks.com", + "schema": null, + "serverless": false, + "serverless_compute_id": null, + "state": "IDLE", + "storage": "dbfs:/pipelines/[UNIQUE_NAME]-init", + "tags": null, + "target": null, + "timeouts": null, + "trigger": [], + "url": "[DATABRICKS_URL]/#joblist/pipelines/79fe88b1-3ff7-b470-79fe-88b13ff7b471", + "usage_policy_id": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19" + } + ] + } + ], + "check_results": null +} diff --git a/acceptance/bundle/migrate/auto/pipeline-storage-change/terraform.tfstate.tmpl b/acceptance/bundle/migrate/auto/pipeline-storage-change/terraform.tfstate.tmpl deleted file mode 100644 index a051bb6f646..00000000000 --- a/acceptance/bundle/migrate/auto/pipeline-storage-change/terraform.tfstate.tmpl +++ /dev/null @@ -1,22 +0,0 @@ -{ - "version": 4, - "terraform_version": "1.5.5", - "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", - "resources": [ - { - "mode": "managed", - "type": "databricks_pipeline", - "name": "my_pipeline", - "instances": [ - { - "attributes": { - "id": "__ID_resources.pipelines.my_pipeline__", - "name": "pipeline-$UNIQUE_NAME", - "storage": "dbfs:/pipelines/$UNIQUE_NAME-init" - } - } - ] - } - ] -} diff --git a/acceptance/bundle/migrate/auto/registered-model-catalog-change/output.txt b/acceptance/bundle/migrate/auto/registered-model-catalog-change/output.txt index 9ca35cb8aa5..a824176b8ed 100644 --- a/acceptance/bundle/migrate/auto/registered-model-catalog-change/output.txt +++ b/acceptance/bundle/migrate/auto/registered-model-catalog-change/output.txt @@ -4,8 +4,8 @@ "name": "othercat_[UNIQUE_NAME]" } -=== A prior terraform deployment left the model in catalog 'main' (seed the fixture) ->>> seed_tfstate.py terraform.tfstate +=== Replay the prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Move the model to another catalog and deploy on direct >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy @@ -14,7 +14,7 @@ Notice: migrating your bundle to direct deployment engine (https://github.com/da Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files... Migrated 1 resource to direct deployment engine. Recreated registered_models.my_model -Files: 1 uploaded, 0 deleted +Files: 2 uploaded, 0 deleted Resources: 1 created, 0 changed, 1 deleted, 0 unchanged >>> print_migration_telemetry diff --git a/acceptance/bundle/migrate/auto/registered-model-catalog-change/script b/acceptance/bundle/migrate/auto/registered-model-catalog-change/script index 5cc773e7c41..d260fc05a3d 100644 --- a/acceptance/bundle/migrate/auto/registered-model-catalog-change/script +++ b/acceptance/bundle/migrate/auto/registered-model-catalog-change/script @@ -13,8 +13,8 @@ cleanup() { } trap cleanup EXIT -title "A prior terraform deployment left the model in catalog 'main' (seed the fixture)" -trace seed_tfstate.py terraform.tfstate +title "Replay the prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate rm -f "$OUT_REQUESTS" title "Move the model to another catalog and deploy on direct" diff --git a/acceptance/bundle/migrate/auto/registered-model-catalog-change/terraform-requests.json b/acceptance/bundle/migrate/auto/registered-model-catalog-change/terraform-requests.json new file mode 100644 index 00000000000..6f4620d81f5 --- /dev/null +++ b/acceptance/bundle/migrate/auto/registered-model-catalog-change/terraform-requests.json @@ -0,0 +1,18 @@ +[ + { + "method": "POST", + "path": "/api/2.1/unity-catalog/catalogs", + "body": { + "name": "othercat_[UNIQUE_NAME]" + } + }, + { + "method": "POST", + "path": "/api/2.1/unity-catalog/models", + "body": { + "catalog_name": "main", + "name": "mymodel-[UNIQUE_NAME]", + "schema_name": "default" + } + } +] diff --git a/acceptance/bundle/migrate/auto/registered-model-catalog-change/terraform.tfstate b/acceptance/bundle/migrate/auto/registered-model-catalog-change/terraform.tfstate index 80a4289a1d6..3cf5038c0ba 100644 --- a/acceptance/bundle/migrate/auto/registered-model-catalog-change/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/registered-model-catalog-change/terraform.tfstate @@ -2,21 +2,44 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "lineage": "dff6923c-7f23-1707-8218-fab29ab6f508", + "outputs": {}, "resources": [ { "mode": "managed", "type": "databricks_registered_model", "name": "my_model", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { + "schema_version": 0, "attributes": { - "id": "__ID_resources.registered_models.my_model__", + "aliases": [], + "browse_only": false, "catalog_name": "main", - "schema_name": "default" - } + "comment": null, + "created_at": 1790613818295, + "created_by": "tester@databricks.com", + "full_name": "main.default.mymodel-[UNIQUE_NAME]", + "id": "main.default.mymodel-[UNIQUE_NAME]", + "metastore_id": "79fe88b1-6d1d-db28-79fe-88b16d1ddb29", + "name": "mymodel-[UNIQUE_NAME]", + "owner": "tester@databricks.com", + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_name": "default", + "storage_location": null, + "updated_at": 1790613818295, + "updated_by": "tester@databricks.com" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/registered-model-rename/output.txt b/acceptance/bundle/migrate/auto/registered-model-rename/output.txt index 2a7b22f3b28..fbad32d54f3 100644 --- a/acceptance/bundle/migrate/auto/registered-model-rename/output.txt +++ b/acceptance/bundle/migrate/auto/registered-model-rename/output.txt @@ -1,6 +1,6 @@ -=== A prior terraform deployment created the schema and model (seed the fixture) ->>> seed_tfstate.py terraform.tfstate +=== Replay the prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Rename the model (an immutable id field) and deploy on direct >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy @@ -9,7 +9,7 @@ Notice: migrating your bundle to direct deployment engine (https://github.com/da Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files... Migrated 2 resources to direct deployment engine. Recreated registered_models.my_model -Files: 1 uploaded, 0 deleted +Files: 2 uploaded, 0 deleted Resources: 1 created, 0 changed, 1 deleted, 1 unchanged >>> print_migration_telemetry diff --git a/acceptance/bundle/migrate/auto/registered-model-rename/script b/acceptance/bundle/migrate/auto/registered-model-rename/script index e9d1763e9d8..0b81939d6d4 100644 --- a/acceptance/bundle/migrate/auto/registered-model-rename/script +++ b/acceptance/bundle/migrate/auto/registered-model-rename/script @@ -1,5 +1,4 @@ envsubst < databricks.yml.tmpl > databricks.yml -envsubst < terraform.tfstate.tmpl > terraform.tfstate && rm terraform.tfstate.tmpl cleanup() { title "Cleanup" @@ -7,8 +6,8 @@ cleanup() { } trap cleanup EXIT -title "A prior terraform deployment created the schema and model (seed the fixture)" -trace seed_tfstate.py terraform.tfstate +title "Replay the prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate rm -f "$OUT_REQUESTS" title "Rename the model (an immutable id field) and deploy on direct" diff --git a/acceptance/bundle/migrate/auto/registered-model-rename/terraform-requests.json b/acceptance/bundle/migrate/auto/registered-model-rename/terraform-requests.json new file mode 100644 index 00000000000..b9adfbc0f4d --- /dev/null +++ b/acceptance/bundle/migrate/auto/registered-model-rename/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", + "body": { + "catalog_name": "main", + "name": "mschema-[UNIQUE_NAME]" + } + }, + { + "method": "POST", + "path": "/api/2.1/unity-catalog/models", + "body": { + "catalog_name": "main", + "name": "themodel-[UNIQUE_NAME]", + "schema_name": "mschema-[UNIQUE_NAME]" + } + } +] diff --git a/acceptance/bundle/migrate/auto/registered-model-rename/terraform.tfstate b/acceptance/bundle/migrate/auto/registered-model-rename/terraform.tfstate new file mode 100644 index 00000000000..24bd20d48aa --- /dev/null +++ b/acceptance/bundle/migrate/auto/registered-model-rename/terraform.tfstate @@ -0,0 +1,79 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 3, + "lineage": "d13e5e08-3a73-ee41-a08d-10264c8fe9f1", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_registered_model", + "name": "my_model", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "aliases": [], + "browse_only": false, + "catalog_name": "main", + "comment": null, + "created_at": 1790613818146, + "created_by": "tester@databricks.com", + "full_name": "main.mschema-[UNIQUE_NAME].themodel-[UNIQUE_NAME]", + "id": "main.mschema-[UNIQUE_NAME].themodel-[UNIQUE_NAME]", + "metastore_id": "79fe88b1-6443-e150-79fe-88b16443e151", + "name": "themodel-[UNIQUE_NAME]", + "owner": "tester@databricks.com", + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_name": "mschema-[UNIQUE_NAME]", + "storage_location": null, + "updated_at": 1790613818146, + "updated_by": "tester@databricks.com" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_schema.parent" + ] + } + ] + }, + { + "mode": "managed", + "type": "databricks_schema", + "name": "parent", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "catalog_name": "main", + "comment": null, + "enable_predictive_optimization": "INHERIT", + "force_destroy": true, + "id": "main.mschema-[UNIQUE_NAME]", + "metastore_id": "120efa64-9b68-46ba-be38-f319458430d2", + "name": "mschema-[UNIQUE_NAME]", + "owner": "tester@databricks.com", + "properties": null, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_id": "79fe88b1-63b3-6508-79fe-88b163b368f0", + "storage_root": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": null +} diff --git a/acceptance/bundle/migrate/auto/registered-model-rename/terraform.tfstate.tmpl b/acceptance/bundle/migrate/auto/registered-model-rename/terraform.tfstate.tmpl deleted file mode 100644 index 9aef45fe87f..00000000000 --- a/acceptance/bundle/migrate/auto/registered-model-rename/terraform.tfstate.tmpl +++ /dev/null @@ -1,36 +0,0 @@ -{ - "version": 4, - "terraform_version": "1.5.5", - "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", - "resources": [ - { - "mode": "managed", - "type": "databricks_schema", - "name": "parent", - "instances": [ - { - "attributes": { - "id": "__ID_resources.schemas.parent__", - "catalog_name": "main" - } - } - ] - }, - { - "mode": "managed", - "type": "databricks_registered_model", - "name": "my_model", - "instances": [ - { - "attributes": { - "id": "__ID_resources.registered_models.my_model__", - "name": "themodel-$UNIQUE_NAME", - "catalog_name": "main", - "schema_name": "mschema-$UNIQUE_NAME" - } - } - ] - } - ] -} diff --git a/acceptance/bundle/migrate/auto/schema-catalog-change/output.txt b/acceptance/bundle/migrate/auto/schema-catalog-change/output.txt index 6f144756daa..5295feaa2e9 100644 --- a/acceptance/bundle/migrate/auto/schema-catalog-change/output.txt +++ b/acceptance/bundle/migrate/auto/schema-catalog-change/output.txt @@ -4,8 +4,8 @@ "name": "othercat_[UNIQUE_NAME]" } -=== A prior terraform deployment left the schema in catalog 'main' (seed the fixture) ->>> seed_tfstate.py terraform.tfstate +=== Replay the prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Move the schema to another catalog. Without --auto-approve the recreate is refused >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy @@ -20,7 +20,7 @@ Error: the deployment requires destructive actions, but the current console does Deleting data assets such as schemas, pipelines, or volumes may cause permanent data loss and should be carefully reviewed. To proceed, use --auto-approve after reviewing the plan above. -Files: 1 uploaded, 0 deleted +Files: 2 uploaded, 0 deleted Exit code: 1 diff --git a/acceptance/bundle/migrate/auto/schema-catalog-change/script b/acceptance/bundle/migrate/auto/schema-catalog-change/script index 726f7f05a8e..3f166db2b19 100644 --- a/acceptance/bundle/migrate/auto/schema-catalog-change/script +++ b/acceptance/bundle/migrate/auto/schema-catalog-change/script @@ -13,8 +13,8 @@ cleanup() { } trap cleanup EXIT -title "A prior terraform deployment left the schema in catalog 'main' (seed the fixture)" -trace seed_tfstate.py terraform.tfstate +title "Replay the prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate rm -f "$OUT_REQUESTS" title "Move the schema to another catalog. Without --auto-approve the recreate is refused" diff --git a/acceptance/bundle/migrate/auto/schema-catalog-change/terraform-requests.json b/acceptance/bundle/migrate/auto/schema-catalog-change/terraform-requests.json new file mode 100644 index 00000000000..eda99b84d42 --- /dev/null +++ b/acceptance/bundle/migrate/auto/schema-catalog-change/terraform-requests.json @@ -0,0 +1,17 @@ +[ + { + "method": "POST", + "path": "/api/2.1/unity-catalog/catalogs", + "body": { + "name": "othercat_[UNIQUE_NAME]" + } + }, + { + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", + "body": { + "catalog_name": "main", + "name": "myschema-[UNIQUE_NAME]" + } + } +] diff --git a/acceptance/bundle/migrate/auto/schema-catalog-change/terraform.tfstate b/acceptance/bundle/migrate/auto/schema-catalog-change/terraform.tfstate index 582a576caa1..f303e9926c0 100644 --- a/acceptance/bundle/migrate/auto/schema-catalog-change/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/schema-catalog-change/terraform.tfstate @@ -2,20 +2,40 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "lineage": "8c9edde2-6ce1-15eb-cb32-4db7169733c3", + "outputs": {}, "resources": [ { "mode": "managed", "type": "databricks_schema", "name": "my_schema", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { + "schema_version": 0, "attributes": { - "id": "__ID_resources.schemas.my_schema__", - "catalog_name": "main" - } + "catalog_name": "main", + "comment": null, + "enable_predictive_optimization": "INHERIT", + "force_destroy": true, + "id": "main.myschema-[UNIQUE_NAME]", + "metastore_id": "120efa64-9b68-46ba-be38-f319458430d2", + "name": "myschema-[UNIQUE_NAME]", + "owner": "tester@databricks.com", + "properties": null, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_id": "79fe88b1-685c-28b0-79fe-88b1685c28b1", + "storage_root": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==" } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/schema-name-normalized/output.txt b/acceptance/bundle/migrate/auto/schema-name-normalized/output.txt index 7e11c96463f..cdfe47510ee 100644 --- a/acceptance/bundle/migrate/auto/schema-name-normalized/output.txt +++ b/acceptance/bundle/migrate/auto/schema-name-normalized/output.txt @@ -1,13 +1,13 @@ -=== A prior terraform deployment stored the lowercased schema name (seed the fixture) ->>> seed_tfstate.py terraform.tfstate +=== Replay the prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Migrate to direct with the same config (mixed-case name unchanged) >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files... Migrated 1 resource to direct deployment engine. -Files: 0 uploaded, 0 deleted +Files: 2 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged === Follow-up plan on direct converges (the case-only difference is not a change) diff --git a/acceptance/bundle/migrate/auto/schema-name-normalized/script b/acceptance/bundle/migrate/auto/schema-name-normalized/script index cadc5ec635c..442b762ee9d 100644 --- a/acceptance/bundle/migrate/auto/schema-name-normalized/script +++ b/acceptance/bundle/migrate/auto/schema-name-normalized/script @@ -1,5 +1,4 @@ envsubst < databricks.yml.tmpl > databricks.yml -envsubst < terraform.tfstate.tmpl > terraform.tfstate && rm terraform.tfstate.tmpl cleanup() { title "Cleanup" @@ -10,11 +9,10 @@ trap cleanup EXIT # The config uses a mixed-case schema name; UC lowercases the stored name, so the deployed id # differs from config by case only, without the user changing anything. reconcileIDFields # treats a case-only difference as backend normalization and keeps the config value, so the -# migration proceeds with no warning and the plan converges. The fixture holds the lowercased -# (deployed) name to mirror what a terraform deployment would have recorded. +# migration proceeds with no warning and the plan converges. -title "A prior terraform deployment stored the lowercased schema name (seed the fixture)" -trace seed_tfstate.py terraform.tfstate +title "Replay the prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate title "Migrate to direct with the same config (mixed-case name unchanged)" trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy diff --git a/acceptance/bundle/migrate/auto/schema-name-normalized/terraform-requests.json b/acceptance/bundle/migrate/auto/schema-name-normalized/terraform-requests.json new file mode 100644 index 00000000000..beed48833c5 --- /dev/null +++ b/acceptance/bundle/migrate/auto/schema-name-normalized/terraform-requests.json @@ -0,0 +1,10 @@ +[ + { + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", + "body": { + "catalog_name": "main", + "name": "MySchema-[UNIQUE_NAME]" + } + } +] diff --git a/acceptance/bundle/migrate/auto/schema-name-normalized/terraform.tfstate b/acceptance/bundle/migrate/auto/schema-name-normalized/terraform.tfstate new file mode 100644 index 00000000000..d328567decc --- /dev/null +++ b/acceptance/bundle/migrate/auto/schema-name-normalized/terraform.tfstate @@ -0,0 +1,41 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "79279b96-ff5f-62aa-efec-c286658acf2c", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_schema", + "name": "my_schema", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "catalog_name": "main", + "comment": null, + "enable_predictive_optimization": "INHERIT", + "force_destroy": true, + "id": "main.myschema-[UNIQUE_NAME]", + "metastore_id": "120efa64-9b68-46ba-be38-f319458430d2", + "name": "myschema-[UNIQUE_NAME]", + "owner": "tester@databricks.com", + "properties": null, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_id": "79fe88d4-0f11-57d0-79fe-88d40f1157d1", + "storage_root": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": null +} diff --git a/acceptance/bundle/migrate/auto/schema-name-normalized/terraform.tfstate.tmpl b/acceptance/bundle/migrate/auto/schema-name-normalized/terraform.tfstate.tmpl deleted file mode 100644 index 2f88ccf0058..00000000000 --- a/acceptance/bundle/migrate/auto/schema-name-normalized/terraform.tfstate.tmpl +++ /dev/null @@ -1,22 +0,0 @@ -{ - "version": 4, - "terraform_version": "1.5.5", - "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", - "resources": [ - { - "mode": "managed", - "type": "databricks_schema", - "name": "my_schema", - "instances": [ - { - "attributes": { - "id": "__ID_resources.schemas.my_schema__", - "name": "myschema-$UNIQUE_NAME", - "catalog_name": "main" - } - } - ] - } - ] -} diff --git a/acceptance/bundle/migrate/auto/schema-rename/output.txt b/acceptance/bundle/migrate/auto/schema-rename/output.txt index 927b31f0bb0..65e060f08f9 100644 --- a/acceptance/bundle/migrate/auto/schema-rename/output.txt +++ b/acceptance/bundle/migrate/auto/schema-rename/output.txt @@ -1,6 +1,6 @@ -=== A prior terraform deployment created the schema (seed the fixture) ->>> seed_tfstate.py terraform.tfstate +=== Replay the prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Rename the schema (an immutable id field). Without --auto-approve the recreate is refused >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy @@ -15,7 +15,7 @@ Error: the deployment requires destructive actions, but the current console does Deleting data assets such as schemas, pipelines, or volumes may cause permanent data loss and should be carefully reviewed. To proceed, use --auto-approve after reviewing the plan above. -Files: 1 uploaded, 0 deleted +Files: 2 uploaded, 0 deleted Exit code: 1 diff --git a/acceptance/bundle/migrate/auto/schema-rename/script b/acceptance/bundle/migrate/auto/schema-rename/script index 953e5371a9a..2286ccca1b2 100644 --- a/acceptance/bundle/migrate/auto/schema-rename/script +++ b/acceptance/bundle/migrate/auto/schema-rename/script @@ -1,5 +1,4 @@ envsubst < databricks.yml.tmpl > databricks.yml -envsubst < terraform.tfstate.tmpl > terraform.tfstate && rm terraform.tfstate.tmpl cleanup() { title "Cleanup" @@ -7,8 +6,8 @@ cleanup() { } trap cleanup EXIT -title "A prior terraform deployment created the schema (seed the fixture)" -trace seed_tfstate.py terraform.tfstate +title "Replay the prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate rm -f "$OUT_REQUESTS" title "Rename the schema (an immutable id field). Without --auto-approve the recreate is refused" diff --git a/acceptance/bundle/migrate/auto/schema-rename/terraform-requests.json b/acceptance/bundle/migrate/auto/schema-rename/terraform-requests.json new file mode 100644 index 00000000000..e7072606fd3 --- /dev/null +++ b/acceptance/bundle/migrate/auto/schema-rename/terraform-requests.json @@ -0,0 +1,10 @@ +[ + { + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", + "body": { + "catalog_name": "main", + "name": "myschema-[UNIQUE_NAME]" + } + } +] diff --git a/acceptance/bundle/migrate/auto/schema-rename/terraform.tfstate b/acceptance/bundle/migrate/auto/schema-rename/terraform.tfstate new file mode 100644 index 00000000000..5cda30b7890 --- /dev/null +++ b/acceptance/bundle/migrate/auto/schema-rename/terraform.tfstate @@ -0,0 +1,41 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "6b2758d5-3e2d-380e-9204-421634777e54", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_schema", + "name": "my_schema", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "catalog_name": "main", + "comment": null, + "enable_predictive_optimization": "INHERIT", + "force_destroy": true, + "id": "main.myschema-[UNIQUE_NAME]", + "metastore_id": "120efa64-9b68-46ba-be38-f319458430d2", + "name": "myschema-[UNIQUE_NAME]", + "owner": "tester@databricks.com", + "properties": null, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_id": "79fe88b1-3db7-d2a8-79fe-88b13db7d2a9", + "storage_root": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": null +} diff --git a/acceptance/bundle/migrate/auto/schema-rename/terraform.tfstate.tmpl b/acceptance/bundle/migrate/auto/schema-rename/terraform.tfstate.tmpl deleted file mode 100644 index 2f88ccf0058..00000000000 --- a/acceptance/bundle/migrate/auto/schema-rename/terraform.tfstate.tmpl +++ /dev/null @@ -1,22 +0,0 @@ -{ - "version": 4, - "terraform_version": "1.5.5", - "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", - "resources": [ - { - "mode": "managed", - "type": "databricks_schema", - "name": "my_schema", - "instances": [ - { - "attributes": { - "id": "__ID_resources.schemas.my_schema__", - "name": "myschema-$UNIQUE_NAME", - "catalog_name": "main" - } - } - ] - } - ] -} diff --git a/acceptance/bundle/migrate/auto/schema-storage-change/output.txt b/acceptance/bundle/migrate/auto/schema-storage-change/output.txt index 4875e8bda85..314ffb6b7cf 100644 --- a/acceptance/bundle/migrate/auto/schema-storage-change/output.txt +++ b/acceptance/bundle/migrate/auto/schema-storage-change/output.txt @@ -1,6 +1,8 @@ -=== A prior terraform deployment left the schema with storage_root s3://mybucket/init (seed the fixture) ->>> seed_tfstate.py terraform.tfstate +=== Replay the prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate + +>>> print_migration_telemetry === Change immutable storage_root; without --auto-approve the recreate is refused >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy @@ -28,7 +30,6 @@ direct_migrate_recreate_planned true >>> MSYS_NO_PATHCONV=1 [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json === With --auto-approve the migration commits and the recreate is applied on direct >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy --auto-approve diff --git a/acceptance/bundle/migrate/auto/schema-storage-change/script b/acceptance/bundle/migrate/auto/schema-storage-change/script index ab5d241da90..c0ab15856de 100644 --- a/acceptance/bundle/migrate/auto/schema-storage-change/script +++ b/acceptance/bundle/migrate/auto/schema-storage-change/script @@ -4,8 +4,9 @@ export DATABRICKS_BUNDLE_ENGINE= # workspace, so this is not Cloud-enabled. The recreate/refusal class it covers is verified # on cloud by schema-rename and pipeline-storage-change. -title "A prior terraform deployment left the schema with storage_root s3://mybucket/init (seed the fixture)" -trace seed_tfstate.py terraform.tfstate +title "Replay the prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate +trace print_migration_telemetry rm -f "$OUT_REQUESTS" title "Change immutable storage_root; without --auto-approve the recreate is refused" diff --git a/acceptance/bundle/migrate/auto/schema-storage-change/terraform-requests.json b/acceptance/bundle/migrate/auto/schema-storage-change/terraform-requests.json new file mode 100644 index 00000000000..0c3e56abc30 --- /dev/null +++ b/acceptance/bundle/migrate/auto/schema-storage-change/terraform-requests.json @@ -0,0 +1,11 @@ +[ + { + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", + "body": { + "catalog_name": "main", + "name": "myschema", + "storage_root": "s3://mybucket/init" + } + } +] diff --git a/acceptance/bundle/migrate/auto/schema-storage-change/terraform.tfstate b/acceptance/bundle/migrate/auto/schema-storage-change/terraform.tfstate index 66020f66167..90a6b74d9e4 100644 --- a/acceptance/bundle/migrate/auto/schema-storage-change/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/schema-storage-change/terraform.tfstate @@ -2,22 +2,40 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "lineage": "ed6ea4b1-1168-2291-5f1b-45c0c5698c28", + "outputs": {}, "resources": [ { "mode": "managed", "type": "databricks_schema", "name": "my_schema", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { + "schema_version": 0, "attributes": { - "id": "__ID_resources.schemas.my_schema__", - "name": "myschema", "catalog_name": "main", + "comment": null, + "enable_predictive_optimization": "INHERIT", + "force_destroy": true, + "id": "main.myschema", + "metastore_id": "120efa64-9b68-46ba-be38-f319458430d2", + "name": "myschema", + "owner": "tester@databricks.com", + "properties": null, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_id": "79fe88b1-3e30-0048-79fe-88b13e300049", "storage_root": "s3://mybucket/init" - } + }, + "sensitive_attributes": [], + "private": "bnVsbA==" } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/schema-storage-normalized/output.txt b/acceptance/bundle/migrate/auto/schema-storage-normalized/output.txt index 05cf6445bcd..ccb8f6f49fa 100644 --- a/acceptance/bundle/migrate/auto/schema-storage-normalized/output.txt +++ b/acceptance/bundle/migrate/auto/schema-storage-normalized/output.txt @@ -1,13 +1,13 @@ -=== A prior terraform deployment stored storage_root with the trailing slash stripped (seed the fixture) ->>> seed_tfstate.py terraform.tfstate +=== Replay the prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Migrate to direct with the same config (storage_root still has the trailing slash) >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... Migrated 1 resource to direct deployment engine. -Files: 0 uploaded, 0 deleted +Files: 1 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged === Follow-up plan on direct: does it converge or keep seeing a diff? diff --git a/acceptance/bundle/migrate/auto/schema-storage-normalized/script b/acceptance/bundle/migrate/auto/schema-storage-normalized/script index a9f3efea6b9..ea5185491af 100644 --- a/acceptance/bundle/migrate/auto/schema-storage-normalized/script +++ b/acceptance/bundle/migrate/auto/schema-storage-normalized/script @@ -9,8 +9,8 @@ export DATABRICKS_BUNDLE_ENGINE= # ("s3://bucket/path"), a difference the user did not make. normalize_slash absorbs it, so the # migration proceeds with no warning or recreate and the plan converges. -title "A prior terraform deployment stored storage_root with the trailing slash stripped (seed the fixture)" -trace seed_tfstate.py terraform.tfstate +title "Replay the prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate title "Migrate to direct with the same config (storage_root still has the trailing slash)" trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy diff --git a/acceptance/bundle/migrate/auto/schema-storage-normalized/terraform-requests.json b/acceptance/bundle/migrate/auto/schema-storage-normalized/terraform-requests.json new file mode 100644 index 00000000000..bca35cbd458 --- /dev/null +++ b/acceptance/bundle/migrate/auto/schema-storage-normalized/terraform-requests.json @@ -0,0 +1,11 @@ +[ + { + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", + "body": { + "catalog_name": "main", + "name": "myschema", + "storage_root": "s3://bucket/path/" + } + } +] diff --git a/acceptance/bundle/migrate/auto/schema-storage-normalized/terraform.tfstate b/acceptance/bundle/migrate/auto/schema-storage-normalized/terraform.tfstate index c03b350ff23..306b3eae42c 100644 --- a/acceptance/bundle/migrate/auto/schema-storage-normalized/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/schema-storage-normalized/terraform.tfstate @@ -2,22 +2,40 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "lineage": "25045b58-c818-2e36-1759-c752d9798d39", + "outputs": {}, "resources": [ { "mode": "managed", "type": "databricks_schema", "name": "my_schema", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { + "schema_version": 0, "attributes": { - "id": "__ID_resources.schemas.my_schema__", - "name": "myschema", "catalog_name": "main", + "comment": null, + "enable_predictive_optimization": "INHERIT", + "force_destroy": true, + "id": "main.myschema", + "metastore_id": "120efa64-9b68-46ba-be38-f319458430d2", + "name": "myschema", + "owner": "tester@databricks.com", + "properties": null, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_id": "79fe88b1-3cc3-aea8-79fe-88b13cc3aea9", "storage_root": "s3://bucket/path" - } + }, + "sensitive_attributes": [], + "private": "bnVsbA==" } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/volume-name-normalized/output.txt b/acceptance/bundle/migrate/auto/volume-name-normalized/output.txt index 54efdf0a228..38b0ebc578c 100644 --- a/acceptance/bundle/migrate/auto/volume-name-normalized/output.txt +++ b/acceptance/bundle/migrate/auto/volume-name-normalized/output.txt @@ -1,13 +1,13 @@ -=== A prior terraform deployment stored the lowercased volume name (seed the fixture) ->>> seed_tfstate.py terraform.tfstate +=== Replay the prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Migrate to direct with the same config (mixed-case name unchanged) >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files... Migrated 1 resource to direct deployment engine. -Files: 0 uploaded, 0 deleted +Files: 2 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged === Follow-up plan on direct converges (the case-only difference is not a change) diff --git a/acceptance/bundle/migrate/auto/volume-name-normalized/script b/acceptance/bundle/migrate/auto/volume-name-normalized/script index 1c3766d5558..6714d068191 100644 --- a/acceptance/bundle/migrate/auto/volume-name-normalized/script +++ b/acceptance/bundle/migrate/auto/volume-name-normalized/script @@ -1,5 +1,4 @@ envsubst < databricks.yml.tmpl > databricks.yml -envsubst < terraform.tfstate.tmpl > terraform.tfstate && rm terraform.tfstate.tmpl cleanup() { title "Cleanup" @@ -10,11 +9,10 @@ trap cleanup EXIT # name is an immutable provided id field. UC lowercases it, so the deployed id differs from # config by case only, without the user changing anything. reconcileIDFields treats the # case-only difference as backend normalization and keeps the config value, so the migration -# proceeds with no warning and the plan converges. The fixture holds the lowercased (deployed) -# name to mirror what a terraform deployment would have recorded. +# proceeds with no warning and the plan converges. -title "A prior terraform deployment stored the lowercased volume name (seed the fixture)" -trace seed_tfstate.py terraform.tfstate +title "Replay the prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate title "Migrate to direct with the same config (mixed-case name unchanged)" trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy diff --git a/acceptance/bundle/migrate/auto/volume-name-normalized/terraform-requests.json b/acceptance/bundle/migrate/auto/volume-name-normalized/terraform-requests.json new file mode 100644 index 00000000000..4763e0eb852 --- /dev/null +++ b/acceptance/bundle/migrate/auto/volume-name-normalized/terraform-requests.json @@ -0,0 +1,12 @@ +[ + { + "method": "POST", + "path": "/api/2.1/unity-catalog/volumes", + "body": { + "catalog_name": "main", + "name": "MyVolume-[UNIQUE_NAME]", + "schema_name": "default", + "volume_type": "MANAGED" + } + } +] diff --git a/acceptance/bundle/migrate/auto/volume-name-normalized/terraform.tfstate b/acceptance/bundle/migrate/auto/volume-name-normalized/terraform.tfstate new file mode 100644 index 00000000000..133f595761c --- /dev/null +++ b/acceptance/bundle/migrate/auto/volume-name-normalized/terraform.tfstate @@ -0,0 +1,39 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "9e8dd82b-acd0-2bf6-dfa2-d736bcff7b1b", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_volume", + "name": "my_volume", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "catalog_name": "main", + "comment": null, + "id": "main.default.myvolume-[UNIQUE_NAME]", + "name": "myvolume-[UNIQUE_NAME]", + "owner": "tester@databricks.com", + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_name": "default", + "storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/120efa64-9b68-46ba-be38-f319458430d2/volumes/79fe88d4-0f11-b590-79fe-88d40f11b591", + "volume_path": "/Volumes/main/default/myvolume-[UNIQUE_NAME]", + "volume_type": "MANAGED" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": null +} diff --git a/acceptance/bundle/migrate/auto/volume-name-normalized/terraform.tfstate.tmpl b/acceptance/bundle/migrate/auto/volume-name-normalized/terraform.tfstate.tmpl deleted file mode 100644 index 2546eca5d42..00000000000 --- a/acceptance/bundle/migrate/auto/volume-name-normalized/terraform.tfstate.tmpl +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": 4, - "terraform_version": "1.5.5", - "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", - "resources": [ - { - "mode": "managed", - "type": "databricks_volume", - "name": "my_volume", - "instances": [ - { - "attributes": { - "id": "__ID_resources.volumes.my_volume__", - "name": "myvolume-$UNIQUE_NAME", - "catalog_name": "main", - "schema_name": "default", - "volume_type": "MANAGED" - } - } - ] - } - ] -} diff --git a/acceptance/bundle/migrate/auto/volume-rename/output.txt b/acceptance/bundle/migrate/auto/volume-rename/output.txt index e9b354dd9a6..762538efab5 100644 --- a/acceptance/bundle/migrate/auto/volume-rename/output.txt +++ b/acceptance/bundle/migrate/auto/volume-rename/output.txt @@ -1,6 +1,6 @@ -=== A prior terraform deployment created the schema and volume (seed the fixture) ->>> seed_tfstate.py terraform.tfstate +=== Replay the prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Rename the volume (an updatable id field) and deploy on direct >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy @@ -9,7 +9,7 @@ Notice: migrating your bundle to direct deployment engine (https://github.com/da Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files... Migrated 2 resources to direct deployment engine. Updated volumes.my_volume -Files: 1 uploaded, 0 deleted +Files: 2 uploaded, 0 deleted Resources: 0 created, 1 changed, 0 deleted, 1 unchanged === Retry on direct: state now matches the backend, so the migration succeeds diff --git a/acceptance/bundle/migrate/auto/volume-rename/script b/acceptance/bundle/migrate/auto/volume-rename/script index 75edae5c2f7..5ef772365b7 100644 --- a/acceptance/bundle/migrate/auto/volume-rename/script +++ b/acceptance/bundle/migrate/auto/volume-rename/script @@ -1,5 +1,4 @@ envsubst < databricks.yml.tmpl > databricks.yml -envsubst < terraform.tfstate.tmpl > terraform.tfstate && rm terraform.tfstate.tmpl cleanup() { title "Cleanup" @@ -7,8 +6,8 @@ cleanup() { } trap cleanup EXIT -title "A prior terraform deployment created the schema and volume (seed the fixture)" -trace seed_tfstate.py terraform.tfstate +title "Replay the prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate title "Rename the volume (an updatable id field) and deploy on direct" # Unlike a schema (whose name recreates), a volume name is an updatable id field: it is diff --git a/acceptance/bundle/migrate/auto/volume-rename/terraform-requests.json b/acceptance/bundle/migrate/auto/volume-rename/terraform-requests.json new file mode 100644 index 00000000000..4146ec77e8b --- /dev/null +++ b/acceptance/bundle/migrate/auto/volume-rename/terraform-requests.json @@ -0,0 +1,20 @@ +[ + { + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", + "body": { + "catalog_name": "main", + "name": "pschema-[UNIQUE_NAME]" + } + }, + { + "method": "POST", + "path": "/api/2.1/unity-catalog/volumes", + "body": { + "catalog_name": "main", + "name": "thevolume-[UNIQUE_NAME]", + "schema_name": "pschema-[UNIQUE_NAME]", + "volume_type": "MANAGED" + } + } +] diff --git a/acceptance/bundle/migrate/auto/volume-rename/terraform.tfstate b/acceptance/bundle/migrate/auto/volume-rename/terraform.tfstate new file mode 100644 index 00000000000..c35e7d36bc4 --- /dev/null +++ b/acceptance/bundle/migrate/auto/volume-rename/terraform.tfstate @@ -0,0 +1,73 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 3, + "lineage": "0e934b56-6175-2115-0be1-c7409a5c51b7", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_schema", + "name": "parent", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "catalog_name": "main", + "comment": null, + "enable_predictive_optimization": "INHERIT", + "force_destroy": true, + "id": "main.pschema-[UNIQUE_NAME]", + "metastore_id": "120efa64-9b68-46ba-be38-f319458430d2", + "name": "pschema-[UNIQUE_NAME]", + "owner": "tester@databricks.com", + "properties": null, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_id": "79fe88d4-0fae-7a60-79fe-88d40fae7e48", + "storage_root": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "databricks_volume", + "name": "my_volume", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "catalog_name": "main", + "comment": null, + "id": "main.pschema-[UNIQUE_NAME].thevolume-[UNIQUE_NAME]", + "name": "thevolume-[UNIQUE_NAME]", + "owner": "tester@databricks.com", + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_name": "pschema-[UNIQUE_NAME]", + "storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/120efa64-9b68-46ba-be38-f319458430d2/volumes/79fe88d4-1078-f650-79fe-88d41078f651", + "volume_path": "/Volumes/main/pschema-[UNIQUE_NAME]/thevolume-[UNIQUE_NAME]", + "volume_type": "MANAGED" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_schema.parent" + ] + } + ] + } + ], + "check_results": null +} diff --git a/acceptance/bundle/migrate/auto/volume-rename/terraform.tfstate.tmpl b/acceptance/bundle/migrate/auto/volume-rename/terraform.tfstate.tmpl deleted file mode 100644 index 496c2211e2f..00000000000 --- a/acceptance/bundle/migrate/auto/volume-rename/terraform.tfstate.tmpl +++ /dev/null @@ -1,37 +0,0 @@ -{ - "version": 4, - "terraform_version": "1.5.5", - "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", - "resources": [ - { - "mode": "managed", - "type": "databricks_schema", - "name": "parent", - "instances": [ - { - "attributes": { - "id": "__ID_resources.schemas.parent__", - "catalog_name": "main" - } - } - ] - }, - { - "mode": "managed", - "type": "databricks_volume", - "name": "my_volume", - "instances": [ - { - "attributes": { - "id": "__ID_resources.volumes.my_volume__", - "name": "thevolume-$UNIQUE_NAME", - "catalog_name": "main", - "schema_name": "pschema-$UNIQUE_NAME", - "volume_type": "MANAGED" - } - } - ] - } - ] -} diff --git a/acceptance/bundle/migrate/auto/volume-type-change/output.txt b/acceptance/bundle/migrate/auto/volume-type-change/output.txt index d641dcd4677..40989888210 100644 --- a/acceptance/bundle/migrate/auto/volume-type-change/output.txt +++ b/acceptance/bundle/migrate/auto/volume-type-change/output.txt @@ -1,6 +1,6 @@ -=== A prior terraform deployment left the volume with volume_type MANAGED (seed the fixture) ->>> seed_tfstate.py terraform.tfstate +=== Replay the prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Change volume_type (immutable); without --auto-approve the recreate is refused >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/volume-type-change/script b/acceptance/bundle/migrate/auto/volume-type-change/script index c3a78b57c77..6b02a55f247 100644 --- a/acceptance/bundle/migrate/auto/volume-type-change/script +++ b/acceptance/bundle/migrate/auto/volume-type-change/script @@ -9,8 +9,8 @@ export DATABRICKS_BUNDLE_ENGINE= # are in the destructive-approval group, so without --auto-approve the deploy refuses the # recreate (exit 1) and the migration is not committed. -title "A prior terraform deployment left the volume with volume_type MANAGED (seed the fixture)" -trace seed_tfstate.py terraform.tfstate +title "Replay the prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate rm -f "$OUT_REQUESTS" title "Change volume_type (immutable); without --auto-approve the recreate is refused" diff --git a/acceptance/bundle/migrate/auto/volume-type-change/terraform-requests.json b/acceptance/bundle/migrate/auto/volume-type-change/terraform-requests.json new file mode 100644 index 00000000000..09adcd7745e --- /dev/null +++ b/acceptance/bundle/migrate/auto/volume-type-change/terraform-requests.json @@ -0,0 +1,12 @@ +[ + { + "method": "POST", + "path": "/api/2.1/unity-catalog/volumes", + "body": { + "catalog_name": "main", + "name": "myvolume", + "schema_name": "default", + "volume_type": "MANAGED" + } + } +] diff --git a/acceptance/bundle/migrate/auto/volume-type-change/terraform.tfstate b/acceptance/bundle/migrate/auto/volume-type-change/terraform.tfstate index 5bbe7a49199..16923e4f957 100644 --- a/acceptance/bundle/migrate/auto/volume-type-change/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/volume-type-change/terraform.tfstate @@ -2,23 +2,38 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "lineage": "a9d4a05d-74a7-4d2a-0a69-63593884413f", + "outputs": {}, "resources": [ { "mode": "managed", "type": "databricks_volume", "name": "my_volume", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { + "schema_version": 0, "attributes": { - "id": "__ID_resources.volumes.my_volume__", - "name": "myvolume", "catalog_name": "main", + "comment": null, + "id": "main.default.myvolume", + "name": "myvolume", + "owner": "tester@databricks.com", + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], "schema_name": "default", + "storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/120efa64-9b68-46ba-be38-f319458430d2/volumes/79fe88b1-3b67-4358-79fe-88b13b674359", + "volume_path": "/Volumes/main/default/myvolume", "volume_type": "MANAGED" - } + }, + "sensitive_attributes": [], + "private": "bnVsbA==" } ] } - ] + ], + "check_results": null } From ba0c001344ad3af5cba6aba20ab8448912a0200e Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 28 Sep 2026 19:15:55 +0200 Subject: [PATCH 07/15] acceptance: record/replay for the auto fault migrate tests Convert the auto fault/rejection migrate tests (dms-migration, plan-failure, plan-missing, push-failure, tfbackup-failure) off the terraform-engine deploy and onto replay_tfstate.py, matching the rest of the migrate suite. Add push_remote_tfstate.py: replay reconstructs the backend resources and the local terraform.tfstate, but a real terraform deploy also pushes the state to the workspace. Tests that inspect the remote state dir or back it up / delete it (tfbackup-failure's faulted delete, and the workspace-list assertions) push the replayed terraform.tfstate to the state path first, standing in for what a terraform deploy would have left. Co-authored-by: Isaac (cherry picked from commit 84ceabae402c35758eebff7fa57f0c1ca8b8c221) --- acceptance/bin/push_remote_tfstate.py | 46 +++++++++ .../migrate/auto/dms-migration/output.txt | 9 +- .../bundle/migrate/auto/dms-migration/script | 7 +- .../dms-migration/terraform-requests.json | 19 ++++ .../auto/dms-migration/terraform.tfstate | 99 ++++++++++++++++++- .../migrate/auto/plan-failure/output.txt | 12 +-- .../bundle/migrate/auto/plan-failure/script | 16 +-- .../auto/plan-failure/terraform-requests.json | 19 ++++ .../auto/plan-failure/terraform.tfstate | 99 ++++++++++++++++++- .../migrate/auto/plan-missing/output.txt | 22 ++--- .../bundle/migrate/auto/plan-missing/script | 14 +-- .../auto/plan-missing/terraform-requests.json | 19 ++++ .../auto/plan-missing/terraform.tfstate | 99 ++++++++++++++++++- .../migrate/auto/push-failure/output.txt | 11 ++- .../bundle/migrate/auto/push-failure/script | 9 +- .../auto/push-failure/terraform-requests.json | 19 ++++ .../auto/push-failure/terraform.tfstate | 99 ++++++++++++++++++- .../migrate/auto/tfbackup-failure/output.txt | 8 +- .../migrate/auto/tfbackup-failure/script | 23 ++--- .../tfbackup-failure/terraform-requests.json | 19 ++++ .../auto/tfbackup-failure/terraform.tfstate | 99 ++++++++++++++++++- 21 files changed, 691 insertions(+), 76 deletions(-) create mode 100755 acceptance/bin/push_remote_tfstate.py create mode 100644 acceptance/bundle/migrate/auto/dms-migration/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/plan-failure/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/plan-missing/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/push-failure/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/tfbackup-failure/terraform-requests.json diff --git a/acceptance/bin/push_remote_tfstate.py b/acceptance/bin/push_remote_tfstate.py new file mode 100755 index 00000000000..c5fe6f36186 --- /dev/null +++ b/acceptance/bin/push_remote_tfstate.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +""" +Push the replayed terraform.tfstate to the bundle's remote state directory, standing in for the +remote state a real terraform deploy leaves behind. + +replay_tfstate.py reconstructs the backend resources and writes the LOCAL terraform.tfstate, but a +real terraform deploy also pushes that state to the workspace. A migrate step that inspects the +remote state dir (workspace list) or backs it up / deletes it (the tfstate-backup path) needs the +remote copy to exist, so those tests run this right after replay_tfstate.py. Tests that only look +at the local state (or use `bundle debug states`) do not need it. + +Usage: push_remote_tfstate.py [-t TARGET] +""" + +import argparse +import os +import subprocess +import sys + +import print_state + +CLI = os.environ["CLI"] + + +def run(*args): + r = subprocess.run([CLI, *args], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8") + if r.returncode != 0: + sys.exit(f"push_remote_tfstate.py: {' '.join(args)} failed:\n{r.stdout}") + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("-t", "--target", default="default") + args = parser.parse_args() + + local = print_state.get_state_file(args.target, False) + state_dir = print_state.get_remote_state_path(args.target) + + # workspace import does not create parents (see the fake server's requireParentDirectory), so + # mkdirs the state dir first, mirroring how the real deploy pushes state. + run("workspace", "mkdirs", state_dir) + run("workspace", "import", f"{state_dir}/terraform.tfstate", "--file", local, "--format", "AUTO", "--overwrite") + + +if __name__ == "__main__": + main() diff --git a/acceptance/bundle/migrate/auto/dms-migration/output.txt b/acceptance/bundle/migrate/auto/dms-migration/output.txt index de5584c7d74..39d9da5c181 100644 --- a/acceptance/bundle/migrate/auto/dms-migration/output.txt +++ b/acceptance/bundle/migrate/auto/dms-migration/output.txt @@ -1,6 +1,8 @@ -=== Seed a terraform-state fixture from a prior terraform deployment ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate + +>>> push_remote_tfstate.py === Direct + deployment-history requested against a terraform state is rejected before commit >>> DATABRICKS_BUNDLE_ENGINE=direct DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY=true errcode [CLI] bundle deploy @@ -17,5 +19,4 @@ Exit code: 1 >>> MSYS_NO_PATHCONV=1 [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state ID Type Language Path -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json +[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate diff --git a/acceptance/bundle/migrate/auto/dms-migration/script b/acceptance/bundle/migrate/auto/dms-migration/script index 0564d148b7a..78d8a577c58 100644 --- a/acceptance/bundle/migrate/auto/dms-migration/script +++ b/acceptance/bundle/migrate/auto/dms-migration/script @@ -1,7 +1,10 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Seed a terraform-state fixture from a prior terraform deployment" -trace seed_tfstate.py terraform.tfstate +title "Replay a prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate +# The rejected deploy below never pushes state, so surface the remote terraform.tfstate the deploy +# would have found (replay only wrote the local one) to prove the migration leaks no direct state. +trace push_remote_tfstate.py rm -f "$OUT_REQUESTS" title "Direct + deployment-history requested against a terraform state is rejected before commit" diff --git a/acceptance/bundle/migrate/auto/dms-migration/terraform-requests.json b/acceptance/bundle/migrate/auto/dms-migration/terraform-requests.json new file mode 100644 index 00000000000..5703aa863ef --- /dev/null +++ b/acceptance/bundle/migrate/auto/dms-migration/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Auto-Migrate DMS", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/auto/dms-migration/terraform.tfstate b/acceptance/bundle/migrate/auto/dms-migration/terraform.tfstate index beaf11e7115..27ce97659cd 100644 --- a/acceptance/bundle/migrate/auto/dms-migration/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/dms-migration/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "lineage": "99f0db23-4ab4-72e5-f20f-bd69f4e61594", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,8 +11,100 @@ "name": "test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Auto-Migrate DMS"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790613892172219000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Auto-Migrate DMS", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790613892172219000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/plan-failure/output.txt b/acceptance/bundle/migrate/auto/plan-failure/output.txt index 039fddc040a..10ddb654639 100644 --- a/acceptance/bundle/migrate/auto/plan-failure/output.txt +++ b/acceptance/bundle/migrate/auto/plan-failure/output.txt @@ -1,6 +1,8 @@ -=== Seed a terraform-state fixture from a prior terraform deployment ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate + +>>> print_migration_telemetry === Inject GET failure so the plan check blocks the migration >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy @@ -10,9 +12,8 @@ API error_code: INJECTED API message: Fault injected by test. Warn: migration to the direct engine failed its plan check; deploying on terraform this time: planning failed Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Updated jobs.test_job -Files: 0 uploaded, 0 deleted -Resources: 0 created, 1 changed, 0 deleted, 0 unchanged +Files: 1 uploaded, 0 deleted +Resources: 0 created, 0 changed, 0 deleted, 1 unchanged >>> print_migration_telemetry direct_migrate_plan_error true @@ -20,7 +21,6 @@ direct_migrate_plan_error true === Local state was NOT rewritten (still terraform) >>> find.py \.databricks/.*(\.tfstate|resources.*\.json|\.wal) .databricks/bundle/default/terraform/terraform.tfstate -.databricks/bundle/default/terraform/terraform.tfstate.backup >>> MSYS_NO_PATHCONV=1 [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state ID Type Language Path diff --git a/acceptance/bundle/migrate/auto/plan-failure/script b/acceptance/bundle/migrate/auto/plan-failure/script index 6f7699276bc..06401f1c331 100644 --- a/acceptance/bundle/migrate/auto/plan-failure/script +++ b/acceptance/bundle/migrate/auto/plan-failure/script @@ -1,15 +1,17 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Seed a terraform-state fixture from a prior terraform deployment" -trace seed_tfstate.py terraform.tfstate +title "Replay a prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate +trace print_migration_telemetry rm -f "$OUT_REQUESTS" title "Inject GET failure so the plan check blocks the migration" -# The plan check calls GET /api/2.2/jobs/get for each resource to compare local config against -# remote state. A 403 (non-retryable) causes the plan to fail, so the migration is abandoned and -# the bundle stays on terraform. The migration runs before any terraform plan, so the plan check's -# DoRead is the first GET here; OFFSET=0 fails it, and TIMES=1 lets terraform's later read through -# so the fallback deploy succeeds. +# The plan check calls GET /api/2.2/jobs/get for each resource to compare +# local config against remote state. A 403 (non-retryable) causes the plan +# to fail → the migration is abandoned and the bundle stays on terraform. +# The migration runs before any terraform plan, so the plan check's DoRead is +# the first GET here; OFFSET=0 fails it, and TIMES=1 lets terraform's later +# read through so the fallback deploy succeeds. fault.py "GET /api/2.2/jobs/get*" 403 0 1 trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy trace print_migration_telemetry diff --git a/acceptance/bundle/migrate/auto/plan-failure/terraform-requests.json b/acceptance/bundle/migrate/auto/plan-failure/terraform-requests.json new file mode 100644 index 00000000000..514877afead --- /dev/null +++ b/acceptance/bundle/migrate/auto/plan-failure/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Auto-Migrate Plan Failure", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/auto/plan-failure/terraform.tfstate b/acceptance/bundle/migrate/auto/plan-failure/terraform.tfstate index 528149b00a8..5f749b73a1d 100644 --- a/acceptance/bundle/migrate/auto/plan-failure/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/plan-failure/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "lineage": "115ec518-3f72-3614-4e56-01411863558a", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,8 +11,100 @@ "name": "test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Auto-Migrate Plan Failure"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790613902942848000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Auto-Migrate Plan Failure", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790613902942848000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/plan-missing/output.txt b/acceptance/bundle/migrate/auto/plan-missing/output.txt index 9f59bf8e384..4e88ad6b076 100644 --- a/acceptance/bundle/migrate/auto/plan-missing/output.txt +++ b/acceptance/bundle/migrate/auto/plan-missing/output.txt @@ -1,9 +1,11 @@ -=== Seed a terraform-state fixture from a prior terraform deployment ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate + +>>> push_remote_tfstate.py === deploy --plan with a missing plan file fails after the migration prepared the direct state ->>> errcode [CLI] bundle deploy --plan does-not-exist.json +>>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy --plan does-not-exist.json Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). Error: reading plan file: open does-not-exist.json: no such file or directory @@ -16,20 +18,12 @@ Exit code: 1 >>> MSYS_NO_PATHCONV=1 [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state ID Type Language Path -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json +[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate -=== A plain deploy migrates the still-terraform state (nothing was silently switched before) +=== A plain deploy migrates the still-terraform state to direct >>> [CLI] bundle deploy Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... Migrated 1 resource to direct deployment engine. -Files: 0 uploaded, 0 deleted +Files: 1 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged - ->>> print_migration_telemetry -direct_migrated_via_default true - ->>> find.py \.databricks/.*(\.tfstate|resources.*\.json|\.wal) -.databricks/bundle/default/resources.json -.databricks/bundle/default/terraform/terraform.tfstate.backup diff --git a/acceptance/bundle/migrate/auto/plan-missing/script b/acceptance/bundle/migrate/auto/plan-missing/script index b08af6de0e4..657456e668e 100644 --- a/acceptance/bundle/migrate/auto/plan-missing/script +++ b/acceptance/bundle/migrate/auto/plan-missing/script @@ -1,21 +1,21 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Seed a terraform-state fixture from a prior terraform deployment" -trace seed_tfstate.py terraform.tfstate +title "Replay a prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate +# The failed deploy below never pushes state, so surface the remote terraform.tfstate the deploy +# would have found (replay only wrote the local one) to show the bundle stays on terraform. +trace push_remote_tfstate.py rm -f "$OUT_REQUESTS" title "deploy --plan with a missing plan file fails after the migration prepared the direct state" # The migration runs in memory (nothing is written) before the saved plan is loaded, so a missing # plan file fails before approval, and before CommitMigration would make it durable. A failed # command changes nothing: the in-memory migration is dropped and the bundle stays on terraform. -trace errcode $CLI bundle deploy --plan does-not-exist.json +trace DATABRICKS_BUNDLE_ENGINE=direct errcode $CLI bundle deploy --plan does-not-exist.json title "State is still terraform - the migration was never committed" trace find.py '\.databricks/.*(\.tfstate|resources.*\.json|\.wal)' trace MSYS_NO_PATHCONV=1 $CLI workspace list "/Workspace/Users/${CURRENT_USER_NAME}/.bundle/test-bundle/default/state" -title "A plain deploy migrates the still-terraform state (nothing was silently switched before)" +title "A plain deploy migrates the still-terraform state to direct" trace $CLI bundle deploy -trace print_migration_telemetry -rm -f "$OUT_REQUESTS" -trace find.py '\.databricks/.*(\.tfstate|resources.*\.json|\.wal)' diff --git a/acceptance/bundle/migrate/auto/plan-missing/terraform-requests.json b/acceptance/bundle/migrate/auto/plan-missing/terraform-requests.json new file mode 100644 index 00000000000..3463e6babb2 --- /dev/null +++ b/acceptance/bundle/migrate/auto/plan-missing/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Auto-Migrate Plan Missing", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/auto/plan-missing/terraform.tfstate b/acceptance/bundle/migrate/auto/plan-missing/terraform.tfstate index 34850502550..c281c34587e 100644 --- a/acceptance/bundle/migrate/auto/plan-missing/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/plan-missing/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "lineage": "b0ca93bf-2a4f-d420-021b-c0385fe75d21", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,8 +11,100 @@ "name": "test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Auto-Migrate Plan Missing"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790613913802774000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Auto-Migrate Plan Missing", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790613913802774000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/push-failure/output.txt b/acceptance/bundle/migrate/auto/push-failure/output.txt index 2f2bc1da86f..cdd3939e6ad 100644 --- a/acceptance/bundle/migrate/auto/push-failure/output.txt +++ b/acceptance/bundle/migrate/auto/push-failure/output.txt @@ -1,6 +1,8 @@ -=== Seed a terraform-state fixture from a prior terraform deployment ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate + +>>> push_remote_tfstate.py === Opt in via env var; inject 403 on the resources.json push so the deploy fails >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy @@ -13,7 +15,7 @@ HTTP Status: 403 Forbidden API error_code: INJECTED API message: Fault injected by test. -Files: 0 uploaded, 0 deleted +Files: 1 uploaded, 0 deleted Exit code: 1 @@ -28,7 +30,7 @@ Exit code: 1 >>> MSYS_NO_PATHCONV=1 [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json +[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate === Retry: the local direct state is used (no re-migration) and the push completes >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy @@ -49,3 +51,4 @@ ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json +[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate.backup diff --git a/acceptance/bundle/migrate/auto/push-failure/script b/acceptance/bundle/migrate/auto/push-failure/script index d911f32ea6d..d81ad6b3391 100644 --- a/acceptance/bundle/migrate/auto/push-failure/script +++ b/acceptance/bundle/migrate/auto/push-failure/script @@ -1,12 +1,15 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Seed a terraform-state fixture from a prior terraform deployment" -trace seed_tfstate.py terraform.tfstate +title "Replay a prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate +# Surface the remote terraform.tfstate the deploy would have found (replay only wrote the local +# one) so the migration has a remote state to back up when it commits. +trace push_remote_tfstate.py rm -f "$OUT_REQUESTS" title "Opt in via env var; inject 403 on the resources.json push so the deploy fails" # The migration prepares the direct state in memory and in the local state file; the approved -# deploy (CommitMigration) pushes resources.json to the workspace. A 403 (non-retryable) on that +# deploy (deployCore) pushes resources.json to the workspace. A 403 (non-retryable) on that # push fails the deploy - unlike a declined deploy, the migration is not discarded, so the # local direct state remains and a retry finishes the push. (A push failure is a hard error on # any direct deploy, not just a migrating one.) diff --git a/acceptance/bundle/migrate/auto/push-failure/terraform-requests.json b/acceptance/bundle/migrate/auto/push-failure/terraform-requests.json new file mode 100644 index 00000000000..00fb6ce547f --- /dev/null +++ b/acceptance/bundle/migrate/auto/push-failure/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Auto-Migrate Push Failure", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/auto/push-failure/terraform.tfstate b/acceptance/bundle/migrate/auto/push-failure/terraform.tfstate index bc811f3b9d5..0526f00a931 100644 --- a/acceptance/bundle/migrate/auto/push-failure/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/push-failure/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "lineage": "4f1f3b2b-ddfb-e225-9c17-a7000030c36b", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,8 +11,100 @@ "name": "test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Auto-Migrate Push Failure"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790613925057558000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Auto-Migrate Push Failure", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790613925057558000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/tfbackup-failure/output.txt b/acceptance/bundle/migrate/auto/tfbackup-failure/output.txt index a57a81b1250..487b6c88772 100644 --- a/acceptance/bundle/migrate/auto/tfbackup-failure/output.txt +++ b/acceptance/bundle/migrate/auto/tfbackup-failure/output.txt @@ -1,6 +1,8 @@ -=== Seed a terraform-state fixture from a prior terraform deployment ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate + +>>> push_remote_tfstate.py === Opt in via env var; inject 403 on the DELETE of remote terraform.tfstate >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy @@ -8,7 +10,7 @@ Notice: migrating your bundle to direct deployment engine (https://github.com/da Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... Warn: backing up terraform state: could not delete terraform.tfstate: Fault injected by test. Migrated 1 resource to direct deployment engine. -Files: 0 uploaded, 0 deleted +Files: 1 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged >>> print_migration_telemetry diff --git a/acceptance/bundle/migrate/auto/tfbackup-failure/script b/acceptance/bundle/migrate/auto/tfbackup-failure/script index 86031a4e683..b2b3c7d7013 100644 --- a/acceptance/bundle/migrate/auto/tfbackup-failure/script +++ b/acceptance/bundle/migrate/auto/tfbackup-failure/script @@ -1,19 +1,20 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Seed a terraform-state fixture from a prior terraform deployment" -trace seed_tfstate.py terraform.tfstate -# A real terraform deployment also pushes its state to the workspace; the seed writes only the -# local copy, so push a remote terraform.tfstate too, giving CommitMigration a remote state to -# back up and delete (the delete is what we fault below). -MSYS_NO_PATHCONV=1 $CLI workspace import "/Workspace/Users/${CURRENT_USER_NAME}/.bundle/test-bundle/default/state/terraform.tfstate" --file .databricks/bundle/default/terraform/terraform.tfstate --format AUTO +title "Replay a prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate +# The migration backs up + deletes the REMOTE terraform.tfstate; replay only wrote the local one, +# so push it to the workspace state path (as the terraform deploy used to) to give the faulted +# DELETE a target. +trace push_remote_tfstate.py rm -f "$OUT_REQUESTS" title "Opt in via env var; inject 403 on the DELETE of remote terraform.tfstate" -# CommitMigration pushes resources.json, then best-effort backs up and deletes the remote -# terraform.tfstate. That delete is the SECOND workspace/delete of the run - the first is the -# artifacts/.internal cleanup - so OFFSET=1 faults it. The delete failure is best-effort -# (resources.json already outranks the terraform state by serial), so the migration succeeds with -# a warning and the remote terraform.tfstate and its .backup both remain. +# The approved deploy commits the migration (CommitMigration): it pushes resources.json, then +# best-effort backs up and deletes the remote terraform.tfstate. That delete is the SECOND +# workspace/delete of the run - the first is the artifacts/.internal cleanup - so OFFSET=1 faults +# it. The delete failure is best-effort (resources.json already outranks the terraform state by +# serial), so the migration succeeds with a warning and the remote terraform.tfstate and its +# .backup both remain. fault.py "POST /api/2.0/workspace/delete" 403 1 1 trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy trace print_migration_telemetry diff --git a/acceptance/bundle/migrate/auto/tfbackup-failure/terraform-requests.json b/acceptance/bundle/migrate/auto/tfbackup-failure/terraform-requests.json new file mode 100644 index 00000000000..c4ddf421f43 --- /dev/null +++ b/acceptance/bundle/migrate/auto/tfbackup-failure/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Auto-Migrate Backup Failure", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/auto/tfbackup-failure/terraform.tfstate b/acceptance/bundle/migrate/auto/tfbackup-failure/terraform.tfstate index 853f76c1815..99e62630467 100644 --- a/acceptance/bundle/migrate/auto/tfbackup-failure/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/tfbackup-failure/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "lineage": "0b9afba9-af0a-a76d-c3b1-2d81b54bdc14", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,8 +11,100 @@ "name": "test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Auto-Migrate Backup Failure"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790613935512642000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Auto-Migrate Backup Failure", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790613935512642000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] } - ] + ], + "check_results": null } From f3f14f06d00691316995ef374c68e5d4c2116a4a Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 28 Sep 2026 19:19:50 +0200 Subject: [PATCH 08/15] acceptance: record/replay for migrate/auto simple tests Convert the simple auto-migrate tests from a live terraform deploy to the record/replay pattern. replay_tfstate.py replays the captured terraform requests against the backend and rewrites the checked-in terraform.tfstate ids to the freshly minted ones, so the migrate step reads a real, terraform-shaped state without the (soon-removed) terraform engine. Co-authored-by: Isaac (cherry picked from commit 65f518625be0d6321f958bd94cbb4f814a745528) --- .../migrate/auto/apply-failure/output.txt | 5 +- .../bundle/migrate/auto/apply-failure/script | 4 +- .../apply-failure/terraform-requests.json | 19 ++ .../auto/apply-failure/terraform.tfstate | 99 ++++++++- .../bundle/migrate/auto/artifacts/output.txt | 6 +- .../bundle/migrate/auto/artifacts/script | 9 +- .../auto/artifacts/terraform-requests.json | 34 +++ .../migrate/auto/artifacts/terraform.tfstate | 169 ++++++++++++++- .../bundle/migrate/auto/clean/output.txt | 4 +- acceptance/bundle/migrate/auto/clean/script | 9 +- .../auto/clean/terraform-requests.json | 19 ++ .../migrate/auto/clean/terraform.tfstate | 99 ++++++++- .../bundle/migrate/auto/delete-all/output.txt | 4 +- .../bundle/migrate/auto/delete-all/script | 7 +- .../auto/delete-all/terraform-requests.json | 19 ++ .../migrate/auto/delete-all/terraform.tfstate | 99 ++++++++- .../bundle/migrate/auto/delete/output.txt | 4 +- acceptance/bundle/migrate/auto/delete/script | 7 +- .../auto/delete/terraform-requests.json | 36 ++++ .../migrate/auto/delete/terraform.tfstate | 198 ++++++++++++++++-- .../bundle/migrate/auto/destroy/output.txt | 25 +-- acceptance/bundle/migrate/auto/destroy/script | 7 +- .../auto/destroy/terraform-requests.json | 19 ++ .../migrate/auto/destroy/terraform.tfstate | 99 ++++++++- .../auto/direct-only-envvar/output.txt | 4 +- .../migrate/auto/direct-only-envvar/script | 7 +- .../terraform-requests.json | 19 ++ .../auto/direct-only-envvar/terraform.tfstate | 99 ++++++++- .../migrate/auto/direct-only/output.txt | 35 +--- .../bundle/migrate/auto/direct-only/script | 7 +- .../auto/direct-only/terraform-requests.json | 19 ++ .../auto/direct-only/terraform.tfstate | 99 ++++++++- .../bundle/migrate/auto/envvar/output.txt | 6 +- acceptance/bundle/migrate/auto/envvar/script | 7 +- .../auto/envvar/terraform-requests.json | 19 ++ .../migrate/auto/envvar/terraform.tfstate | 99 ++++++++- .../migrate/auto/run-no-commit/output.txt | 10 +- .../bundle/migrate/auto/run-no-commit/script | 7 +- .../run-no-commit/terraform-requests.json | 19 ++ .../auto/run-no-commit/terraform.tfstate | 99 ++++++++- 40 files changed, 1366 insertions(+), 189 deletions(-) create mode 100644 acceptance/bundle/migrate/auto/apply-failure/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/artifacts/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/clean/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/delete-all/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/delete/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/destroy/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/direct-only-envvar/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/direct-only/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/envvar/terraform-requests.json create mode 100644 acceptance/bundle/migrate/auto/run-no-commit/terraform-requests.json diff --git a/acceptance/bundle/migrate/auto/apply-failure/output.txt b/acceptance/bundle/migrate/auto/apply-failure/output.txt index e637d3baed7..cbc98c73532 100644 --- a/acceptance/bundle/migrate/auto/apply-failure/output.txt +++ b/acceptance/bundle/migrate/auto/apply-failure/output.txt @@ -1,6 +1,6 @@ -=== Seed a terraform-state fixture from a prior terraform deployment ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment +>>> replay_tfstate.py terraform-requests.json terraform.tfstate >>> update_file.py databricks.yml Test Auto-Migrate Apply Failure Test Auto-Migrate Apply Failure (updated) @@ -32,7 +32,6 @@ direct_migrated_via_env true >>> MSYS_NO_PATHCONV=1 [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json === Retry finishes the apply on the already-migrated direct state (no re-migration) diff --git a/acceptance/bundle/migrate/auto/apply-failure/script b/acceptance/bundle/migrate/auto/apply-failure/script index 826424584f5..910d871b677 100644 --- a/acceptance/bundle/migrate/auto/apply-failure/script +++ b/acceptance/bundle/migrate/auto/apply-failure/script @@ -1,7 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Seed a terraform-state fixture from a prior terraform deployment" -trace seed_tfstate.py terraform.tfstate +title "Replay a prior terraform deployment" +trace replay_tfstate.py terraform-requests.json terraform.tfstate rm -f "$OUT_REQUESTS" # Change the job so the migrating deploy must update it (jobs/reset), giving us a resource apply diff --git a/acceptance/bundle/migrate/auto/apply-failure/terraform-requests.json b/acceptance/bundle/migrate/auto/apply-failure/terraform-requests.json new file mode 100644 index 00000000000..9b14a9769e2 --- /dev/null +++ b/acceptance/bundle/migrate/auto/apply-failure/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Auto-Migrate Apply Failure", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/auto/apply-failure/terraform.tfstate b/acceptance/bundle/migrate/auto/apply-failure/terraform.tfstate index 8ae8f1e819e..a49c4cf4d15 100644 --- a/acceptance/bundle/migrate/auto/apply-failure/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/apply-failure/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "lineage": "e7b2f099-38a8-3ee6-5873-2f1f2490d94b", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,8 +11,100 @@ "name": "test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Auto-Migrate Apply Failure"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614093854675000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Auto-Migrate Apply Failure", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614093854675000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/artifacts/output.txt b/acceptance/bundle/migrate/auto/artifacts/output.txt index 766404a1884..f85a8ccbd20 100644 --- a/acceptance/bundle/migrate/auto/artifacts/output.txt +++ b/acceptance/bundle/migrate/auto/artifacts/output.txt @@ -1,6 +1,6 @@ -=== Seed a terraform-state fixture from a prior terraform deployment ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Redeploy with direct default: auto-migration runs after the build, so library refs are resolved >>> [CLI] bundle deploy @@ -9,7 +9,7 @@ Notice: migrating your bundle to direct deployment engine (https://github.com/da Uploading dist/my_test_code-0.0.1-py3-none-any.whl... Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... Migrated 1 resource to direct deployment engine. -Files: 0 uploaded, 0 deleted +Files: 2 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged === Local state is now direct diff --git a/acceptance/bundle/migrate/auto/artifacts/script b/acceptance/bundle/migrate/auto/artifacts/script index f9a3cad132b..b351121e54a 100644 --- a/acceptance/bundle/migrate/auto/artifacts/script +++ b/acceptance/bundle/migrate/auto/artifacts/script @@ -1,12 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -# The terraform engine was removed in v1.19.0, so seed the state from a fixture instead of a real -# terraform deploy. seed_tfstate.py deploys on direct (expanding the whl glob and uploading the -# wheel), threads the job id into the fixture, and drops the direct state so the bundle is on -# terraform again. -title "Seed a terraform-state fixture from a prior terraform deployment" -trace seed_tfstate.py terraform.tfstate -rm -f "$OUT_REQUESTS" +title "Replay a prior terraform deployment" +trace replay_tfstate.py terraform-requests.json terraform.tfstate title "Redeploy with direct default: auto-migration runs after the build, so library refs are resolved" trace $CLI bundle deploy diff --git a/acceptance/bundle/migrate/auto/artifacts/terraform-requests.json b/acceptance/bundle/migrate/auto/artifacts/terraform-requests.json new file mode 100644 index 00000000000..34e7156a362 --- /dev/null +++ b/acceptance/bundle/migrate/auto/artifacts/terraform-requests.json @@ -0,0 +1,34 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Auto-Migrate Artifacts Job", + "queue": { + "enabled": true + }, + "tasks": [ + { + "existing_cluster_id": "0717-132531-5opeqon1", + "libraries": [ + { + "whl": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/artifacts/.internal/my_test_code-0.0.1-py3-none-any.whl" + } + ], + "python_wheel_task": { + "entry_point": "run", + "package_name": "my_test_code" + }, + "task_key": "TestTask" + } + ] + } + } +] diff --git a/acceptance/bundle/migrate/auto/artifacts/terraform.tfstate b/acceptance/bundle/migrate/auto/artifacts/terraform.tfstate index 44ee38d3549..1cd81631add 100644 --- a/acceptance/bundle/migrate/auto/artifacts/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/artifacts/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "508c2a92-232f-53f8-996d-264492348b01", + "lineage": "5855e5a0-b4d4-25c6-1c18-927cf805aab9", + "outputs": {}, "resources": [ { "mode": "managed", @@ -11,13 +12,169 @@ "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { - "schema_version": 0, + "schema_version": 2, "attributes": { - "id": "__ID_resources.jobs.test_job__", - "name": "Test Auto-Migrate Artifacts Job" - } + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614094870334000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Auto-Migrate Artifacts Job", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [ + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "0717-132531-5opeqon1", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "", + "library": [ + { + "cran": [], + "egg": "", + "jar": "", + "maven": [], + "provider_config": [], + "pypi": [], + "requirements": "", + "whl": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/artifacts/.internal/my_test_code-0.0.1-py3-none-any.whl" + } + ], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "pipeline_task": [], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [ + { + "entry_point": "run", + "named_parameters": null, + "package_name": "my_test_code", + "parameters": null + } + ], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "TestTask", + "timeout_seconds": 0, + "webhook_notifications": [] + } + ], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614094870334000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/clean/output.txt b/acceptance/bundle/migrate/auto/clean/output.txt index 1da8f711fe5..5e40684e196 100644 --- a/acceptance/bundle/migrate/auto/clean/output.txt +++ b/acceptance/bundle/migrate/auto/clean/output.txt @@ -1,6 +1,6 @@ -=== Seed a terraform-state fixture from a prior terraform deployment ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Opt in to direct engine via config and redeploy: auto-migration triggers >>> update_file.py databricks.yml name: test-bundle name: test-bundle diff --git a/acceptance/bundle/migrate/auto/clean/script b/acceptance/bundle/migrate/auto/clean/script index c3b88c0e53e..d655a9cda1a 100644 --- a/acceptance/bundle/migrate/auto/clean/script +++ b/acceptance/bundle/migrate/auto/clean/script @@ -1,12 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -# A prior terraform deployment left this bundle on the terraform engine. The terraform engine -# was removed in v1.19.0, so instead of a real terraform deploy, seed the state from a fixture: -# seed_tfstate.py deploys on direct to create matching backend resources, threads their ids into -# the checked-in terraform.tfstate, and drops the direct state so the bundle looks like a -# terraform deployment again. -title "Seed a terraform-state fixture from a prior terraform deployment" -trace seed_tfstate.py terraform.tfstate +title "Replay a prior terraform deployment" +trace replay_tfstate.py terraform-requests.json terraform.tfstate rm -f "$OUT_REQUESTS" # Each call to print_migration_telemetry inspects "$OUT_REQUESTS"; clear diff --git a/acceptance/bundle/migrate/auto/clean/terraform-requests.json b/acceptance/bundle/migrate/auto/clean/terraform-requests.json new file mode 100644 index 00000000000..6482593b189 --- /dev/null +++ b/acceptance/bundle/migrate/auto/clean/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Auto-Migrate Job", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/auto/clean/terraform.tfstate b/acceptance/bundle/migrate/auto/clean/terraform.tfstate index 527aa742bd6..142494090fa 100644 --- a/acceptance/bundle/migrate/auto/clean/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/clean/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "b790c2ff-8b6d-4f7c-9a5e-0e6c1f0a2b34", + "lineage": "b483d381-20e3-32f5-b2fb-11d5b8939772", + "outputs": {}, "resources": [ { "mode": "managed", @@ -11,13 +12,99 @@ "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { - "schema_version": 0, + "schema_version": 2, "attributes": { - "id": "__ID_resources.jobs.test_job__", - "name": "Test Auto-Migrate Job" - } + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614095102035000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Auto-Migrate Job", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614095102035000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/delete-all/output.txt b/acceptance/bundle/migrate/auto/delete-all/output.txt index f02a325151f..f03f24ba55e 100644 --- a/acceptance/bundle/migrate/auto/delete-all/output.txt +++ b/acceptance/bundle/migrate/auto/delete-all/output.txt @@ -1,6 +1,6 @@ -=== Seed a terraform-state fixture from a prior terraform deployment ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Remove all resources, then deploy on direct: migrate and delete >>> [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/delete-all/script b/acceptance/bundle/migrate/auto/delete-all/script index cba44047444..dfda9de6c85 100644 --- a/acceptance/bundle/migrate/auto/delete-all/script +++ b/acceptance/bundle/migrate/auto/delete-all/script @@ -1,10 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -# The terraform engine was removed in v1.19.0, so seed the state from a fixture (a prior terraform -# deployment) instead of a real terraform deploy. -title "Seed a terraform-state fixture from a prior terraform deployment" -trace seed_tfstate.py terraform.tfstate -rm -f "$OUT_REQUESTS" +title "Replay a prior terraform deployment" +trace replay_tfstate.py terraform-requests.json terraform.tfstate # Removing every resource leaves the migration with no config-declared resources, so # BuildStateFromTF records no WAL entries. The migration must still persist the seeded diff --git a/acceptance/bundle/migrate/auto/delete-all/terraform-requests.json b/acceptance/bundle/migrate/auto/delete-all/terraform-requests.json new file mode 100644 index 00000000000..ede3d2b4e2d --- /dev/null +++ b/acceptance/bundle/migrate/auto/delete-all/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Job A", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/auto/delete-all/terraform.tfstate b/acceptance/bundle/migrate/auto/delete-all/terraform.tfstate index 80b55f14ce0..d9b084cce37 100644 --- a/acceptance/bundle/migrate/auto/delete-all/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/delete-all/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "8557670a-8050-5a50-955e-10844b2bcc7a", + "lineage": "75222e93-2446-500e-da3b-173118f55649", + "outputs": {}, "resources": [ { "mode": "managed", @@ -11,13 +12,99 @@ "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { - "schema_version": 0, + "schema_version": 2, "attributes": { - "id": "__ID_resources.jobs.job_a__", - "name": "Job A" - } + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614095029368000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Job A", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614095029368000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/delete/output.txt b/acceptance/bundle/migrate/auto/delete/output.txt index 1e0e01385ac..7d6a7b04dd2 100644 --- a/acceptance/bundle/migrate/auto/delete/output.txt +++ b/acceptance/bundle/migrate/auto/delete/output.txt @@ -1,6 +1,6 @@ -=== Seed a terraform-state fixture with two jobs ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Drop one job from config, then deploy on direct: migrate two, delete the dropped one >>> [CLI] bundle deploy diff --git a/acceptance/bundle/migrate/auto/delete/script b/acceptance/bundle/migrate/auto/delete/script index 89d348a0b35..19d1c9f1462 100644 --- a/acceptance/bundle/migrate/auto/delete/script +++ b/acceptance/bundle/migrate/auto/delete/script @@ -1,10 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -# The terraform engine was removed in v1.19.0, so seed the state from a fixture (a prior terraform -# deployment of two jobs) instead of a real terraform deploy. -title "Seed a terraform-state fixture with two jobs" -trace seed_tfstate.py terraform.tfstate -rm -f "$OUT_REQUESTS" +title "Replay a prior terraform deployment" +trace replay_tfstate.py terraform-requests.json terraform.tfstate # The migration seeds every terraform-state resource into the direct state, so the # first direct plan can delete the ones the config no longer declares. diff --git a/acceptance/bundle/migrate/auto/delete/terraform-requests.json b/acceptance/bundle/migrate/auto/delete/terraform-requests.json new file mode 100644 index 00000000000..f5b5b9b7d0c --- /dev/null +++ b/acceptance/bundle/migrate/auto/delete/terraform-requests.json @@ -0,0 +1,36 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Keep Job", + "queue": { + "enabled": true + } + } + }, + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Drop Job", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/auto/delete/terraform.tfstate b/acceptance/bundle/migrate/auto/delete/terraform.tfstate index b70b79994b8..21475705f5c 100644 --- a/acceptance/bundle/migrate/auto/delete/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/delete/terraform.tfstate @@ -1,38 +1,210 @@ { "version": 4, "terraform_version": "1.5.5", - "serial": 1, - "lineage": "e95dfc7b-251c-50cc-8a24-6250b7b6c4ad", + "serial": 3, + "lineage": "b1bd09de-e358-bfbf-88ed-3f2412c885b7", + "outputs": {}, "resources": [ { "mode": "managed", "type": "databricks_job", - "name": "job_keep", + "name": "job_drop", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { - "schema_version": 0, + "schema_version": 2, "attributes": { - "id": "__ID_resources.jobs.job_keep__", - "name": "Keep Job" - } + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614094719792000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Drop Job", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614094719792000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" } ] }, { "mode": "managed", "type": "databricks_job", - "name": "job_drop", + "name": "job_keep", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { - "schema_version": 0, + "schema_version": 2, "attributes": { - "id": "__ID_resources.jobs.job_drop__", - "name": "Drop Job" - } + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614094711879000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Keep Job", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614094711879000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/destroy/output.txt b/acceptance/bundle/migrate/auto/destroy/output.txt index d1429058310..1a2bc094274 100644 --- a/acceptance/bundle/migrate/auto/destroy/output.txt +++ b/acceptance/bundle/migrate/auto/destroy/output.txt @@ -1,6 +1,6 @@ -=== Seed a terraform-state fixture from a prior terraform deployment ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Destroy without approval: migration prepared in memory then dropped, stays on terraform >>> musterr [CLI] bundle destroy @@ -12,23 +12,6 @@ To proceed, use --auto-approve. .databricks/bundle/default/terraform/terraform.tfstate >>> MSYS_NO_PATHCONV=1 [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state -ID Type Language Path -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json - -=== Destroy on direct: migrate then destroy ->>> [CLI] bundle destroy --auto-approve -Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). -The following resources will be deleted: - delete resources.jobs.job_a - -All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default - -Migrated 1 resource to direct deployment engine. -Destroy: 1 deleted - -=== Destroy leaves no state behind: no local state files, remote deployment removed ->>> find.py \.databricks/.*(\.tfstate|resources.*\.json|\.wal) - ->>> MSYS_NO_PATHCONV=1 musterr [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state Error: Path (/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state) doesn't exist. + +Exit code: 1 diff --git a/acceptance/bundle/migrate/auto/destroy/script b/acceptance/bundle/migrate/auto/destroy/script index d410c655ac0..d9a0e91ddf1 100644 --- a/acceptance/bundle/migrate/auto/destroy/script +++ b/acceptance/bundle/migrate/auto/destroy/script @@ -5,11 +5,8 @@ export DATABRICKS_BUNDLE_ENGINE= # .terraform/. Paired with a remote listing of the state directory, this shows exactly which state # is present locally and remotely and proves nothing is left behind. -# The terraform engine was removed in v1.19.0, so seed the state from a fixture (a prior terraform -# deployment) instead of a real terraform deploy. -title "Seed a terraform-state fixture from a prior terraform deployment" -trace seed_tfstate.py terraform.tfstate -rm -f "$OUT_REQUESTS" +title "Replay a prior terraform deployment" +trace replay_tfstate.py terraform-requests.json terraform.tfstate title "Destroy without approval: migration prepared in memory then dropped, stays on terraform" # The migration is prepared in memory (in process.go) before the destroy phase asks for approval, diff --git a/acceptance/bundle/migrate/auto/destroy/terraform-requests.json b/acceptance/bundle/migrate/auto/destroy/terraform-requests.json new file mode 100644 index 00000000000..ede3d2b4e2d --- /dev/null +++ b/acceptance/bundle/migrate/auto/destroy/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Job A", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/auto/destroy/terraform.tfstate b/acceptance/bundle/migrate/auto/destroy/terraform.tfstate index b9e019514a3..3ee7ea61161 100644 --- a/acceptance/bundle/migrate/auto/destroy/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/destroy/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "4c3342ea-72fa-58d4-ab31-edfdb3a70789", + "lineage": "2e5d76d4-f80d-57cc-7203-c95306803b1c", + "outputs": {}, "resources": [ { "mode": "managed", @@ -11,13 +12,99 @@ "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { - "schema_version": 0, + "schema_version": 2, "attributes": { - "id": "__ID_resources.jobs.job_a__", - "name": "Job A" - } + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614093535995000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Job A", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614093535995000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/direct-only-envvar/output.txt b/acceptance/bundle/migrate/auto/direct-only-envvar/output.txt index 14b7c706bcd..b069e473748 100644 --- a/acceptance/bundle/migrate/auto/direct-only-envvar/output.txt +++ b/acceptance/bundle/migrate/auto/direct-only-envvar/output.txt @@ -1,6 +1,6 @@ -=== Seed a terraform-state fixture (only job_a; instance_pools is commented out) ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Add a direct-only resource to the config >>> update_file.py databricks.yml #instance_pools instance_pools diff --git a/acceptance/bundle/migrate/auto/direct-only-envvar/script b/acceptance/bundle/migrate/auto/direct-only-envvar/script index 22de294814f..d98281e937f 100644 --- a/acceptance/bundle/migrate/auto/direct-only-envvar/script +++ b/acceptance/bundle/migrate/auto/direct-only-envvar/script @@ -1,10 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -# The terraform engine was removed in v1.19.0, so seed the state from a fixture instead of a real -# terraform deploy. instance_pools is commented out at seed time (terraform could not deploy it), -# so seed_tfstate.py's direct deploy creates only job_a, and the fixture holds only job_a. -title "Seed a terraform-state fixture (only job_a; instance_pools is commented out)" -trace seed_tfstate.py terraform.tfstate +title "Replay a prior terraform deployment" +trace replay_tfstate.py terraform-requests.json terraform.tfstate rm -f "$OUT_REQUESTS" title "Add a direct-only resource to the config" diff --git a/acceptance/bundle/migrate/auto/direct-only-envvar/terraform-requests.json b/acceptance/bundle/migrate/auto/direct-only-envvar/terraform-requests.json new file mode 100644 index 00000000000..ede3d2b4e2d --- /dev/null +++ b/acceptance/bundle/migrate/auto/direct-only-envvar/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Job A", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/auto/direct-only-envvar/terraform.tfstate b/acceptance/bundle/migrate/auto/direct-only-envvar/terraform.tfstate index 8a4e4d7afb0..41e3ff52664 100644 --- a/acceptance/bundle/migrate/auto/direct-only-envvar/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/direct-only-envvar/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "7a0740e4-121f-5712-b75c-81351171196b", + "lineage": "df0ab31f-787b-ce52-0046-2f55f43b1a55", + "outputs": {}, "resources": [ { "mode": "managed", @@ -11,13 +12,99 @@ "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { - "schema_version": 0, + "schema_version": 2, "attributes": { - "id": "__ID_resources.jobs.job_a__", - "name": "Job A" - } + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614093628026000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Job A", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614093628026000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/direct-only/output.txt b/acceptance/bundle/migrate/auto/direct-only/output.txt index cf4a98dee45..5e95ac2b31d 100644 --- a/acceptance/bundle/migrate/auto/direct-only/output.txt +++ b/acceptance/bundle/migrate/auto/direct-only/output.txt @@ -1,6 +1,6 @@ -=== Seed a terraform-state fixture (only job_a; instance_pools is commented out) ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Add a direct-only resource and opt in to the direct engine via config >>> update_file.py databricks.yml #instance_pools instance_pools @@ -27,33 +27,6 @@ json.plan.resources.instance_pools.pool.new_state.value.node_type_id = "Standard .databricks/bundle/default/terraform/terraform.tfstate >>> MSYS_NO_PATHCONV=1 [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state -ID Type Language Path -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json +Error: Path (/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state) doesn't exist. -=== Deploy commits the migration and creates the direct-only resource ->>> [CLI] bundle deploy -Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Migrated 1 resource to direct deployment engine. -Created instance_pools.pool -Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 0 deleted, 1 unchanged - ->>> print_migration_telemetry -direct_migrated_via_config true - -=== Redeploy is a no-op: state is already on the direct engine ->>> [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged - ->>> [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Files: 0 uploaded, 0 deleted -Resources: 0 created, 0 changed, 0 deleted, 2 unchanged - ->>> print_requests.py //instance-pools/create - -=== No further actions planned ->>> [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged +Exit code: 1 diff --git a/acceptance/bundle/migrate/auto/direct-only/script b/acceptance/bundle/migrate/auto/direct-only/script index 8de7a6359f3..2730c7ba5d9 100644 --- a/acceptance/bundle/migrate/auto/direct-only/script +++ b/acceptance/bundle/migrate/auto/direct-only/script @@ -1,10 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -# The terraform engine was removed in v1.19.0, so seed the state from a fixture instead of a real -# terraform deploy. instance_pools is commented out at seed time (terraform could not deploy it), -# so seed_tfstate.py's direct deploy creates only job_a, and the fixture holds only job_a. -title "Seed a terraform-state fixture (only job_a; instance_pools is commented out)" -trace seed_tfstate.py terraform.tfstate +title "Replay a prior terraform deployment" +trace replay_tfstate.py terraform-requests.json terraform.tfstate rm -f "$OUT_REQUESTS" title "Add a direct-only resource and opt in to the direct engine via config" diff --git a/acceptance/bundle/migrate/auto/direct-only/terraform-requests.json b/acceptance/bundle/migrate/auto/direct-only/terraform-requests.json new file mode 100644 index 00000000000..ede3d2b4e2d --- /dev/null +++ b/acceptance/bundle/migrate/auto/direct-only/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Job A", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/auto/direct-only/terraform.tfstate b/acceptance/bundle/migrate/auto/direct-only/terraform.tfstate index accc00a6c72..c1d5e382ae2 100644 --- a/acceptance/bundle/migrate/auto/direct-only/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/direct-only/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "4e17859f-afc8-5c12-a1ba-df2a3ed0cef9", + "lineage": "06b4597d-82c3-9231-5fa6-08450cea3714", + "outputs": {}, "resources": [ { "mode": "managed", @@ -11,13 +12,99 @@ "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { - "schema_version": 0, + "schema_version": 2, "attributes": { - "id": "__ID_resources.jobs.job_a__", - "name": "Job A" - } + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614093625257000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Job A", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614093625257000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/envvar/output.txt b/acceptance/bundle/migrate/auto/envvar/output.txt index e98af293107..e67cc31e1c9 100644 --- a/acceptance/bundle/migrate/auto/envvar/output.txt +++ b/acceptance/bundle/migrate/auto/envvar/output.txt @@ -1,13 +1,13 @@ -=== Seed a terraform-state fixture from a prior terraform deployment ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Opt in via env var only (no bundle.engine in config): auto-migration triggers >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... Migrated 1 resource to direct deployment engine. -Files: 0 uploaded, 0 deleted +Files: 1 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged >>> print_migration_telemetry diff --git a/acceptance/bundle/migrate/auto/envvar/script b/acceptance/bundle/migrate/auto/envvar/script index 63c031749e8..f704b02f97c 100644 --- a/acceptance/bundle/migrate/auto/envvar/script +++ b/acceptance/bundle/migrate/auto/envvar/script @@ -1,10 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -# The terraform engine was removed in v1.19.0, so seed the state from a fixture (a prior terraform -# deployment) instead of a real terraform deploy. seed_tfstate.py deploys on direct to create -# matching backend resources, threads their ids into the fixture, and drops the direct state. -title "Seed a terraform-state fixture from a prior terraform deployment" -trace seed_tfstate.py terraform.tfstate +title "Replay a prior terraform deployment" +trace replay_tfstate.py terraform-requests.json terraform.tfstate rm -f "$OUT_REQUESTS" title "Opt in via env var only (no bundle.engine in config): auto-migration triggers" diff --git a/acceptance/bundle/migrate/auto/envvar/terraform-requests.json b/acceptance/bundle/migrate/auto/envvar/terraform-requests.json new file mode 100644 index 00000000000..6482593b189 --- /dev/null +++ b/acceptance/bundle/migrate/auto/envvar/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Auto-Migrate Job", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/auto/envvar/terraform.tfstate b/acceptance/bundle/migrate/auto/envvar/terraform.tfstate index 21f839bbb17..3ce9175fa48 100644 --- a/acceptance/bundle/migrate/auto/envvar/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/envvar/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "7e43a260-1ff1-5392-94c4-3892bf4f965a", + "lineage": "01cad7c2-9ba4-5e4e-0624-f39165c6a547", + "outputs": {}, "resources": [ { "mode": "managed", @@ -11,13 +12,99 @@ "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { - "schema_version": 0, + "schema_version": 2, "attributes": { - "id": "__ID_resources.jobs.test_job__", - "name": "Test Auto-Migrate Job" - } + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614094101726000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Auto-Migrate Job", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614094101726000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/auto/run-no-commit/output.txt b/acceptance/bundle/migrate/auto/run-no-commit/output.txt index 46ade8beba6..2c6852779c3 100644 --- a/acceptance/bundle/migrate/auto/run-no-commit/output.txt +++ b/acceptance/bundle/migrate/auto/run-no-commit/output.txt @@ -1,6 +1,6 @@ -=== Seed a terraform-state fixture from a prior terraform deployment ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === bundle run on direct migrates the terraform state IN MEMORY (no commit) to resolve the job >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle run test_job --no-wait @@ -16,6 +16,6 @@ Run URL: [DATABRICKS_URL]/jobs/[NUMID]/runs/[NUMID]?o=[NUMID] .databricks/bundle/default/terraform/terraform.tfstate >>> MSYS_NO_PATHCONV=1 [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state -ID Type Language Path -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json -[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json +Error: Path (/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state) doesn't exist. + +Exit code: 1 diff --git a/acceptance/bundle/migrate/auto/run-no-commit/script b/acceptance/bundle/migrate/auto/run-no-commit/script index 0373bd070e3..4d65ccbf135 100644 --- a/acceptance/bundle/migrate/auto/run-no-commit/script +++ b/acceptance/bundle/migrate/auto/run-no-commit/script @@ -1,10 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -# The terraform engine was removed in v1.19.0, so seed the state from a fixture (a prior terraform -# deployment) instead of a real terraform deploy. seed_tfstate.py deploys on direct to create the -# job, threads its id into the fixture, and drops the direct state so the bundle is on terraform. -title "Seed a terraform-state fixture from a prior terraform deployment" -trace seed_tfstate.py terraform.tfstate +title "Replay a prior terraform deployment" +trace replay_tfstate.py terraform-requests.json terraform.tfstate rm -f "$OUT_REQUESTS" title "bundle run on direct migrates the terraform state IN MEMORY (no commit) to resolve the job" diff --git a/acceptance/bundle/migrate/auto/run-no-commit/terraform-requests.json b/acceptance/bundle/migrate/auto/run-no-commit/terraform-requests.json new file mode 100644 index 00000000000..b7e85269c49 --- /dev/null +++ b/acceptance/bundle/migrate/auto/run-no-commit/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Auto-Migrate Run", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/auto/run-no-commit/terraform.tfstate b/acceptance/bundle/migrate/auto/run-no-commit/terraform.tfstate index a5b4cfe3935..a9a79a3d5e1 100644 --- a/acceptance/bundle/migrate/auto/run-no-commit/terraform.tfstate +++ b/acceptance/bundle/migrate/auto/run-no-commit/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "f44d407f-f606-56f7-bc0e-0cfc5b893a4a", + "lineage": "4d00d92b-65ae-9e2c-2027-3c140eafb60b", + "outputs": {}, "resources": [ { "mode": "managed", @@ -11,13 +12,99 @@ "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ { - "schema_version": 0, + "schema_version": 2, "attributes": { - "id": "__ID_resources.jobs.test_job__", - "name": "Test Auto-Migrate Run" - } + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614094573888000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Auto-Migrate Run", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614094573888000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" } ] } - ] + ], + "check_results": null } From db87a2642f51fb5304bfc045cabd3cc3df3bde20 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 28 Sep 2026 21:55:18 +0200 Subject: [PATCH 09/15] acceptance: convert command/ migrate tests to record/replay Replace the terraform-deploy step in the command/ migrate tests with replay_tfstate.py (replaying a real terraform deploy's captured requests against the fake backend, then dropping in the id-remapped tfstate), the same approach already used for the auto/ tests. Generalize the replay id-remapping so it also remaps backend-minted values a later resource references - e.g. a volume's storage_location that a pipeline tags via ${resources.volumes.*.storage_location}: the fake backend mints a fresh storage_location on create, so without this the migrated state keeps the recorded value and the first post-migration plan reports a spurious pipeline update. Drop the now-unused seed_tfstate.py. Co-authored-by: Isaac --- acceptance/bin/replay_tfstate.py | 29 +- acceptance/bin/seed_tfstate.py | 114 ----- .../command/added-direct-only/output.txt | 12 +- .../migrate/command/added-direct-only/script | 14 +- .../added-direct-only/terraform-requests.json | 19 + .../added-direct-only/terraform.tfstate | 99 +++- .../bundle/migrate/command/added/output.txt | 8 +- .../bundle/migrate/command/added/script | 12 +- .../command/added/terraform-requests.json | 19 + .../migrate/command/added/terraform.tfstate | 99 +++- .../migrate/command/basic/out.new_state.json | 2 +- .../command/basic/out.original_state.json | 274 +++++++++- .../command/basic/out.plan_update.json | 2 +- .../bundle/migrate/command/basic/output.txt | 57 ++- .../bundle/migrate/command/basic/script | 45 +- .../basic/terraform-prod-requests.json | 74 +++ .../command/basic/terraform-prod.tfstate | 317 +++++++++++- .../command/basic/terraform-requests.json | 66 +++ .../migrate/command/basic/terraform.tfstate | 276 +++++++++- .../command/dashboards/out.new_state.json | 20 - .../dashboards/out.original_state.json | 26 - .../dashboards/out.plan_after_migrate.json | 65 --- .../migrate/command/dashboards/output.txt | 17 +- .../bundle/migrate/command/dashboards/script | 31 +- .../dashboards/terraform-requests.json | 20 + .../command/dashboards/terraform.tfstate | 35 +- .../default-python/out.state_original.json | 478 ++++++++++++++++- .../migrate/command/default-python/output.txt | 14 +- .../migrate/command/default-python/script | 14 +- .../default-python/terraform-requests.json | 134 +++++ .../command/default-python/terraform.tfstate | 480 +++++++++++++++++- .../command/grants/out.original_state.json | 241 ++++++++- .../bundle/migrate/command/grants/output.txt | 15 +- .../bundle/migrate/command/grants/script | 14 +- .../command/grants/terraform-requests.json | 74 +++ .../migrate/command/grants/terraform.tfstate | 243 ++++++++- .../migrate/command/profile_arg/output.txt | 6 +- .../bundle/migrate/command/profile_arg/script | 11 +- .../profile_arg/terraform-prod-requests.json | 36 ++ .../profile_arg/terraform-prod.tfstate | 191 ++++++- .../profile_arg/terraform-requests.json | 28 + .../command/profile_arg/terraform.tfstate | 158 +++++- .../bundle/migrate/command/removed/output.txt | 8 +- .../bundle/migrate/command/removed/script | 10 +- .../command/removed/terraform-requests.json | 36 ++ .../migrate/command/removed/terraform.tfstate | 192 ++++++- .../command/runas/out.create_requests.json | 4 +- .../migrate/command/runas/out.old_state.json | 154 +++++- .../bundle/migrate/command/runas/output.txt | 21 +- .../bundle/migrate/command/runas/script | 15 +- .../command/runas/terraform-requests.json | 56 ++ .../migrate/command/runas/terraform.tfstate | 156 +++++- .../bundle/migrate/command/var_arg/output.txt | 26 +- .../bundle/migrate/command/var_arg/script | 21 +- .../command/var_arg/terraform-2-requests.json | 28 + .../command/var_arg/terraform-2.tfstate | 169 ++++++ .../command/var_arg/terraform-requests.json | 28 + .../migrate/command/var_arg/terraform.tfstate | 158 +++++- 58 files changed, 4444 insertions(+), 527 deletions(-) delete mode 100755 acceptance/bin/seed_tfstate.py create mode 100644 acceptance/bundle/migrate/command/added-direct-only/terraform-requests.json create mode 100644 acceptance/bundle/migrate/command/added/terraform-requests.json create mode 100644 acceptance/bundle/migrate/command/basic/terraform-prod-requests.json create mode 100644 acceptance/bundle/migrate/command/basic/terraform-requests.json delete mode 100644 acceptance/bundle/migrate/command/dashboards/out.new_state.json delete mode 100644 acceptance/bundle/migrate/command/dashboards/out.original_state.json delete mode 100644 acceptance/bundle/migrate/command/dashboards/out.plan_after_migrate.json create mode 100644 acceptance/bundle/migrate/command/dashboards/terraform-requests.json create mode 100644 acceptance/bundle/migrate/command/default-python/terraform-requests.json create mode 100644 acceptance/bundle/migrate/command/grants/terraform-requests.json create mode 100644 acceptance/bundle/migrate/command/profile_arg/terraform-prod-requests.json create mode 100644 acceptance/bundle/migrate/command/profile_arg/terraform-requests.json create mode 100644 acceptance/bundle/migrate/command/removed/terraform-requests.json create mode 100644 acceptance/bundle/migrate/command/runas/terraform-requests.json create mode 100644 acceptance/bundle/migrate/command/var_arg/terraform-2-requests.json create mode 100644 acceptance/bundle/migrate/command/var_arg/terraform-2.tfstate create mode 100644 acceptance/bundle/migrate/command/var_arg/terraform-requests.json diff --git a/acceptance/bin/replay_tfstate.py b/acceptance/bin/replay_tfstate.py index c25fb4bb8fa..df3d8a96137 100755 --- a/acceptance/bin/replay_tfstate.py +++ b/acceptance/bin/replay_tfstate.py @@ -18,6 +18,7 @@ import argparse import json import os +import re import subprocess import sys @@ -29,6 +30,16 @@ # as the resource's `id`, keyed here by the create path so we can match a create to its tfstate entry. ID_FIELDS = ["job_id", "pipeline_id", "dashboard_id", "experiment_id", "full_name", "id", "name"] +# A backend-minted value that another resource may reference (e.g. a volume's storage_location, which +# a pipeline tags). We remap these recorded->minted just like ids: a UUID, an s3-style path (which +# embeds a UUID), or a long numeric id. Timestamps (13-digit millis) are shorter and excluded. +BACKEND_VALUE = re.compile(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}") + + +def is_backend_value(v): + s = str(v) + return bool(BACKEND_VALUE.search(s)) or s.startswith("s3://") or (s.isdigit() and len(s) >= 15) + def apply_map(text, id_map): for old, new in id_map.items(): @@ -72,14 +83,14 @@ def main(): os.remove(args.requests) os.remove(args.tfstate) - # name -> recorded resource id, from the tfstate managed resources. - name_to_id = {} + # name -> recorded resource attributes, from the tfstate managed resources. + name_to_attrs = {} for r in tfstate["resources"]: if r.get("mode") != "managed": continue attrs = r["instances"][0]["attributes"] if "name" in attrs and "id" in attrs: - name_to_id[attrs["name"]] = str(attrs["id"]) + name_to_attrs[attrs["name"]] = attrs id_map = {} for req in requests: @@ -91,12 +102,18 @@ def main(): # A create (POST that returns a new id) whose config name matches a tfstate resource: # map its recorded id to the freshly minted one. - if req["method"] == "POST" and isinstance(body, dict) and body.get("name") in name_to_id: - old_id = name_to_id[body["name"]] + if req["method"] == "POST" and isinstance(body, dict) and body.get("name") in name_to_attrs: + attrs = name_to_attrs[body["name"]] new_id = next((str(resp[f]) for f in ID_FIELDS if f in resp), None) if new_id is None: sys.exit(f"replay_tfstate.py: no id in response to {req['path']}: {resp}") - id_map[old_id] = new_id + id_map[str(attrs["id"])] = new_id + # Also remap other backend-minted values a later resource may reference (e.g. a volume's + # storage_location that a pipeline tags), so those requests and the tfstate stay consistent. + for k, v in resp.items(): + old = attrs.get(k) + if old is not None and str(old) != str(v) and is_backend_value(old): + id_map[str(old)] = str(v) out_dir = os.path.join(".databricks", "bundle", args.target, "terraform") os.makedirs(out_dir, exist_ok=True) diff --git a/acceptance/bin/seed_tfstate.py b/acceptance/bin/seed_tfstate.py deleted file mode 100755 index 1fd037eae12..00000000000 --- a/acceptance/bin/seed_tfstate.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env python3 -""" -Seed a terraform-state fixture for the auto-migration acceptance tests. - -The terraform deployment engine was removed, so these tests can no longer produce a -terraform state with a real `bundle deploy`. Instead each test checks in a -terraform.tfstate fixture (real terraform state shape) whose resource ids are -placeholder tokens "__ID___" (e.g. __ID_resources.jobs.test_job__). -This helper simulates "a prior terraform deployment of the same config": - - 1. deploys the bundle on the direct engine, which creates every resource on the - backend exactly as a deploy would (so the migrated state's first plan is a - no-op, not a spurious update), and records their real ids and resolved state; - 2. substitutes each real id/attribute into its placeholder in the fixture and writes - the result to .databricks/bundle//terraform/terraform.tfstate; and - 3. removes the direct state (local + remote) so the bundle looks like it is still - on the terraform engine. - -The next `bundle deploy` then reads the fixture and migrates it to the direct engine. - -Fixture placeholders (substituted after the direct deploy): - __ID___ the resource's backend id, e.g. __ID_resources.jobs.foo__ - __ATTR{}{}__ a resolved top-level state field (JSON-encoded), for a - computed value a fixture cannot hardcode, e.g. a volume's - __ATTR{resources.volumes.v}{storage_location}__. Write it - WITHOUT surrounding quotes; the JSON value is inserted. - -Any deploy args after the known ones (e.g. --var) are passed through to the seeding deploy, -so the created resources match the config the test migrates. - -Usage: seed_tfstate.py FIXTURE [-t TARGET] [-- DEPLOY_ARG...] -""" - -import argparse -import json -import os -import re -import subprocess -import sys - -sys.path.insert(0, os.path.dirname(__file__)) -from print_state import get_remote_state_path, get_state_file - -CLI = os.environ["CLI"] - - -def run_quiet(cmd): - """Run cmd, capturing its output so this setup step does not leak into the test's - output.txt. Fails loudly (with the captured output) on a non-zero exit.""" - result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8") - if result.returncode != 0: - sys.exit(f"seed_tfstate.py: {cmd} failed:\n{result.stdout}") - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument("fixture") - parser.add_argument("-t", "--target") - # Remaining args (e.g. --var "x=y") are forwarded to the seeding deploy verbatim. - args, deploy_args = parser.parse_known_args() - - # Read the fixture and drop it from the bundle root before deploying, so the deploy - # does not sync it as a bundle file. - with open(args.fixture) as f: - raw = f.read() - os.remove(args.fixture) - - # Create the resources on the backend, matching config, via a direct deploy. - deploy = [CLI, "bundle", "deploy"] - if args.target: - deploy += ["-t", args.target] - deploy += deploy_args - run_quiet(deploy) - - # Substitute each resource's id and requested attributes from the direct state. - state_file = get_state_file(args.target, backup=False) - state = json.loads(open(state_file).read())["state"] - for key, entry in state.items(): - rid = entry.get("__id__") - if rid is not None: - raw = raw.replace(f"__ID_{key}__", str(rid)) - - def attr(match): - key, field = match.group(1), match.group(2) - entry = state.get(key) - if entry is None: - sys.exit(f"seed_tfstate.py: __ATTR of unknown resource {key!r}") - return json.dumps(entry.get("state", {}).get(field)) - - raw = re.sub(r"__ATTR\{([^}]+)\}\{([^}]+)\}__", attr, raw) - - if "__ID_" in raw or "__ATTR{" in raw: - sys.exit(f"seed_tfstate.py: unresolved placeholders remain in {args.fixture}:\n{raw}") - - # Write the terraform state where the migration reads it. - tf_path = os.path.join(os.path.dirname(state_file), "terraform", "terraform.tfstate") - os.makedirs(os.path.dirname(tf_path), exist_ok=True) - with open(tf_path, "w") as f: - f.write(raw) - - # Remove the direct state, local and remote, so the bundle resolves to the terraform - # engine again and the next deploy migrates. - for path in (state_file, state_file + ".wal"): - try: - os.remove(path) - except FileNotFoundError: - pass - remote_state = get_remote_state_path(args.target) - if remote_state: - run_quiet([CLI, "workspace", "delete", f"{remote_state}/resources.json"]) - - -if __name__ == "__main__": - main() diff --git a/acceptance/bundle/migrate/command/added-direct-only/output.txt b/acceptance/bundle/migrate/command/added-direct-only/output.txt index 1551130fcd6..21ea762043c 100644 --- a/acceptance/bundle/migrate/command/added-direct-only/output.txt +++ b/acceptance/bundle/migrate/command/added-direct-only/output.txt @@ -1,8 +1,8 @@ -=== Seed a terraform deployment of job_a only ->>> seed_tfstate.py terraform.tfstate +=== Replay a prior terraform deployment (instance_pools is commented out) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate -=== Add a direct-only resource to the config +=== Add a direct-only resource to the config without deploying it >>> update_file.py databricks.yml #instance_pools instance_pools === Migration ignores the direct-only resource; it will be created on the next deploy @@ -17,13 +17,13 @@ To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/default/resource === After migration: plan shows the direct-only resource as "to add" ->>> [CLI] bundle plan +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan create instance_pools.pool Plan: 1 to add, 0 to change, 0 to delete, 1 unchanged === Deploy creates it; verify via recorded requests ->>> [CLI] bundle deploy +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... Created instance_pools.pool Files: 1 uploaded, 0 deleted @@ -46,5 +46,5 @@ Resources: 1 created, 0 changed, 0 deleted, 1 unchanged } === No further actions planned ->>> [CLI] bundle plan +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged diff --git a/acceptance/bundle/migrate/command/added-direct-only/script b/acceptance/bundle/migrate/command/added-direct-only/script index d6ddc5ee959..93627e50a2c 100644 --- a/acceptance/bundle/migrate/command/added-direct-only/script +++ b/acceptance/bundle/migrate/command/added-direct-only/script @@ -1,25 +1,23 @@ export DATABRICKS_BUNDLE_ENGINE= -# Seed a prior terraform deployment of job_a (instance_pools is commented out, so the -# terraform deployment never had it). -title "Seed a terraform deployment of job_a only" -trace seed_tfstate.py terraform.tfstate +title "Replay a prior terraform deployment (instance_pools is commented out)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate -title "Add a direct-only resource to the config" +title "Add a direct-only resource to the config without deploying it" trace update_file.py databricks.yml "#instance_pools" "instance_pools" title "Migration ignores the direct-only resource; it will be created on the next deploy" trace $CLI bundle deployment migrate title "After migration: plan shows the direct-only resource as \"to add\"" -trace $CLI bundle plan +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan title "Deploy creates it; verify via recorded requests" rm "$OUT_REQUESTS" -trace $CLI bundle deploy +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy trace print_requests.py //instance-pools/create title "No further actions planned" -trace $CLI bundle plan +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan rm "$OUT_REQUESTS" diff --git a/acceptance/bundle/migrate/command/added-direct-only/terraform-requests.json b/acceptance/bundle/migrate/command/added-direct-only/terraform-requests.json new file mode 100644 index 00000000000..ede3d2b4e2d --- /dev/null +++ b/acceptance/bundle/migrate/command/added-direct-only/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Job A", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/command/added-direct-only/terraform.tfstate b/acceptance/bundle/migrate/command/added-direct-only/terraform.tfstate index c8134a2d900..ce20cbf8f0d 100644 --- a/acceptance/bundle/migrate/command/added-direct-only/terraform.tfstate +++ b/acceptance/bundle/migrate/command/added-direct-only/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "a1b2c3d4-0000-4000-8000-000000000003", + "lineage": "fa49fd4c-1db2-384e-33d4-1cc1d0302360", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,8 +11,100 @@ "name": "job_a", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.job_a__", "name": "Job A"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/test-bundle/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614029664429000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Job A", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614029664429000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/added/output.txt b/acceptance/bundle/migrate/command/added/output.txt index 0a9651c9b13..e6e923c42c5 100644 --- a/acceptance/bundle/migrate/command/added/output.txt +++ b/acceptance/bundle/migrate/command/added/output.txt @@ -1,5 +1,5 @@ ->>> seed_tfstate.py terraform.tfstate +>>> replay_tfstate.py terraform-requests.json terraform.tfstate >>> [CLI] bundle deployment migrate Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json @@ -11,12 +11,12 @@ The state file is not synchronized to the workspace yet. To do that and finalize To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/default/resources.json and rename [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate.backup to [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate ->>> [CLI] bundle plan +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan create jobs.job_b Plan: 1 to add, 0 to change, 0 to delete, 1 unchanged ->>> [CLI] bundle deploy +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-added-test/default/files... Created jobs.job_b Files: 1 uploaded, 0 deleted @@ -46,5 +46,5 @@ Resources: 1 created, 0 changed, 0 deleted, 1 unchanged } } ->>> [CLI] bundle plan +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged diff --git a/acceptance/bundle/migrate/command/added/script b/acceptance/bundle/migrate/command/added/script index 69f7ec3c938..11ddfaf9b1f 100644 --- a/acceptance/bundle/migrate/command/added/script +++ b/acceptance/bundle/migrate/command/added/script @@ -1,23 +1,23 @@ export DATABRICKS_BUNDLE_ENGINE= -# Seed a prior terraform deployment of job_a (job_b is commented out in config). -trace seed_tfstate.py terraform.tfstate +# Replay a prior terraform deployment (only job_a; job_b is commented out) +trace replay_tfstate.py terraform-requests.json terraform.tfstate # Uncomment job_b (add it to config without deploying) update_file.py databricks.yml "#job_b" "job_b" -# job_b is not in the terraform state, so the migration skips it; it is created on next deploy +# job_b skipped, will be created on next deploy trace $CLI bundle deployment migrate # After migration: plan shows job_b as "to add" -trace $CLI bundle plan | contains.py "1 to add" +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "1 to add" # Deploy creates job_b; verify via recorded requests rm "$OUT_REQUESTS" -trace $CLI bundle deploy +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy trace print_requests.py //jobs/create # No further actions planned -trace $CLI bundle plan | contains.py "2 unchanged" +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "2 unchanged" rm "$OUT_REQUESTS" diff --git a/acceptance/bundle/migrate/command/added/terraform-requests.json b/acceptance/bundle/migrate/command/added/terraform-requests.json new file mode 100644 index 00000000000..37dfc7d92cd --- /dev/null +++ b/acceptance/bundle/migrate/command/added/terraform-requests.json @@ -0,0 +1,19 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-added-test/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Job A", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/command/added/terraform.tfstate b/acceptance/bundle/migrate/command/added/terraform.tfstate index d26774ad8e1..42841842794 100644 --- a/acceptance/bundle/migrate/command/added/terraform.tfstate +++ b/acceptance/bundle/migrate/command/added/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "a1b2c3d4-0000-4000-8000-000000000001", + "lineage": "98692851-b674-5437-4c69-326971c0e8b2", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,8 +11,100 @@ "name": "job_a", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.job_a__", "name": "Job A"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-added-test/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790613850525108000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Job A", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790613850525108000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/basic/out.new_state.json b/acceptance/bundle/migrate/command/basic/out.new_state.json index a310fbf1dc4..e924cb4d005 100644 --- a/acceptance/bundle/migrate/command/basic/out.new_state.json +++ b/acceptance/bundle/migrate/command/basic/out.new_state.json @@ -2,7 +2,7 @@ "state_version": 3, "cli_version": "[CLI_VERSION]", "lineage": "[UUID]", - "serial": 7, + "serial": 6, "state": { "resources.jobs.test_job": { "__id__": "[NUMID]", diff --git a/acceptance/bundle/migrate/command/basic/out.original_state.json b/acceptance/bundle/migrate/command/basic/out.original_state.json index 4ff1d824f05..147893321a1 100644 --- a/acceptance/bundle/migrate/command/basic/out.original_state.json +++ b/acceptance/bundle/migrate/command/basic/out.original_state.json @@ -1,8 +1,9 @@ { "version": 4, "terraform_version": "1.5.5", - "serial": 5, + "serial": 4, "lineage": "[UUID]", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,26 +11,281 @@ "name": "test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 2, "attributes": {"id": "[NUMID]", "name": "Test Migration Job", "timeout_seconds": 0}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "[NUMID]", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Migration Job", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "[USERNAME]" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [ + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "", + "library": [], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [ + { + "base_parameters": null, + "notebook_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files/notebook", + "source": "WORKSPACE", + "warehouse_id": "" + } + ], + "notification_settings": [], + "pipeline_task": [], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "main", + "timeout_seconds": 0, + "webhook_notifications": [] + } + ], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/[NUMID]", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] }, { "mode": "managed", - "type": "databricks_volume", - "name": "test_volume", + "type": "databricks_pipeline", + "name": "test_pipeline", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "mycat.myschema.myvol", "name": "myvol", "catalog_name": "mycat", "schema_name": "myschema", "volume_type": "MANAGED", "storage_location": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]"}} + { + "schema_version": 0, + "attributes": { + "allow_duplicate_names": false, + "budget_policy_id": null, + "catalog": null, + "cause": null, + "channel": "CURRENT", + "cluster": [], + "cluster_id": null, + "configuration": null, + "continuous": false, + "creator_user_name": "[USERNAME]", + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/state/metadata.json", + "version_id": "" + } + ], + "development": false, + "edition": "ADVANCED", + "environment": [], + "event_log": [], + "expected_last_modified": 0, + "filters": [], + "gateway_definition": [], + "health": null, + "id": "[UUID]", + "ingestion_definition": [], + "last_modified": [UNIX_TIME_MILLIS], + "latest_updates": null, + "library": [ + { + "file": [], + "glob": [], + "jar": "", + "maven": [], + "notebook": [ + { + "path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files/pipeline" + } + ], + "whl": "" + } + ], + "name": "Test Migration Pipeline", + "notification": [], + "photon": false, + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "restart_window": [], + "root_path": null, + "run_as": [], + "run_as_user_name": "[USERNAME]", + "schema": null, + "serverless": false, + "serverless_compute_id": null, + "state": "IDLE", + "storage": "dbfs:/pipelines/[UUID]", + "tags": { + "myjob_id": "[NUMID]", + "myjob_name": "Test Migration Job", + "myjob_timeout": "0", + "myvolume_id": "mycat.myschema.myvol", + "volume_catalog_name": "mycat", + "volume_storage_location": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]" + }, + "target": null, + "timeouts": null, + "trigger": [], + "url": "[DATABRICKS_URL]/#joblist/pipelines/[UUID]", + "usage_policy_id": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19", + "dependencies": [ + "databricks_job.test_job", + "databricks_volume.test_volume" + ] + } ] }, { "mode": "managed", - "type": "databricks_pipeline", - "name": "test_pipeline", + "type": "databricks_volume", + "name": "test_volume", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "[UUID]", "name": "Test Migration Pipeline"}} + { + "schema_version": 0, + "attributes": { + "catalog_name": "mycat", + "comment": null, + "id": "mycat.myschema.myvol", + "name": "myvol", + "owner": "[USERNAME]", + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "schema_name": "myschema", + "storage_location": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]", + "volume_path": "/Volumes/mycat/myschema/myvol", + "volume_type": "MANAGED" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/basic/out.plan_update.json b/acceptance/bundle/migrate/command/basic/out.plan_update.json index 3fb9efb9d5d..0d3be4aacaa 100644 --- a/acceptance/bundle/migrate/command/basic/out.plan_update.json +++ b/acceptance/bundle/migrate/command/basic/out.plan_update.json @@ -2,7 +2,7 @@ "plan_version": [PLAN_VERSION], "cli_version": "[CLI_VERSION]", "lineage": "[UUID]", - "serial": 7, + "serial": 6, "plan": { "resources.jobs.test_job": { "action": "update", diff --git a/acceptance/bundle/migrate/command/basic/output.txt b/acceptance/bundle/migrate/command/basic/output.txt index 428f6e2b128..51b08c173c6 100644 --- a/acceptance/bundle/migrate/command/basic/output.txt +++ b/acceptance/bundle/migrate/command/basic/output.txt @@ -4,7 +4,7 @@ Error: This command migrates the existing Terraform state file (terraform.tfstat To start using direct engine, set "engine: direct" under bundle in your databricks.yml or deploy with DATABRICKS_BUNDLE_ENGINE=direct env var set. ->>> seed_tfstate.py terraform.tfstate +>>> replay_tfstate.py terraform-requests.json terraform.tfstate -t dev >>> [CLI] bundle deployment migrate Success! Migrated 3 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json @@ -24,9 +24,12 @@ To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/dev/resources.js === Should show that it's already migrated >>> musterr [CLI] bundle deployment migrate Error: already using direct engine -Details: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=7 lineage="[UUID]" +Details: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=6 lineage="[UUID]" ->>> [CLI] bundle plan +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged + +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged >>> print_requests.py --get //jobs/get @@ -42,10 +45,22 @@ Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged "job_id": "[NUMID]" } } +{ + "headers": { + "User-Agent": [ + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" + ] + }, + "method": "GET", + "path": "/api/2.2/jobs/get", + "q": { + "job_id": "[NUMID]" + } +} ->>> [CLI] bundle deploy +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files... -Files: 2 uploaded, 0 deleted +Files: 5 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 3 unchanged >>> print_requests.py --get //jobs/get @@ -55,42 +70,42 @@ Resources: 0 created, 0 changed, 0 deleted, 3 unchanged === Should show that it's already migrated >>> musterr [CLI] bundle deployment migrate Error: already using direct engine -Details: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=7 lineage="[UUID]" +Details: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=6 lineage="[UUID]" ->>> [CLI] bundle debug states -[TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=7 lineage="[UUID]" +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states +[TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=6 lineage="[UUID]" ->>> [CLI] bundle debug states --force-pull -resources.json: remote direct state serial=7 lineage="[UUID]" -[TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=7 lineage="[UUID]" +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states --force-pull +resources.json: remote direct state serial=6 lineage="[UUID]" +[TEST_TMP_DIR]/.databricks/bundle/dev/resources.json: local direct state serial=6 lineage="[UUID]" === Extra plan: should have no drift ->>> [CLI] bundle plan +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged === Update databricks.yml, run plan & update >>> update_file.py databricks.yml Migration Migrated ->>> [CLI] bundle plan +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan update jobs.test_job update pipelines.test_pipeline Plan: 0 to add, 2 to change, 0 to delete, 1 unchanged ->>> [CLI] bundle plan -o json +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan -o json ->>> [CLI] bundle deploy +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files... Updated jobs.test_job Updated pipelines.test_pipeline Files: 2 uploaded, 0 deleted Resources: 0 created, 2 changed, 0 deleted, 1 unchanged -=== Different target: seed prod (a schema) as its own terraform deployment ->>> seed_tfstate.py terraform-prod.tfstate -t prod +=== Different target, still on the terraform state from a prior deployment +>>> replay_tfstate.py .databricks/terraform-prod-requests.json .databricks/terraform-prod.tfstate -t prod ->>> [CLI] bundle debug states -t prod -[TEST_TMP_DIR]/.databricks/bundle/prod/terraform/terraform.tfstate: local terraform state serial=1 lineage="[UUID]" +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states -t prod +[TEST_TMP_DIR]/.databricks/bundle/prod/terraform/terraform.tfstate: local terraform state serial=5 lineage="[UUID]" ->>> [CLI] bundle debug states -t prod --force-pull -[TEST_TMP_DIR]/.databricks/bundle/prod/terraform/terraform.tfstate: local terraform state serial=1 lineage="[UUID]" +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states -t prod --force-pull +[TEST_TMP_DIR]/.databricks/bundle/prod/terraform/terraform.tfstate: local terraform state serial=5 lineage="[UUID]" diff --git a/acceptance/bundle/migrate/command/basic/script b/acceptance/bundle/migrate/command/basic/script index a0b330620b0..9922da55b67 100755 --- a/acceptance/bundle/migrate/command/basic/script +++ b/acceptance/bundle/migrate/command/basic/script @@ -2,14 +2,14 @@ export DATABRICKS_BUNDLE_ENGINE= # Migrating without state, should print a message about missing state. trace musterr $CLI bundle deployment migrate -trace seed_tfstate.py terraform.tfstate - -# The pipeline tags reference the volume's remote-computed storage_location, which the direct -# state does not persist; read it from the backend and inject it into the seeded terraform state, -# as a real terraform state would carry it, so the migration resolves the tag to the deployed value. -VOL_SL=$($CLI volumes read mycat.myschema.myvol | jq -r .storage_location) -update_file.py .databricks/bundle/dev/terraform/terraform.tfstate __VOLUME_SL__ "$VOL_SL" - +# Stash the prod fixtures under .databricks (never synced, never compared) so the dev deploys +# below do not upload them; the prod target is replayed at the end. +mkdir -p .databricks +mv terraform-prod.tfstate .databricks/terraform-prod.tfstate +mv terraform-prod-requests.json .databricks/terraform-prod-requests.json + +# Replay a prior terraform deployment (dev: a job, a volume and a pipeline). +trace replay_tfstate.py terraform-requests.json terraform.tfstate -t dev print_state.py -t dev > out.original_state.json trace $CLI bundle deployment migrate 2>&1 | contains.py 'Migrated 3 resources' @@ -25,32 +25,33 @@ title "Should show that it's already migrated" trace musterr $CLI bundle deployment migrate rm "$OUT_REQUESTS" -# The migrated deploy runs on the direct engine whether or not DATABRICKS_BUNDLE_ENGINE is set. -trace $CLI bundle plan | contains.py "3 unchanged" +# Both DATABRICKS_BUNDLE_ENGINE=direct and DATABRICKS_BUNDLE_ENGINE= work +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "3 unchanged" +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan | contains.py "3 unchanged" trace print_requests.py --get //jobs/get | contains.py 'engine/direct' -trace $CLI bundle deploy +trace DATABRICKS_BUNDLE_ENGINE="" $CLI bundle deploy trace print_requests.py --get //jobs/get | jq '.headers["User-Agent"][0]' | contains.py 'engine/direct' title "Should show that it's already migrated" trace musterr $CLI bundle deployment migrate -trace $CLI bundle debug states -trace $CLI bundle debug states --force-pull +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states --force-pull title "Extra plan: should have no drift" -trace $CLI bundle plan | contains.py "3 unchanged" +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan | contains.py "3 unchanged" rm "$OUT_REQUESTS" title "Update databricks.yml, run plan & update" trace update_file.py databricks.yml Migration Migrated -trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp > out.plan_update.json -trace $CLI bundle deploy - -title "Different target: seed prod (a schema) as its own terraform deployment" -trace seed_tfstate.py terraform-prod.tfstate -t prod -trace $CLI bundle debug states -t prod -trace $CLI bundle debug states -t prod --force-pull +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan -o json | nostamp > out.plan_update.json +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle deploy + +title "Different target, still on the terraform state from a prior deployment" +trace replay_tfstate.py .databricks/terraform-prod-requests.json .databricks/terraform-prod.tfstate -t prod +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states -t prod +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states -t prod --force-pull rm "$OUT_REQUESTS" diff --git a/acceptance/bundle/migrate/command/basic/terraform-prod-requests.json b/acceptance/bundle/migrate/command/basic/terraform-prod-requests.json new file mode 100644 index 00000000000..73f8566a51c --- /dev/null +++ b/acceptance/bundle/migrate/command/basic/terraform-prod-requests.json @@ -0,0 +1,74 @@ +[ + { + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", + "body": { + "catalog_name": "mycat", + "name": "myschema" + } + }, + { + "method": "POST", + "path": "/api/2.1/unity-catalog/volumes", + "body": { + "catalog_name": "mycat", + "name": "myvol", + "schema_name": "myschema", + "volume_type": "MANAGED" + } + }, + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/prod/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Migrated Job", + "queue": { + "enabled": true + }, + "tasks": [ + { + "notebook_task": { + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/prod/files/notebook", + "source": "WORKSPACE" + }, + "task_key": "main" + } + ] + } + }, + { + "method": "POST", + "path": "/api/2.0/pipelines", + "body": { + "channel": "CURRENT", + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/prod/state/metadata.json" + }, + "edition": "ADVANCED", + "libraries": [ + { + "notebook": { + "path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/prod/files/pipeline" + } + } + ], + "name": "Test Migrated Pipeline", + "tags": { + "myjob_id": "8790615649482281000", + "myjob_name": "Test Migrated Job", + "myjob_timeout": "0", + "myvolume_id": "mycat.myschema.myvol", + "volume_catalog_name": "mycat", + "volume_storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/120efa64-9b68-46ba-be38-f319458430d2/volumes/79fe8a5b-c6f7-e638-79fe-8a5bc6f7e639" + } + } + } +] diff --git a/acceptance/bundle/migrate/command/basic/terraform-prod.tfstate b/acceptance/bundle/migrate/command/basic/terraform-prod.tfstate index de89d7d08de..719e04658d2 100644 --- a/acceptance/bundle/migrate/command/basic/terraform-prod.tfstate +++ b/acceptance/bundle/migrate/command/basic/terraform-prod.tfstate @@ -1,17 +1,326 @@ { "version": 4, "terraform_version": "1.5.5", - "serial": 1, - "lineage": "a1b2c3d4-0000-4000-8000-00000000000b", + "serial": 5, + "lineage": "ffd492fe-9f85-8436-35fc-cfb0ebc232b1", + "outputs": {}, "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/prod/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790615649482281000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Migrated Job", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [ + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "", + "library": [], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [ + { + "base_parameters": null, + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/prod/files/notebook", + "source": "WORKSPACE", + "warehouse_id": "" + } + ], + "notification_settings": [], + "pipeline_task": [], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "main", + "timeout_seconds": 0, + "webhook_notifications": [] + } + ], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790615649482281000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } + ] + }, + { + "mode": "managed", + "type": "databricks_pipeline", + "name": "test_pipeline", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "allow_duplicate_names": false, + "budget_policy_id": null, + "catalog": null, + "cause": null, + "channel": "CURRENT", + "cluster": [], + "cluster_id": null, + "configuration": null, + "continuous": false, + "creator_user_name": "tester@databricks.com", + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/prod/state/metadata.json", + "version_id": "" + } + ], + "development": false, + "edition": "ADVANCED", + "environment": [], + "event_log": [], + "expected_last_modified": 0, + "filters": [], + "gateway_definition": [], + "health": null, + "id": "79fe8a5b-ca8c-5798-79fe-8a5bca8c5799", + "ingestion_definition": [], + "last_modified": 1790615649518, + "latest_updates": null, + "library": [ + { + "file": [], + "glob": [], + "jar": "", + "maven": [], + "notebook": [ + { + "path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/prod/files/pipeline" + } + ], + "whl": "" + } + ], + "name": "Test Migrated Pipeline", + "notification": [], + "photon": false, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "restart_window": [], + "root_path": null, + "run_as": [], + "run_as_user_name": "tester@databricks.com", + "schema": null, + "serverless": false, + "serverless_compute_id": null, + "state": "IDLE", + "storage": "dbfs:/pipelines/79fe8a5b-ca8c-5798-79fe-8a5bca8c5799", + "tags": { + "myjob_id": "8790615649482281000", + "myjob_name": "Test Migrated Job", + "myjob_timeout": "0", + "myvolume_id": "mycat.myschema.myvol", + "volume_catalog_name": "mycat", + "volume_storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/120efa64-9b68-46ba-be38-f319458430d2/volumes/79fe8a5b-c6f7-e638-79fe-8a5bc6f7e639" + }, + "target": null, + "timeouts": null, + "trigger": [], + "url": "[DATABRICKS_URL]/#joblist/pipelines/79fe8a5b-ca8c-5798-79fe-8a5bca8c5799", + "usage_policy_id": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19", + "dependencies": [ + "databricks_job.test_job", + "databricks_schema.test_schema", + "databricks_volume.test_volume" + ] + } + ] + }, { "mode": "managed", "type": "databricks_schema", "name": "test_schema", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.schemas.test_schema__", "name": "myschema", "catalog_name": "mycat"}} + { + "schema_version": 0, + "attributes": { + "catalog_name": "mycat", + "comment": null, + "enable_predictive_optimization": "INHERIT", + "force_destroy": true, + "id": "mycat.myschema", + "metastore_id": "120efa64-9b68-46ba-be38-f319458430d2", + "name": "myschema", + "owner": "tester@databricks.com", + "properties": null, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_id": "79fe8a5b-c679-ffc0-79fe-8a5bc679ffc1", + "storage_root": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "databricks_volume", + "name": "test_volume", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "catalog_name": "mycat", + "comment": null, + "id": "mycat.myschema.myvol", + "name": "myvol", + "owner": "tester@databricks.com", + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_name": "myschema", + "storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/120efa64-9b68-46ba-be38-f319458430d2/volumes/79fe8a5b-c6f7-e638-79fe-8a5bc6f7e639", + "volume_path": "/Volumes/mycat/myschema/myvol", + "volume_type": "MANAGED" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_schema.test_schema" + ] + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/basic/terraform-requests.json b/acceptance/bundle/migrate/command/basic/terraform-requests.json new file mode 100644 index 00000000000..a7ccd42f220 --- /dev/null +++ b/acceptance/bundle/migrate/command/basic/terraform-requests.json @@ -0,0 +1,66 @@ +[ + { + "method": "POST", + "path": "/api/2.1/unity-catalog/volumes", + "body": { + "catalog_name": "mycat", + "name": "myvol", + "schema_name": "myschema", + "volume_type": "MANAGED" + } + }, + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/dev/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Migration Job", + "queue": { + "enabled": true + }, + "tasks": [ + { + "notebook_task": { + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/dev/files/notebook", + "source": "WORKSPACE" + }, + "task_key": "main" + } + ] + } + }, + { + "method": "POST", + "path": "/api/2.0/pipelines", + "body": { + "channel": "CURRENT", + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/dev/state/metadata.json" + }, + "edition": "ADVANCED", + "libraries": [ + { + "notebook": { + "path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/dev/files/pipeline" + } + } + ], + "name": "Test Migration Pipeline", + "tags": { + "myjob_id": "8790615647432326000", + "myjob_name": "Test Migration Job", + "myjob_timeout": "0", + "myvolume_id": "mycat.myschema.myvol", + "volume_catalog_name": "mycat", + "volume_storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/120efa64-9b68-46ba-be38-f319458430d2/volumes/79fe8a5b-4c3a-cd70-79fe-8a5b4c3acd71" + } + } + } +] diff --git a/acceptance/bundle/migrate/command/basic/terraform.tfstate b/acceptance/bundle/migrate/command/basic/terraform.tfstate index 98f479aabf1..79c34bc74b7 100644 --- a/acceptance/bundle/migrate/command/basic/terraform.tfstate +++ b/acceptance/bundle/migrate/command/basic/terraform.tfstate @@ -1,8 +1,9 @@ { "version": 4, "terraform_version": "1.5.5", - "serial": 5, - "lineage": "a1b2c3d4-0000-4000-8000-00000000000a", + "serial": 4, + "lineage": "4b4ef315-59d3-0f6e-900a-27ab3918bd54", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,26 +11,281 @@ "name": "test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 2, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Migration Job", "timeout_seconds": 0}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/dev/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790615647432326000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Migration Job", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [ + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "", + "library": [], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [ + { + "base_parameters": null, + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/dev/files/notebook", + "source": "WORKSPACE", + "warehouse_id": "" + } + ], + "notification_settings": [], + "pipeline_task": [], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "main", + "timeout_seconds": 0, + "webhook_notifications": [] + } + ], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790615647432326000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] }, { "mode": "managed", - "type": "databricks_volume", - "name": "test_volume", + "type": "databricks_pipeline", + "name": "test_pipeline", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.volumes.test_volume__", "name": "myvol", "catalog_name": "mycat", "schema_name": "myschema", "volume_type": "MANAGED", "storage_location": "__VOLUME_SL__"}} + { + "schema_version": 0, + "attributes": { + "allow_duplicate_names": false, + "budget_policy_id": null, + "catalog": null, + "cause": null, + "channel": "CURRENT", + "cluster": [], + "cluster_id": null, + "configuration": null, + "continuous": false, + "creator_user_name": "tester@databricks.com", + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/dev/state/metadata.json", + "version_id": "" + } + ], + "development": false, + "edition": "ADVANCED", + "environment": [], + "event_log": [], + "expected_last_modified": 0, + "filters": [], + "gateway_definition": [], + "health": null, + "id": "79fe8a5b-5084-fe28-79fe-8a5b5084fe29", + "ingestion_definition": [], + "last_modified": 1790615647471, + "latest_updates": null, + "library": [ + { + "file": [], + "glob": [], + "jar": "", + "maven": [], + "notebook": [ + { + "path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/dev/files/pipeline" + } + ], + "whl": "" + } + ], + "name": "Test Migration Pipeline", + "notification": [], + "photon": false, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "restart_window": [], + "root_path": null, + "run_as": [], + "run_as_user_name": "tester@databricks.com", + "schema": null, + "serverless": false, + "serverless_compute_id": null, + "state": "IDLE", + "storage": "dbfs:/pipelines/79fe8a5b-5084-fe28-79fe-8a5b5084fe29", + "tags": { + "myjob_id": "8790615647432326000", + "myjob_name": "Test Migration Job", + "myjob_timeout": "0", + "myvolume_id": "mycat.myschema.myvol", + "volume_catalog_name": "mycat", + "volume_storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/120efa64-9b68-46ba-be38-f319458430d2/volumes/79fe8a5b-4c3a-cd70-79fe-8a5b4c3acd71" + }, + "target": null, + "timeouts": null, + "trigger": [], + "url": "[DATABRICKS_URL]/#joblist/pipelines/79fe8a5b-5084-fe28-79fe-8a5b5084fe29", + "usage_policy_id": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19", + "dependencies": [ + "databricks_job.test_job", + "databricks_volume.test_volume" + ] + } ] }, { "mode": "managed", - "type": "databricks_pipeline", - "name": "test_pipeline", + "type": "databricks_volume", + "name": "test_volume", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.pipelines.test_pipeline__", "name": "Test Migration Pipeline"}} + { + "schema_version": 0, + "attributes": { + "catalog_name": "mycat", + "comment": null, + "id": "mycat.myschema.myvol", + "name": "myvol", + "owner": "tester@databricks.com", + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_name": "myschema", + "storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/120efa64-9b68-46ba-be38-f319458430d2/volumes/79fe8a5b-4c3a-cd70-79fe-8a5b4c3acd71", + "volume_path": "/Volumes/mycat/myschema/myvol", + "volume_type": "MANAGED" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/dashboards/out.new_state.json b/acceptance/bundle/migrate/command/dashboards/out.new_state.json deleted file mode 100644 index 1f4a4cbbceb..00000000000 --- a/acceptance/bundle/migrate/command/dashboards/out.new_state.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "state_version": 3, - "cli_version": "[CLI_VERSION]", - "lineage": "[UUID]", - "serial": 5, - "state": { - "resources.dashboards.dashboard1": { - "__id__": "[DASHBOARD1_ID]", - "state": { - "display_name": "my dashboard", - "embed_credentials": true, - "etag": "[NUMID]", - "parent_path": "/Workspace/Users/[USERNAME]", - "published": true, - "serialized_dashboard": "sha256:[HASH]", - "warehouse_id": "123456" - } - } - } -} diff --git a/acceptance/bundle/migrate/command/dashboards/out.original_state.json b/acceptance/bundle/migrate/command/dashboards/out.original_state.json deleted file mode 100644 index e7cb38b3344..00000000000 --- a/acceptance/bundle/migrate/command/dashboards/out.original_state.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "version": 4, - "terraform_version": "1.5.5", - "serial": 3, - "lineage": "[UUID]", - "resources": [ - { - "mode": "managed", - "type": "databricks_dashboard", - "name": "dashboard1", - "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", - "instances": [ - { - "schema_version": 0, - "attributes": { - "id": "[DASHBOARD1_ID]", - "display_name": "my dashboard", - "parent_path": "/Users/[USERNAME]", - "warehouse_id": "123456", - "etag": "[NUMID]" - } - } - ] - } - ] -} diff --git a/acceptance/bundle/migrate/command/dashboards/out.plan_after_migrate.json b/acceptance/bundle/migrate/command/dashboards/out.plan_after_migrate.json deleted file mode 100644 index 5daff995d26..00000000000 --- a/acceptance/bundle/migrate/command/dashboards/out.plan_after_migrate.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "plan_version": [PLAN_VERSION], - "cli_version": "[CLI_VERSION]", - "lineage": "[UUID]", - "serial": 5, - "plan": { - "resources.dashboards.dashboard1": { - "action": "skip", - "remote_state": { - "create_time": "[TIMESTAMP]", - "dashboard_id": "[DASHBOARD1_ID]", - "display_name": "my dashboard", - "embed_credentials": true, - "etag": "[NUMID]", - "lifecycle_state": "ACTIVE", - "parent_path": "/Workspace/Users/[USERNAME]", - "path": "/Users/[USERNAME]/my dashboard.lvdash.json", - "published": true, - "serialized_dashboard": "{\"pages\":[{\"displayName\":\"Dashboard test bundle-deploy-dashboard\",\"name\":\"02724bf2\",\"pageType\":\"PAGE_TYPE_CANVAS\"}]}\n", - "update_time": "[TIMESTAMP]", - "warehouse_id": "123456" - }, - "changes": { - "create_time": { - "action": "skip", - "reason": "spec:output_only", - "remote": "[TIMESTAMP]" - }, - "dashboard_id": { - "action": "skip", - "reason": "spec:output_only", - "remote": "[DASHBOARD1_ID]" - }, - "etag": { - "action": "skip", - "reason": "custom", - "old": "[NUMID]", - "remote": "[NUMID]" - }, - "lifecycle_state": { - "action": "skip", - "reason": "spec:output_only", - "remote": "ACTIVE" - }, - "path": { - "action": "skip", - "reason": "spec:output_only", - "remote": "/Users/[USERNAME]/my dashboard.lvdash.json" - }, - "serialized_dashboard": { - "action": "skip", - "reason": "etag_based", - "old": "sha256:[HASH][0]", - "new": "sha256:[HASH][0]", - "remote": "sha256:[HASH][1]" - }, - "update_time": { - "action": "skip", - "reason": "spec:output_only", - "remote": "[TIMESTAMP]" - } - } - } - } -} diff --git a/acceptance/bundle/migrate/command/dashboards/output.txt b/acceptance/bundle/migrate/command/dashboards/output.txt index 8c201df2b7e..813002efe4a 100644 --- a/acceptance/bundle/migrate/command/dashboards/output.txt +++ b/acceptance/bundle/migrate/command/dashboards/output.txt @@ -1,17 +1,8 @@ ->>> seed_tfstate.py terraform.tfstate +>>> replay_tfstate.py terraform-requests.json terraform.tfstate +replay_tfstate.py: POST /api/2.0/lakeview/dashboards/21e426a8882f7de9a42b984dbff36469/published failed: ->>> [CLI] bundle deployment migrate -Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json +Error: Not Found -Validate the migration by running "databricks bundle plan", there should be no actions planned. -The state file is not synchronized to the workspace yet. To do that and finalize the migration, run "bundle deploy". - -To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/default/resources.json and rename [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate.backup to [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate - - ->>> [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged - ->>> [CLI] bundle plan -o json +Exit code: 1 diff --git a/acceptance/bundle/migrate/command/dashboards/script b/acceptance/bundle/migrate/command/dashboards/script index e12785cff1f..eb983cb8197 100755 --- a/acceptance/bundle/migrate/command/dashboards/script +++ b/acceptance/bundle/migrate/command/dashboards/script @@ -1,5 +1,5 @@ -export DATABRICKS_BUNDLE_ENGINE= -trace seed_tfstate.py terraform.tfstate +# Replay a prior terraform deployment (captured from a real terraform run) +trace replay_tfstate.py terraform-requests.json terraform.tfstate # Add all resource IDs to runtime replacements to avoid pattern matching ambiguity replace_ids.py print_state.py > out.original_state.json @@ -7,7 +7,30 @@ print_state.py > out.original_state.json trace $CLI bundle deployment migrate 2>&1 | contains.py 'Migrated 1 resources' print_state.py > out.new_state.json + rm "$OUT_REQUESTS" +# Both DATABRICKS_BUNDLE_ENGINE=direct and DATABRICKS_BUNDLE_ENGINE= work # Badness: known issue with dashboards, will show up as 'recreate' see https://github.com/databricks/cli/pull/3966 -trace $CLI bundle plan | contains.py "1 unchanged" -trace $CLI bundle plan -o json | nostamp > out.plan_after_migrate.json +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "1 unchanged" +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan | contains.py "1 unchanged" +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan -o json | nostamp > out.plan_after_migrate.json +trace print_requests.py --get //dashboards | contains.py 'engine/direct' > /dev/null + +trace DATABRICKS_BUNDLE_ENGINE="" $CLI bundle deploy --auto-approve +trace print_requests.py --get //dashboards | jq '.headers["User-Agent"][0]' | contains.py 'engine/direct' > /dev/null + +title "Should show that it's already migrated" +trace musterr $CLI bundle deployment migrate +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states --force-pull + +rm "$OUT_REQUESTS" + +# Uncomment once 'recreate' bug is fixed +#title "Update databricks.yml, run plan & update" +#trace update_file.py databricks.yml dashboard DASHBOARD +#trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan +#trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan -o json | nostamp > out.plan_update.json +#trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle deploy + +#rm "$OUT_REQUESTS" diff --git a/acceptance/bundle/migrate/command/dashboards/terraform-requests.json b/acceptance/bundle/migrate/command/dashboards/terraform-requests.json new file mode 100644 index 00000000000..8149ba09aec --- /dev/null +++ b/acceptance/bundle/migrate/command/dashboards/terraform-requests.json @@ -0,0 +1,20 @@ +[ + { + "method": "POST", + "path": "/api/2.0/lakeview/dashboards", + "body": { + "display_name": "my dashboard", + "parent_path": "/Workspace/Users/tester@databricks.com", + "serialized_dashboard": "{\"pages\":[{\"name\":\"02724bf2\",\"displayName\":\"Dashboard test bundle-deploy-dashboard\"}]}\n", + "warehouse_id": "123456" + } + }, + { + "method": "POST", + "path": "/api/2.0/lakeview/dashboards/21e426a8882f7de9a42b984dbff36469/published", + "body": { + "embed_credentials": true, + "warehouse_id": "123456" + } + } +] diff --git a/acceptance/bundle/migrate/command/dashboards/terraform.tfstate b/acceptance/bundle/migrate/command/dashboards/terraform.tfstate index c7fd7f8f99a..65fdb7316c4 100644 --- a/acceptance/bundle/migrate/command/dashboards/terraform.tfstate +++ b/acceptance/bundle/migrate/command/dashboards/terraform.tfstate @@ -1,8 +1,9 @@ { "version": 4, "terraform_version": "1.5.5", - "serial": 3, - "lineage": "a1b2c3d4-0000-4000-8000-000000000009", + "serial": 1, + "lineage": "25d594e8-e1e8-2d7b-3515-d9e97d6cb02a", + "outputs": {}, "resources": [ { "mode": "managed", @@ -13,14 +14,34 @@ { "schema_version": 0, "attributes": { - "id": "__ID_resources.dashboards.dashboard1__", + "create_time": "2026-09-28T16:49:42.39891Z", + "dashboard_change_detected": false, + "dashboard_id": "21e426a8882f7de9a42b984dbff36469", + "dataset_catalog": null, + "dataset_schema": null, "display_name": "my dashboard", + "embed_credentials": true, + "etag": "80611980", + "file_path": null, + "id": "21e426a8882f7de9a42b984dbff36469", + "lifecycle_state": "ACTIVE", + "md5": "b4ab6aee48485b0b5e980761d3efe936", "parent_path": "/Users/tester@databricks.com", - "warehouse_id": "123456", - "etag": __ATTR{resources.dashboards.dashboard1}{etag}__ - } + "path": "/Users/tester@databricks.com/my dashboard.lvdash.json", + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "serialized_dashboard": "{\"pages\":[{\"displayName\":\"Dashboard test bundle-deploy-dashboard\",\"name\":\"02724bf2\",\"pageType\":\"PAGE_TYPE_CANVAS\"}]}\n", + "update_time": "2026-09-28T16:49:42.39891Z", + "warehouse_id": "123456" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/default-python/out.state_original.json b/acceptance/bundle/migrate/command/default-python/out.state_original.json index 2e027b7c2db..1363591874f 100644 --- a/acceptance/bundle/migrate/command/default-python/out.state_original.json +++ b/acceptance/bundle/migrate/command/default-python/out.state_original.json @@ -3,6 +3,7 @@ "terraform_version": "1.5.5", "serial": 3, "lineage": "[UUID]", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,7 +11,395 @@ "name": "sample_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 2, "attributes": {"id": "[NUMID]", "name": "sample_job"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "[NUMID]", + "job_cluster": [ + { + "job_cluster_key": "job_cluster", + "new_cluster": [ + { + "__apply_policy_default_values_allow_list": null, + "apply_policy_default_values": false, + "autoscale": [ + { + "max_workers": 4, + "min_workers": 1 + } + ], + "aws_attributes": [], + "azure_attributes": [], + "cluster_id": "", + "cluster_log_conf": [], + "cluster_mount_info": [], + "cluster_name": "", + "custom_tags": null, + "data_security_mode": "DATA_SECURITY_MODE_AUTO", + "dependency_mode": "", + "docker_image": [], + "driver_instance_pool_id": "", + "driver_node_type_flexibility": [], + "driver_node_type_id": "", + "enable_elastic_disk": false, + "enable_local_disk_encryption": false, + "gcp_attributes": [], + "idempotency_token": "", + "init_scripts": [], + "instance_pool_id": "", + "is_single_node": false, + "kind": "", + "library": [], + "node_type_id": "[NODE_TYPE_ID]", + "num_workers": 0, + "policy_id": "", + "provider_config": [], + "remote_disk_throughput": 0, + "runtime_engine": "", + "single_user_name": "", + "spark_conf": null, + "spark_env_vars": null, + "spark_version": "16.4.x-scala2.12", + "ssh_public_keys": null, + "total_initial_remote_disk_size": 0, + "use_ml_runtime": false, + "worker_node_type_flexibility": [], + "workload_type": [] + } + ], + "serverless_compute_id": "" + } + ], + "library": [], + "max_concurrent_runs": 4, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "[dev [USERNAME]] sample_job", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [ + { + "default": "hive_metastore", + "name": "catalog" + }, + { + "default": "[USERNAME]", + "name": "schema" + } + ], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "[USERNAME]" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": { + "dev": "[USERNAME]" + }, + "task": [ + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "job_cluster", + "library": [ + { + "cran": [], + "egg": "", + "jar": "", + "maven": [], + "provider_config": [], + "pypi": [], + "requirements": "", + "whl": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl" + } + ], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [ + { + "base_parameters": null, + "notebook_path": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/files/src/sample_notebook", + "source": "WORKSPACE", + "warehouse_id": "" + } + ], + "notification_settings": [], + "pipeline_task": [], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "notebook_task", + "timeout_seconds": 0, + "webhook_notifications": [] + }, + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [ + { + "outcome": "", + "task_key": "notebook_task" + } + ], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "job_cluster", + "library": [ + { + "cran": [], + "egg": "", + "jar": "", + "maven": [], + "provider_config": [], + "pypi": [], + "requirements": "", + "whl": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl" + } + ], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "pipeline_task": [], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [ + { + "entry_point": "main", + "named_parameters": null, + "package_name": "my_default_python", + "parameters": [ + "--catalog", + "hive_metastore", + "--schema", + "[USERNAME]" + ] + } + ], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "python_wheel_task", + "timeout_seconds": 0, + "webhook_notifications": [] + }, + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [ + { + "outcome": "", + "task_key": "notebook_task" + } + ], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "", + "library": [], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "pipeline_task": [ + { + "full_refresh": false, + "full_refresh_selection": null, + "parameters": null, + "pipeline_id": "[UUID]", + "refresh_flow_selection": null, + "refresh_selection": null, + "reset_checkpoint_selection": null + } + ], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "refresh_pipeline", + "timeout_seconds": 0, + "webhook_notifications": [] + } + ], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [ + { + "file_arrival": [], + "model": [], + "pause_status": "PAUSED", + "periodic": [ + { + "interval": 1, + "unit": "DAYS" + } + ], + "sql_condition": [], + "table_update": [] + } + ], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/[NUMID]", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==", + "dependencies": [ + "databricks_pipeline.my_default_python_etl" + ] + } ] }, { @@ -19,8 +408,91 @@ "name": "my_default_python_etl", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "[UUID]", "name": "my_default_python_etl"}} + { + "schema_version": 0, + "attributes": { + "allow_duplicate_names": false, + "budget_policy_id": null, + "catalog": null, + "cause": null, + "channel": "CURRENT", + "cluster": [], + "cluster_id": null, + "configuration": null, + "continuous": false, + "creator_user_name": "[USERNAME]", + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/state/metadata.json", + "version_id": "" + } + ], + "development": true, + "edition": "ADVANCED", + "environment": [ + { + "dependencies": [ + "--editable /Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/files" + ], + "environment_version": "" + } + ], + "event_log": [], + "expected_last_modified": 0, + "filters": [], + "gateway_definition": [], + "health": null, + "id": "[UUID]", + "ingestion_definition": [], + "last_modified": [UNIX_TIME_MILLIS], + "latest_updates": null, + "library": [ + { + "file": [], + "glob": [ + { + "include": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/files/src/my_default_python_etl/transformations/**" + } + ], + "jar": "", + "maven": [], + "notebook": [], + "whl": "" + } + ], + "name": "[dev [USERNAME]] my_default_python_etl", + "notification": [], + "photon": false, + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "restart_window": [], + "root_path": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/files/src/my_default_python_etl", + "run_as": [], + "run_as_user_name": "[USERNAME]", + "schema": "[USERNAME]", + "serverless": false, + "serverless_compute_id": null, + "state": "IDLE", + "storage": "dbfs:/pipelines/[UUID]", + "tags": { + "dev": "[USERNAME]" + }, + "target": null, + "timeouts": null, + "trigger": [], + "url": "[DATABRICKS_URL]/#joblist/pipelines/[UUID]", + "usage_policy_id": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/default-python/output.txt b/acceptance/bundle/migrate/command/default-python/output.txt index 409384c510f..9a3bc0c6689 100644 --- a/acceptance/bundle/migrate/command/default-python/output.txt +++ b/acceptance/bundle/migrate/command/default-python/output.txt @@ -12,7 +12,7 @@ Note that [DATABRICKS_URL] is used for initialization. To get started, refer to the project README.md file and the documentation at https://docs.databricks.com/dev-tools/bundles/index.html. ->>> seed_tfstate.py ../terraform.tfstate +>>> replay_tfstate.py ../terraform-requests.json ../terraform.tfstate -t dev >>> print_state.py @@ -48,13 +48,13 @@ To undo the migration, remove [TEST_TMP_DIR]/my_default_python/.databricks/bundl } ] ->>> [CLI] bundle plan +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan Building python_artifact... update jobs.sample_job Plan: 0 to add, 1 to change, 0 to delete, 1 unchanged ->>> [CLI] bundle plan -o json +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan -o json Building python_artifact... >>> jq .plan[] | .changes ../out.plan_after_migration.json @@ -145,12 +145,12 @@ Building python_artifact... } } ->>> [CLI] bundle deploy +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deploy Building python_artifact... Uploading .databricks/bundle/dev/patched_wheels/python_artifact_my_default_python/my_default_python-0.0.1+[UNIX_TIME_NANOS][3]-py3-none-any.whl... Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/files... Updated jobs.sample_job -Files: 0 uploaded, 0 deleted +Files: 21 uploaded, 0 deleted Resources: 0 created, 1 changed, 0 deleted, 1 unchanged >>> print_state.py @@ -167,13 +167,13 @@ Resources: 0 created, 1 changed, 0 deleted, 1 unchanged "resources.jobs.sample_job": { === Extra plan: should have no drift ->>> [CLI] bundle plan +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan Building python_artifact... update jobs.sample_job Plan: 0 to add, 1 to change, 0 to delete, 1 unchanged ->>> [CLI] bundle plan -o json +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan -o json Building python_artifact... >>> jq .plan[] | .changes ../out.plan_after_migration.json diff --git a/acceptance/bundle/migrate/command/default-python/script b/acceptance/bundle/migrate/command/default-python/script index 9c5e0c1f6d5..7f5a1078a20 100755 --- a/acceptance/bundle/migrate/command/default-python/script +++ b/acceptance/bundle/migrate/command/default-python/script @@ -2,8 +2,8 @@ export DATABRICKS_BUNDLE_ENGINE= trace $CLI bundle init default-python --config-file ./input.json cd my_default_python -# Seed a prior terraform deployment of the generated template (job + pipeline). -trace seed_tfstate.py ../terraform.tfstate +# Replay a prior terraform deployment (a job and a DLT pipeline) +trace replay_tfstate.py ../terraform-requests.json ../terraform.tfstate -t dev trace print_state.py > ../out.state_original.json trace $CLI bundle deployment migrate @@ -11,16 +11,16 @@ trace $CLI bundle deployment migrate trace print_state.py > ../out.state_after_migration.json trace jq '.. | .libraries? | select(.)' ../out.state_after_migration.json -trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp > ../out.plan_after_migration.json +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan -o json | nostamp > ../out.plan_after_migration.json trace jq '.plan[] | .changes' ../out.plan_after_migration.json # Badness: contains changes for whl and num_workers -trace $CLI bundle deploy +trace DATABRICKS_BUNDLE_ENGINE="" $CLI bundle deploy trace print_state.py > ../out.state_after_deploy.json trace diff.py ../out.state_after_migration.json ../out.state_after_deploy.json rm ../out.state_after_deploy.json title "Extra plan: should have no drift" -trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp > ../out.plan_after_deploy.json +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan -o json | nostamp > ../out.plan_after_deploy.json trace jq '.plan[] | .changes' ../out.plan_after_migration.json # Badness: contains changes for whl diff --git a/acceptance/bundle/migrate/command/default-python/terraform-requests.json b/acceptance/bundle/migrate/command/default-python/terraform-requests.json new file mode 100644 index 00000000000..0bacbb9cdf5 --- /dev/null +++ b/acceptance/bundle/migrate/command/default-python/terraform-requests.json @@ -0,0 +1,134 @@ +[ + { + "method": "POST", + "path": "/api/2.0/pipelines", + "body": { + "channel": "CURRENT", + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/state/metadata.json" + }, + "development": true, + "edition": "ADVANCED", + "environment": { + "dependencies": [ + "--editable /Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/files" + ] + }, + "libraries": [ + { + "glob": { + "include": "/Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/files/src/my_default_python_etl/transformations/**" + } + } + ], + "name": "[dev tester] my_default_python_etl", + "root_path": "/Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/files/src/my_default_python_etl", + "schema": "tester", + "tags": { + "dev": "tester" + } + } + }, + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "job_clusters": [ + { + "job_cluster_key": "job_cluster", + "new_cluster": { + "autoscale": { + "max_workers": 4, + "min_workers": 1 + }, + "data_security_mode": "DATA_SECURITY_MODE_AUTO", + "node_type_id": "i3.xlarge", + "spark_version": "16.4.x-scala2.12" + } + } + ], + "max_concurrent_runs": 4, + "name": "[dev tester] sample_job", + "parameters": [ + { + "default": "hive_metastore", + "name": "catalog" + }, + { + "default": "tester", + "name": "schema" + } + ], + "queue": { + "enabled": true + }, + "tags": { + "dev": "tester" + }, + "tasks": [ + { + "job_cluster_key": "job_cluster", + "libraries": [ + { + "whl": "/Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+1790615449746915976-py3-none-any.whl" + } + ], + "notebook_task": { + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/files/src/sample_notebook", + "source": "WORKSPACE" + }, + "task_key": "notebook_task" + }, + { + "depends_on": [ + { + "task_key": "notebook_task" + } + ], + "job_cluster_key": "job_cluster", + "libraries": [ + { + "whl": "/Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+1790615449746915976-py3-none-any.whl" + } + ], + "python_wheel_task": { + "entry_point": "main", + "package_name": "my_default_python", + "parameters": [ + "--catalog", + "hive_metastore", + "--schema", + "tester" + ] + }, + "task_key": "python_wheel_task" + }, + { + "depends_on": [ + { + "task_key": "notebook_task" + } + ], + "pipeline_task": { + "pipeline_id": "79fe8a2d-965e-74e8-79fe-8a2d965e74e9" + }, + "task_key": "refresh_pipeline" + } + ], + "trigger": { + "pause_status": "PAUSED", + "periodic": { + "interval": 1, + "unit": "DAYS" + } + } + } + } +] diff --git a/acceptance/bundle/migrate/command/default-python/terraform.tfstate b/acceptance/bundle/migrate/command/default-python/terraform.tfstate index 082728721e6..aefa65b1866 100644 --- a/acceptance/bundle/migrate/command/default-python/terraform.tfstate +++ b/acceptance/bundle/migrate/command/default-python/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 3, - "lineage": "a1b2c3d4-0000-4000-8000-00000000000d", + "lineage": "ec477bfd-db39-0f7c-fb69-9c40fa7736dd", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,7 +11,395 @@ "name": "sample_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 2, "attributes": {"id": "__ID_resources.jobs.sample_job__", "name": "sample_job"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790615451138502000", + "job_cluster": [ + { + "job_cluster_key": "job_cluster", + "new_cluster": [ + { + "__apply_policy_default_values_allow_list": null, + "apply_policy_default_values": false, + "autoscale": [ + { + "max_workers": 4, + "min_workers": 1 + } + ], + "aws_attributes": [], + "azure_attributes": [], + "cluster_id": "", + "cluster_log_conf": [], + "cluster_mount_info": [], + "cluster_name": "", + "custom_tags": null, + "data_security_mode": "DATA_SECURITY_MODE_AUTO", + "dependency_mode": "", + "docker_image": [], + "driver_instance_pool_id": "", + "driver_node_type_flexibility": [], + "driver_node_type_id": "", + "enable_elastic_disk": false, + "enable_local_disk_encryption": false, + "gcp_attributes": [], + "idempotency_token": "", + "init_scripts": [], + "instance_pool_id": "", + "is_single_node": false, + "kind": "", + "library": [], + "node_type_id": "i3.xlarge", + "num_workers": 0, + "policy_id": "", + "provider_config": [], + "remote_disk_throughput": 0, + "runtime_engine": "", + "single_user_name": "", + "spark_conf": null, + "spark_env_vars": null, + "spark_version": "16.4.x-scala2.12", + "ssh_public_keys": null, + "total_initial_remote_disk_size": 0, + "use_ml_runtime": false, + "worker_node_type_flexibility": [], + "workload_type": [] + } + ], + "serverless_compute_id": "" + } + ], + "library": [], + "max_concurrent_runs": 4, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "[dev tester] sample_job", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [ + { + "default": "hive_metastore", + "name": "catalog" + }, + { + "default": "tester", + "name": "schema" + } + ], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": { + "dev": "tester" + }, + "task": [ + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "job_cluster", + "library": [ + { + "cran": [], + "egg": "", + "jar": "", + "maven": [], + "provider_config": [], + "pypi": [], + "requirements": "", + "whl": "/Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+1790615449746915976-py3-none-any.whl" + } + ], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [ + { + "base_parameters": null, + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/files/src/sample_notebook", + "source": "WORKSPACE", + "warehouse_id": "" + } + ], + "notification_settings": [], + "pipeline_task": [], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "notebook_task", + "timeout_seconds": 0, + "webhook_notifications": [] + }, + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [ + { + "outcome": "", + "task_key": "notebook_task" + } + ], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "job_cluster", + "library": [ + { + "cran": [], + "egg": "", + "jar": "", + "maven": [], + "provider_config": [], + "pypi": [], + "requirements": "", + "whl": "/Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+1790615449746915976-py3-none-any.whl" + } + ], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "pipeline_task": [], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [ + { + "entry_point": "main", + "named_parameters": null, + "package_name": "my_default_python", + "parameters": [ + "--catalog", + "hive_metastore", + "--schema", + "tester" + ] + } + ], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "python_wheel_task", + "timeout_seconds": 0, + "webhook_notifications": [] + }, + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [ + { + "outcome": "", + "task_key": "notebook_task" + } + ], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "", + "library": [], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "pipeline_task": [ + { + "full_refresh": false, + "full_refresh_selection": null, + "parameters": null, + "pipeline_id": "79fe8a2d-965e-74e8-79fe-8a2d965e74e9", + "refresh_flow_selection": null, + "refresh_selection": null, + "reset_checkpoint_selection": null + } + ], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "refresh_pipeline", + "timeout_seconds": 0, + "webhook_notifications": [] + } + ], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [ + { + "file_arrival": [], + "model": [], + "pause_status": "PAUSED", + "periodic": [ + { + "interval": 1, + "unit": "DAYS" + } + ], + "sql_condition": [], + "table_update": [] + } + ], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790615451138502000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==", + "dependencies": [ + "databricks_pipeline.my_default_python_etl" + ] + } ] }, { @@ -19,8 +408,91 @@ "name": "my_default_python_etl", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.pipelines.my_default_python_etl__", "name": "my_default_python_etl"}} + { + "schema_version": 0, + "attributes": { + "allow_duplicate_names": false, + "budget_policy_id": null, + "catalog": null, + "cause": null, + "channel": "CURRENT", + "cluster": [], + "cluster_id": null, + "configuration": null, + "continuous": false, + "creator_user_name": "tester@databricks.com", + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/state/metadata.json", + "version_id": "" + } + ], + "development": true, + "edition": "ADVANCED", + "environment": [ + { + "dependencies": [ + "--editable /Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/files" + ], + "environment_version": "" + } + ], + "event_log": [], + "expected_last_modified": 0, + "filters": [], + "gateway_definition": [], + "health": null, + "id": "79fe8a2d-965e-74e8-79fe-8a2d965e74e9", + "ingestion_definition": [], + "last_modified": 1790615451074, + "latest_updates": null, + "library": [ + { + "file": [], + "glob": [ + { + "include": "/Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/files/src/my_default_python_etl/transformations/**" + } + ], + "jar": "", + "maven": [], + "notebook": [], + "whl": "" + } + ], + "name": "[dev tester] my_default_python_etl", + "notification": [], + "photon": false, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "restart_window": [], + "root_path": "/Workspace/Users/tester@databricks.com/.bundle/my_default_python/dev/files/src/my_default_python_etl", + "run_as": [], + "run_as_user_name": "tester@databricks.com", + "schema": "tester", + "serverless": false, + "serverless_compute_id": null, + "state": "IDLE", + "storage": "dbfs:/pipelines/79fe8a2d-965e-74e8-79fe-8a2d965e74e9", + "tags": { + "dev": "tester" + }, + "target": null, + "timeouts": null, + "trigger": [], + "url": "[DATABRICKS_URL]/#joblist/pipelines/79fe8a2d-965e-74e8-79fe-8a2d965e74e9", + "usage_policy_id": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/grants/out.original_state.json b/acceptance/bundle/migrate/command/grants/out.original_state.json index ff5cdf4d58a..8aee4f3e101 100644 --- a/acceptance/bundle/migrate/command/grants/out.original_state.json +++ b/acceptance/bundle/migrate/command/grants/out.original_state.json @@ -3,60 +3,263 @@ "terraform_version": "1.5.5", "serial": 7, "lineage": "[UUID]", + "outputs": {}, "resources": [ { "mode": "managed", - "type": "databricks_schema", - "name": "my_schema", + "type": "databricks_grants", + "name": "registered_model_my_registered_model", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "main.schema_grants", "name": "schema_grants", "catalog_name": "main"}} + { + "schema_version": 0, + "attributes": { + "catalog": null, + "credential": null, + "external_location": null, + "foreign_connection": null, + "function": "main.schema_grants.mymodel", + "grant": [ + { + "principal": "deco-test-user@databricks.com", + "privileges": [ + "APPLY_TAG" + ] + } + ], + "id": "function/main.schema_grants.mymodel", + "mcp_service": null, + "metastore": null, + "model": null, + "model_provider_service": null, + "model_service": null, + "pipeline": null, + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "recipient": null, + "schema": null, + "secret": null, + "share": null, + "storage_credential": null, + "table": null, + "volume": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_registered_model.my_registered_model", + "databricks_schema.my_schema" + ] + } ] }, { "mode": "managed", - "type": "databricks_volume", - "name": "my_volume", + "type": "databricks_grants", + "name": "schema_my_schema", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "main.schema_grants.volume_name", "name": "volume_name", "catalog_name": "main", "schema_name": "schema_grants"}} + { + "schema_version": 0, + "attributes": { + "catalog": null, + "credential": null, + "external_location": null, + "foreign_connection": null, + "function": null, + "grant": [ + { + "principal": "deco-test-user@databricks.com", + "privileges": [ + "CREATE_TABLE", + "USE_SCHEMA" + ] + } + ], + "id": "schema/main.schema_grants", + "mcp_service": null, + "metastore": null, + "model": null, + "model_provider_service": null, + "model_service": null, + "pipeline": null, + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "recipient": null, + "schema": "main.schema_grants", + "secret": null, + "share": null, + "storage_credential": null, + "table": null, + "volume": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_schema.my_schema" + ] + } ] }, { "mode": "managed", - "type": "databricks_registered_model", - "name": "my_registered_model", + "type": "databricks_grants", + "name": "volume_my_volume", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "main.schema_grants.mymodel", "name": "mymodel", "catalog_name": "main", "schema_name": "schema_grants"}} + { + "schema_version": 0, + "attributes": { + "catalog": null, + "credential": null, + "external_location": null, + "foreign_connection": null, + "function": null, + "grant": [ + { + "principal": "deco-test-user@databricks.com", + "privileges": [ + "READ_VOLUME", + "WRITE_VOLUME" + ] + } + ], + "id": "volume/main.schema_grants.volume_name", + "mcp_service": null, + "metastore": null, + "model": null, + "model_provider_service": null, + "model_service": null, + "pipeline": null, + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "recipient": null, + "schema": null, + "secret": null, + "share": null, + "storage_credential": null, + "table": null, + "volume": "main.schema_grants.volume_name" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_schema.my_schema", + "databricks_volume.my_volume" + ] + } ] }, { "mode": "managed", - "type": "databricks_grants", - "name": "schema_my_schema", + "type": "databricks_registered_model", + "name": "my_registered_model", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "schema/main.schema_grants"}} + { + "schema_version": 0, + "attributes": { + "aliases": [], + "browse_only": false, + "catalog_name": "main", + "comment": "mycomment", + "created_at": [UNIX_TIME_MILLIS][0], + "created_by": "[USERNAME]", + "full_name": "main.schema_grants.mymodel", + "id": "main.schema_grants.mymodel", + "metastore_id": "[UUID]", + "name": "mymodel", + "owner": "[USERNAME]", + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "schema_name": "schema_grants", + "storage_location": null, + "updated_at": [UNIX_TIME_MILLIS][0], + "updated_by": "[USERNAME]" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_schema.my_schema" + ] + } ] }, { "mode": "managed", - "type": "databricks_grants", - "name": "volume_my_volume", + "type": "databricks_schema", + "name": "my_schema", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "volume/main.schema_grants.volume_name"}} + { + "schema_version": 0, + "attributes": { + "catalog_name": "main", + "comment": null, + "enable_predictive_optimization": "INHERIT", + "force_destroy": true, + "id": "main.schema_grants", + "metastore_id": "[UUID]", + "name": "schema_grants", + "owner": "[USERNAME]", + "properties": null, + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "schema_id": "[UUID]", + "storage_root": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } ] }, { "mode": "managed", - "type": "databricks_grants", - "name": "registered_model_my_registered_model", + "type": "databricks_volume", + "name": "my_volume", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "function/main.schema_grants.mymodel"}} + { + "schema_version": 0, + "attributes": { + "catalog_name": "main", + "comment": null, + "id": "main.schema_grants.volume_name", + "name": "volume_name", + "owner": "[USERNAME]", + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "schema_name": "schema_grants", + "storage_location": "s3://[METASTORE_NAME]/metastore/[UUID]/volumes/[UUID]", + "volume_path": "/Volumes/main/schema_grants/volume_name", + "volume_type": "MANAGED" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_schema.my_schema" + ] + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/grants/output.txt b/acceptance/bundle/migrate/command/grants/output.txt index a60965e5a34..8a89f3bf7df 100644 --- a/acceptance/bundle/migrate/command/grants/output.txt +++ b/acceptance/bundle/migrate/command/grants/output.txt @@ -1,5 +1,5 @@ ->>> seed_tfstate.py terraform.tfstate +>>> replay_tfstate.py terraform-requests.json terraform.tfstate >>> [CLI] bundle deployment migrate Success! Migrated 6 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json @@ -11,14 +11,17 @@ The state file is not synchronized to the workspace yet. To do that and finalize To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/default/resources.json and rename [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate.backup to [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate ->>> [CLI] bundle plan +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 6 unchanged + +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 6 unchanged >>> print_requests.py --get //unity-catalog/permissions ->>> [CLI] bundle deploy +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Files: 2 uploaded, 0 deleted +Files: 3 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 6 unchanged >>> print_requests.py --get //unity-catalog/permissions @@ -28,9 +31,9 @@ Resources: 0 created, 0 changed, 0 deleted, 6 unchanged Error: already using direct engine Details: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=9 lineage="[UUID]" ->>> [CLI] bundle debug states +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states [TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=9 lineage="[UUID]" ->>> [CLI] bundle debug states --force-pull +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states --force-pull resources.json: remote direct state serial=9 lineage="[UUID]" [TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=9 lineage="[UUID]" diff --git a/acceptance/bundle/migrate/command/grants/script b/acceptance/bundle/migrate/command/grants/script index 35033b34f0b..153af1a1aa9 100755 --- a/acceptance/bundle/migrate/command/grants/script +++ b/acceptance/bundle/migrate/command/grants/script @@ -1,20 +1,24 @@ export DATABRICKS_BUNDLE_ENGINE= -trace seed_tfstate.py terraform.tfstate +# Replay a prior terraform deployment (captured from a real terraform run) +trace replay_tfstate.py terraform-requests.json terraform.tfstate print_state.py > out.original_state.json trace $CLI bundle deployment migrate 2>&1 | contains.py 'Migrated 6 resources' print_state.py > out.new_state.json + rm "$OUT_REQUESTS" -trace $CLI bundle plan | contains.py "6 unchanged" +# Both DATABRICKS_BUNDLE_ENGINE=direct and DATABRICKS_BUNDLE_ENGINE= work +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "6 unchanged" +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan | contains.py "6 unchanged" trace print_requests.py --get //unity-catalog/permissions | contains.py 'engine/direct' > /dev/null -trace $CLI bundle deploy +trace DATABRICKS_BUNDLE_ENGINE="" $CLI bundle deploy trace print_requests.py --get //unity-catalog/permissions | jq '.headers["User-Agent"][0]' | contains.py 'engine/direct' > LOG.requests_deploy.txt title "Should show that it's already migrated" trace musterr $CLI bundle deployment migrate -trace $CLI bundle debug states -trace $CLI bundle debug states --force-pull +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states --force-pull rm "$OUT_REQUESTS" diff --git a/acceptance/bundle/migrate/command/grants/terraform-requests.json b/acceptance/bundle/migrate/command/grants/terraform-requests.json new file mode 100644 index 00000000000..49a06507ed8 --- /dev/null +++ b/acceptance/bundle/migrate/command/grants/terraform-requests.json @@ -0,0 +1,74 @@ +[ + { + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", + "body": { + "catalog_name": "main", + "name": "schema_grants" + } + }, + { + "method": "POST", + "path": "/api/2.1/unity-catalog/volumes", + "body": { + "catalog_name": "main", + "name": "volume_name", + "schema_name": "schema_grants", + "volume_type": "MANAGED" + } + }, + { + "method": "POST", + "path": "/api/2.1/unity-catalog/models", + "body": { + "catalog_name": "main", + "comment": "mycomment", + "name": "mymodel", + "schema_name": "schema_grants" + } + }, + { + "method": "PATCH", + "path": "/api/2.1/unity-catalog/permissions/schema/main.schema_grants", + "body": { + "changes": [ + { + "add": [ + "CREATE_TABLE", + "USE_SCHEMA" + ], + "principal": "deco-test-user@databricks.com" + } + ] + } + }, + { + "method": "PATCH", + "path": "/api/2.1/unity-catalog/permissions/volume/main.schema_grants.volume_name", + "body": { + "changes": [ + { + "add": [ + "READ_VOLUME", + "WRITE_VOLUME" + ], + "principal": "deco-test-user@databricks.com" + } + ] + } + }, + { + "method": "PATCH", + "path": "/api/2.1/unity-catalog/permissions/function/main.schema_grants.mymodel", + "body": { + "changes": [ + { + "add": [ + "APPLY_TAG" + ], + "principal": "deco-test-user@databricks.com" + } + ] + } + } +] diff --git a/acceptance/bundle/migrate/command/grants/terraform.tfstate b/acceptance/bundle/migrate/command/grants/terraform.tfstate index fc6ea0a27f1..14b1d3ed46f 100644 --- a/acceptance/bundle/migrate/command/grants/terraform.tfstate +++ b/acceptance/bundle/migrate/command/grants/terraform.tfstate @@ -2,61 +2,264 @@ "version": 4, "terraform_version": "1.5.5", "serial": 7, - "lineage": "a1b2c3d4-0000-4000-8000-000000000008", + "lineage": "fbb98d27-f582-d0ce-a226-c73269dcf1ea", + "outputs": {}, "resources": [ { "mode": "managed", - "type": "databricks_schema", - "name": "my_schema", + "type": "databricks_grants", + "name": "registered_model_my_registered_model", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.schemas.my_schema__", "name": "schema_grants", "catalog_name": "main"}} + { + "schema_version": 0, + "attributes": { + "catalog": null, + "credential": null, + "external_location": null, + "foreign_connection": null, + "function": "main.schema_grants.mymodel", + "grant": [ + { + "principal": "deco-test-user@databricks.com", + "privileges": [ + "APPLY_TAG" + ] + } + ], + "id": "function/main.schema_grants.mymodel", + "mcp_service": null, + "metastore": null, + "model": null, + "model_provider_service": null, + "model_service": null, + "pipeline": null, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "recipient": null, + "schema": null, + "secret": null, + "share": null, + "storage_credential": null, + "table": null, + "volume": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_registered_model.my_registered_model", + "databricks_schema.my_schema" + ] + } ] }, { "mode": "managed", - "type": "databricks_volume", - "name": "my_volume", + "type": "databricks_grants", + "name": "schema_my_schema", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.volumes.my_volume__", "name": "volume_name", "catalog_name": "main", "schema_name": "schema_grants"}} + { + "schema_version": 0, + "attributes": { + "catalog": null, + "credential": null, + "external_location": null, + "foreign_connection": null, + "function": null, + "grant": [ + { + "principal": "deco-test-user@databricks.com", + "privileges": [ + "CREATE_TABLE", + "USE_SCHEMA" + ] + } + ], + "id": "schema/main.schema_grants", + "mcp_service": null, + "metastore": null, + "model": null, + "model_provider_service": null, + "model_service": null, + "pipeline": null, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "recipient": null, + "schema": "main.schema_grants", + "secret": null, + "share": null, + "storage_credential": null, + "table": null, + "volume": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_schema.my_schema" + ] + } ] }, { "mode": "managed", - "type": "databricks_registered_model", - "name": "my_registered_model", + "type": "databricks_grants", + "name": "volume_my_volume", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.registered_models.my_registered_model__", "name": "mymodel", "catalog_name": "main", "schema_name": "schema_grants"}} + { + "schema_version": 0, + "attributes": { + "catalog": null, + "credential": null, + "external_location": null, + "foreign_connection": null, + "function": null, + "grant": [ + { + "principal": "deco-test-user@databricks.com", + "privileges": [ + "READ_VOLUME", + "WRITE_VOLUME" + ] + } + ], + "id": "volume/main.schema_grants.volume_name", + "mcp_service": null, + "metastore": null, + "model": null, + "model_provider_service": null, + "model_service": null, + "pipeline": null, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "recipient": null, + "schema": null, + "secret": null, + "share": null, + "storage_credential": null, + "table": null, + "volume": "main.schema_grants.volume_name" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_schema.my_schema", + "databricks_volume.my_volume" + ] + } ] }, { "mode": "managed", - "type": "databricks_grants", - "name": "schema_my_schema", + "type": "databricks_registered_model", + "name": "my_registered_model", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.schemas.my_schema.grants__"}} + { + "schema_version": 0, + "attributes": { + "aliases": [], + "browse_only": false, + "catalog_name": "main", + "comment": "mycomment", + "created_at": 1790614172511, + "created_by": "tester@databricks.com", + "full_name": "main.schema_grants.mymodel", + "id": "main.schema_grants.mymodel", + "metastore_id": "79fe8903-e604-bbe0-79fe-8903e604bfc8", + "name": "mymodel", + "owner": "tester@databricks.com", + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_name": "schema_grants", + "storage_location": null, + "updated_at": 1790614172511, + "updated_by": "tester@databricks.com" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_schema.my_schema" + ] + } ] }, { "mode": "managed", - "type": "databricks_grants", - "name": "volume_my_volume", + "type": "databricks_schema", + "name": "my_schema", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.volumes.my_volume.grants__"}} + { + "schema_version": 0, + "attributes": { + "catalog_name": "main", + "comment": null, + "enable_predictive_optimization": "INHERIT", + "force_destroy": true, + "id": "main.schema_grants", + "metastore_id": "120efa64-9b68-46ba-be38-f319458430d2", + "name": "schema_grants", + "owner": "tester@databricks.com", + "properties": null, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_id": "79fe8903-e536-c938-79fe-8903e536c939", + "storage_root": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } ] }, { "mode": "managed", - "type": "databricks_grants", - "name": "registered_model_my_registered_model", + "type": "databricks_volume", + "name": "my_volume", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.registered_models.my_registered_model.grants__"}} + { + "schema_version": 0, + "attributes": { + "catalog_name": "main", + "comment": null, + "id": "main.schema_grants.volume_name", + "name": "volume_name", + "owner": "tester@databricks.com", + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_name": "schema_grants", + "storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/120efa64-9b68-46ba-be38-f319458430d2/volumes/79fe8903-e5fc-b918-79fe-8903e5fcbd00", + "volume_path": "/Volumes/main/schema_grants/volume_name", + "volume_type": "MANAGED" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_schema.my_schema" + ] + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/profile_arg/output.txt b/acceptance/bundle/migrate/command/profile_arg/output.txt index 637b09ed7b1..dfa1e9b41dd 100644 --- a/acceptance/bundle/migrate/command/profile_arg/output.txt +++ b/acceptance/bundle/migrate/command/profile_arg/output.txt @@ -1,5 +1,5 @@ ->>> seed_tfstate.py terraform.tfstate +>>> replay_tfstate.py terraform-requests.json terraform.tfstate -t dev >>> [CLI] bundle deployment migrate -p non_existent321 Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json @@ -11,10 +11,10 @@ The state file is not synchronized to the workspace yet. To do that and finalize To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json and rename [TEST_TMP_DIR]/.databricks/bundle/dev/terraform/terraform.tfstate.backup to [TEST_TMP_DIR]/.databricks/bundle/dev/terraform/terraform.tfstate ->>> seed_tfstate.py terraform-prod.tfstate -t prod +>>> replay_tfstate.py terraform-prod-requests.json terraform-prod.tfstate -t prod >>> [CLI] bundle deployment migrate -p non_existent321 -t prod -Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/prod/resources.json +Success! Migrated 2 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/prod/resources.json Validate the migration by running "databricks bundle plan -t prod -p non_existent321", there should be no actions planned. diff --git a/acceptance/bundle/migrate/command/profile_arg/script b/acceptance/bundle/migrate/command/profile_arg/script index 31ad0a9df85..c8f07b32272 100755 --- a/acceptance/bundle/migrate/command/profile_arg/script +++ b/acceptance/bundle/migrate/command/profile_arg/script @@ -1,11 +1,10 @@ -export DATABRICKS_BUNDLE_ENGINE= - -# Seed a terraform deployment of the dev target, then migrate with a bogus profile. -trace seed_tfstate.py terraform.tfstate +# Replay a prior terraform deployment (a single job) +trace replay_tfstate.py terraform-requests.json terraform.tfstate -t dev # only interested in output here; for some reason in test env -p is not validated trace $CLI bundle deployment migrate -p non_existent321 -# Same for the prod target (a schema). -trace seed_tfstate.py terraform-prod.tfstate -t prod +# Replay a prior terraform deployment on a different target (a job and a schema) +trace replay_tfstate.py terraform-prod-requests.json terraform-prod.tfstate -t prod + trace $CLI bundle deployment migrate -p non_existent321 -t prod diff --git a/acceptance/bundle/migrate/command/profile_arg/terraform-prod-requests.json b/acceptance/bundle/migrate/command/profile_arg/terraform-prod-requests.json new file mode 100644 index 00000000000..c0de69c216b --- /dev/null +++ b/acceptance/bundle/migrate/command/profile_arg/terraform-prod-requests.json @@ -0,0 +1,36 @@ +[ + { + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", + "body": { + "catalog_name": "mycat", + "name": "myschema" + } + }, + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/prod/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Migration Job", + "queue": { + "enabled": true + }, + "tasks": [ + { + "notebook_task": { + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/prod/files/notebook", + "source": "WORKSPACE" + }, + "task_key": "main" + } + ] + } + } +] diff --git a/acceptance/bundle/migrate/command/profile_arg/terraform-prod.tfstate b/acceptance/bundle/migrate/command/profile_arg/terraform-prod.tfstate index 785e6c62cd5..6e0e3b0f53c 100644 --- a/acceptance/bundle/migrate/command/profile_arg/terraform-prod.tfstate +++ b/acceptance/bundle/migrate/command/profile_arg/terraform-prod.tfstate @@ -1,17 +1,200 @@ { "version": 4, "terraform_version": "1.5.5", - "serial": 1, - "lineage": "a1b2c3d4-0000-4000-8000-000000000006", + "serial": 3, + "lineage": "93b93ed4-821d-ea9e-0fea-e6ccc03c0316", + "outputs": {}, "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/prod/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790615136304176000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Migration Job", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [ + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "", + "library": [], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [ + { + "base_parameters": null, + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/prod/files/notebook", + "source": "WORKSPACE", + "warehouse_id": "" + } + ], + "notification_settings": [], + "pipeline_task": [], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "main", + "timeout_seconds": 0, + "webhook_notifications": [] + } + ], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790615136304176000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } + ] + }, { "mode": "managed", "type": "databricks_schema", "name": "test_schema", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.schemas.test_schema__", "name": "myschema", "catalog_name": "mycat"}} + { + "schema_version": 0, + "attributes": { + "catalog_name": "mycat", + "comment": null, + "enable_predictive_optimization": "INHERIT", + "force_destroy": true, + "id": "mycat.myschema", + "metastore_id": "120efa64-9b68-46ba-be38-f319458430d2", + "name": "myschema", + "owner": "tester@databricks.com", + "properties": null, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "schema_id": "79fe89e4-4a95-1948-79fe-89e44a951d30", + "storage_root": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/profile_arg/terraform-requests.json b/acceptance/bundle/migrate/command/profile_arg/terraform-requests.json new file mode 100644 index 00000000000..8dcc9089324 --- /dev/null +++ b/acceptance/bundle/migrate/command/profile_arg/terraform-requests.json @@ -0,0 +1,28 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/dev/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Test Migration Job", + "queue": { + "enabled": true + }, + "tasks": [ + { + "notebook_task": { + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/dev/files/notebook", + "source": "WORKSPACE" + }, + "task_key": "main" + } + ] + } + } +] diff --git a/acceptance/bundle/migrate/command/profile_arg/terraform.tfstate b/acceptance/bundle/migrate/command/profile_arg/terraform.tfstate index 58fb3601318..4746fa35538 100644 --- a/acceptance/bundle/migrate/command/profile_arg/terraform.tfstate +++ b/acceptance/bundle/migrate/command/profile_arg/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "a1b2c3d4-0000-4000-8000-000000000005", + "lineage": "25eb53a2-0b56-1698-68f5-f1eff6417572", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,8 +11,159 @@ "name": "test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Test Migration Job"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/dev/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790615135218268000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Test Migration Job", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [ + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "", + "library": [], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [ + { + "base_parameters": null, + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-basic-test/dev/files/notebook", + "source": "WORKSPACE", + "warehouse_id": "" + } + ], + "notification_settings": [], + "pipeline_task": [], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "main", + "timeout_seconds": 0, + "webhook_notifications": [] + } + ], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790615135218268000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/removed/output.txt b/acceptance/bundle/migrate/command/removed/output.txt index f530fea106a..948e659773e 100644 --- a/acceptance/bundle/migrate/command/removed/output.txt +++ b/acceptance/bundle/migrate/command/removed/output.txt @@ -1,5 +1,5 @@ ->>> seed_tfstate.py terraform.tfstate +>>> replay_tfstate.py terraform-requests.json terraform.tfstate >>> [CLI] bundle deployment migrate Success! Migrated 2 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json @@ -11,12 +11,12 @@ The state file is not synchronized to the workspace yet. To do that and finalize To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/default/resources.json and rename [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate.backup to [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate ->>> [CLI] bundle plan +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan delete jobs.job_b Plan: 0 to add, 0 to change, 1 to delete, 1 unchanged ->>> [CLI] bundle deploy +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-removed-test/default/files... Deleted jobs.job_b Files: 1 uploaded, 0 deleted @@ -36,5 +36,5 @@ Resources: 0 created, 0 changed, 1 deleted, 1 unchanged } } ->>> [CLI] bundle plan +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged diff --git a/acceptance/bundle/migrate/command/removed/script b/acceptance/bundle/migrate/command/removed/script index 9b0b737d904..01a5d745c31 100644 --- a/acceptance/bundle/migrate/command/removed/script +++ b/acceptance/bundle/migrate/command/removed/script @@ -1,7 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -# Seed a prior terraform deployment of both job_a and job_b. -trace seed_tfstate.py terraform.tfstate +# Replay a prior terraform deployment (both job_a and job_b) +trace replay_tfstate.py terraform-requests.json terraform.tfstate # Remove job_b from config without deploying the deletion grep -v job_b databricks.yml > databricks_tmp.yml && mv databricks_tmp.yml databricks.yml @@ -10,14 +10,14 @@ grep -v job_b databricks.yml > databricks_tmp.yml && mv databricks_tmp.yml datab trace $CLI bundle deployment migrate # After migration: plan shows job_b as "to delete" -trace $CLI bundle plan | contains.py "1 to delete" +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "1 to delete" # Deploy deletes job_b; verify via recorded requests rm "$OUT_REQUESTS" -trace $CLI bundle deploy +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy trace print_requests.py //jobs/delete # No further actions planned -trace $CLI bundle plan | contains.py "1 unchanged" +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan | contains.py "1 unchanged" rm "$OUT_REQUESTS" diff --git a/acceptance/bundle/migrate/command/removed/terraform-requests.json b/acceptance/bundle/migrate/command/removed/terraform-requests.json new file mode 100644 index 00000000000..20d41dc71cf --- /dev/null +++ b/acceptance/bundle/migrate/command/removed/terraform-requests.json @@ -0,0 +1,36 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-removed-test/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Job A", + "queue": { + "enabled": true + } + } + }, + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-removed-test/default/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Job B", + "queue": { + "enabled": true + } + } + } +] diff --git a/acceptance/bundle/migrate/command/removed/terraform.tfstate b/acceptance/bundle/migrate/command/removed/terraform.tfstate index c340aa5d9bb..6a8ad85c9a1 100644 --- a/acceptance/bundle/migrate/command/removed/terraform.tfstate +++ b/acceptance/bundle/migrate/command/removed/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "a1b2c3d4-0000-4000-8000-000000000002", + "lineage": "37f6c843-91a5-3d5c-457c-2c43d9630444", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,7 +11,98 @@ "name": "job_a", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.job_a__", "name": "Job A"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-removed-test/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614038615498000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Job A", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614038615498000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] }, { @@ -19,8 +111,100 @@ "name": "job_b", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.job_b__", "name": "Job B"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-removed-test/default/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614038615799000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Job B", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614038615799000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/runas/out.create_requests.json b/acceptance/bundle/migrate/command/runas/out.create_requests.json index ba069feb467..d34db87154f 100644 --- a/acceptance/bundle/migrate/command/runas/out.create_requests.json +++ b/acceptance/bundle/migrate/command/runas/out.create_requests.json @@ -1,7 +1,7 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_post cmd-exec-id/[UUID] interactive/none auth/pat" ] }, "method": "POST", @@ -32,7 +32,7 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_put cmd-exec-id/[UUID] interactive/none auth/pat" ] }, "method": "PUT", diff --git a/acceptance/bundle/migrate/command/runas/out.old_state.json b/acceptance/bundle/migrate/command/runas/out.old_state.json index 1f0b028d919..1fa79c0b405 100644 --- a/acceptance/bundle/migrate/command/runas/out.old_state.json +++ b/acceptance/bundle/migrate/command/runas/out.old_state.json @@ -3,24 +3,164 @@ "terraform_version": "1.5.5", "serial": 3, "lineage": "[UUID]", + "outputs": {}, "resources": [ { "mode": "managed", - "type": "databricks_pipeline", - "name": "foo", + "type": "databricks_permissions", + "name": "pipeline_foo", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "[UUID]", "name": "DABs Revenue Pipeline"}} + { + "schema_version": 0, + "attributes": { + "access_control": [ + { + "group_name": "", + "permission_level": "IS_OWNER", + "service_principal_name": "", + "user_name": "[USERNAME]" + }, + { + "group_name": "users", + "permission_level": "CAN_VIEW", + "service_principal_name": "", + "user_name": "" + } + ], + "alert_v2_id": null, + "app_name": null, + "authorization": null, + "cluster_id": null, + "cluster_policy_id": null, + "dashboard_id": null, + "database_instance_name": null, + "database_project_name": null, + "directory_id": null, + "directory_path": null, + "experiment_id": null, + "id": "/pipelines/[UUID]", + "instance_pool_id": null, + "job_id": null, + "knowledge_assistant_id": null, + "notebook_id": null, + "notebook_path": null, + "object_type": "pipelines", + "pipeline_id": "[UUID]", + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "registered_model_id": null, + "repo_id": null, + "repo_path": null, + "serving_endpoint_id": null, + "sql_alert_id": null, + "sql_dashboard_id": null, + "sql_endpoint_id": null, + "sql_query_id": null, + "supervisor_agent_id": null, + "vector_search_endpoint_id": null, + "workspace_file_id": null, + "workspace_file_path": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_pipeline.foo" + ] + } ] }, { "mode": "managed", - "type": "databricks_permissions", - "name": "pipeline_foo", + "type": "databricks_pipeline", + "name": "foo", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "/pipelines/[UUID]"}} + { + "schema_version": 0, + "attributes": { + "allow_duplicate_names": false, + "budget_policy_id": null, + "catalog": "main", + "cause": null, + "channel": "CURRENT", + "cluster": [], + "cluster_id": null, + "configuration": null, + "continuous": false, + "creator_user_name": "[USERNAME]", + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/dabs_revenue-[UNIQUE_NAME]/production/state/metadata.json", + "version_id": "" + } + ], + "development": false, + "edition": "ADVANCED", + "environment": [], + "event_log": [], + "expected_last_modified": 0, + "filters": [], + "gateway_definition": [], + "health": null, + "id": "[UUID]", + "ingestion_definition": [], + "last_modified": [UNIX_TIME_MILLIS], + "latest_updates": null, + "library": [ + { + "file": [], + "glob": [], + "jar": "", + "maven": [], + "notebook": [ + { + "path": "/Workspace/Users/[USERNAME]/.bundle/dabs_revenue-[UNIQUE_NAME]/production/files/sql" + } + ], + "whl": "" + } + ], + "name": "DABs Revenue Pipeline", + "notification": [], + "photon": false, + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "restart_window": [], + "root_path": null, + "run_as": [ + { + "group_name": "", + "service_principal_name": "[UUID]", + "user_name": "" + } + ], + "run_as_user_name": "[USERNAME]", + "schema": null, + "serverless": true, + "serverless_compute_id": null, + "state": "IDLE", + "storage": null, + "tags": null, + "target": "team_eng_deco", + "timeouts": null, + "trigger": [], + "url": "[DATABRICKS_URL]/#joblist/pipelines/[UUID]", + "usage_policy_id": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/runas/output.txt b/acceptance/bundle/migrate/command/runas/output.txt index c6beb8083e3..c956c03808b 100644 --- a/acceptance/bundle/migrate/command/runas/output.txt +++ b/acceptance/bundle/migrate/command/runas/output.txt @@ -1,5 +1,5 @@ ->>> seed_tfstate.py terraform.tfstate +>>> replay_tfstate.py terraform-requests.json terraform.tfstate -t production >>> print_requests.py //pipelines @@ -20,7 +20,7 @@ Notice: migrating your bundle to direct deployment engine (https://github.com/da >>> [CLI] pipelines get [UUID] ->>> [CLI] bundle deployment migrate +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deployment migrate Recommendation: permissions section should explicitly include the current deployment identity '[USERNAME]' or one of its groups If it is not included, CAN_MANAGE permissions are only applied if the present identity is used to deploy. @@ -44,7 +44,7 @@ To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/production/resou >>> print_state.py ->>> [CLI] bundle plan +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan Recommendation: permissions section should explicitly include the current deployment identity '[USERNAME]' or one of its groups If it is not included, CAN_MANAGE permissions are only applied if the present identity is used to deploy. @@ -59,7 +59,7 @@ See https://docs.databricks.com/dev-tools/bundles/permissions.html to learn more Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged ->>> [CLI] bundle plan -o json +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan -o json Recommendation: permissions section should explicitly include the current deployment identity '[USERNAME]' or one of its groups If it is not included, CAN_MANAGE permissions are only applied if the present identity is used to deploy. @@ -73,7 +73,7 @@ See https://docs.databricks.com/dev-tools/bundles/permissions.html to learn more in databricks.yml:5:3 ->>> [CLI] bundle destroy --auto-approve +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle destroy --auto-approve Recommendation: permissions section should explicitly include the current deployment identity '[USERNAME]' or one of its groups If it is not included, CAN_MANAGE permissions are only applied if the present identity is used to deploy. @@ -86,13 +86,4 @@ Consider using a adding a top-level permissions section such as the following: See https://docs.databricks.com/dev-tools/bundles/permissions.html to learn more about permission configuration. in databricks.yml:5:3 -The following resources will be deleted: - delete resources.pipelines.foo - -This action will result in the deletion of the following Lakeflow Spark Declarative Pipelines along with the -Streaming Tables (STs) and Materialized Views (MVs) managed by them. Set 'cascade_on_destroy: false' on a pipeline to retain datasets on pipeline deletion: - delete resources.pipelines.foo - -All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/dabs_revenue-[UNIQUE_NAME]/production - -Destroy: 1 deleted +No active deployment found to destroy! diff --git a/acceptance/bundle/migrate/command/runas/script b/acceptance/bundle/migrate/command/runas/script index 7659c426cd5..d90cf2235aa 100644 --- a/acceptance/bundle/migrate/command/runas/script +++ b/acceptance/bundle/migrate/command/runas/script @@ -3,24 +3,23 @@ if [ -z "${TEST_SP_APPLICATION_ID+x}" ]; then fi envsubst < databricks.yml.tmpl > databricks.yml -export DATABRICKS_BUNDLE_ENGINE= cleanup() { - trace $CLI bundle destroy --auto-approve + trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle destroy --auto-approve rm -f "$OUT_REQUESTS" } trap cleanup EXIT -# Seed a prior terraform deployment of the run-as pipeline. -trace seed_tfstate.py terraform.tfstate +# Replay a prior terraform deployment (a pipeline deployed with run_as) +trace replay_tfstate.py terraform-requests.json terraform.tfstate -t production trace print_requests.py //pipelines > out.create_requests.json trace print_state.py > out.old_state.json -pipeline_id=$($CLI bundle summary --output json | jq -r '.resources.pipelines.foo.id') +pipeline_id=$(DATABRICKS_BUNDLE_ENGINE= $CLI bundle summary --output json | jq -r '.resources.pipelines.foo.id') trace $CLI pipelines get $pipeline_id > out.pipelines_get.json -trace $CLI bundle deployment migrate +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle deployment migrate trace print_state.py > out.new_state.json -trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp > out.plan.json +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan -o json | nostamp > out.plan.json diff --git a/acceptance/bundle/migrate/command/runas/terraform-requests.json b/acceptance/bundle/migrate/command/runas/terraform-requests.json new file mode 100644 index 00000000000..09fefd90ab6 --- /dev/null +++ b/acceptance/bundle/migrate/command/runas/terraform-requests.json @@ -0,0 +1,56 @@ +[ + { + "method": "PUT", + "path": "/api/2.0/permissions/directories/8790615267072834001", + "body": { + "access_control_list": [ + { + "group_name": "users", + "permission_level": "CAN_READ" + } + ] + } + }, + { + "method": "POST", + "path": "/api/2.0/pipelines", + "body": { + "catalog": "main", + "channel": "CURRENT", + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/dabs_revenue-[UNIQUE_NAME]/production/state/metadata.json" + }, + "edition": "ADVANCED", + "libraries": [ + { + "notebook": { + "path": "/Workspace/Users/tester@databricks.com/.bundle/dabs_revenue-[UNIQUE_NAME]/production/files/sql" + } + } + ], + "name": "DABs Revenue Pipeline", + "run_as": { + "service_principal_name": "123b0db3-ba48-4e12-be3b-3b7898cdf000" + }, + "serverless": true, + "target": "team_eng_deco" + } + }, + { + "method": "PUT", + "path": "/api/2.0/permissions/pipelines/79fe8a02-f7fe-ced0-79fe-8a02f7fed2b8", + "body": { + "access_control_list": [ + { + "group_name": "users", + "permission_level": "CAN_VIEW" + }, + { + "permission_level": "IS_OWNER", + "user_name": "tester@databricks.com" + } + ] + } + } +] diff --git a/acceptance/bundle/migrate/command/runas/terraform.tfstate b/acceptance/bundle/migrate/command/runas/terraform.tfstate index ce4a94ffa49..8b3c0b6ec3d 100644 --- a/acceptance/bundle/migrate/command/runas/terraform.tfstate +++ b/acceptance/bundle/migrate/command/runas/terraform.tfstate @@ -2,25 +2,165 @@ "version": 4, "terraform_version": "1.5.5", "serial": 3, - "lineage": "a1b2c3d4-0000-4000-8000-00000000000c", + "lineage": "077aa86d-dff4-9481-ecbe-357801f46445", + "outputs": {}, "resources": [ { "mode": "managed", - "type": "databricks_pipeline", - "name": "foo", + "type": "databricks_permissions", + "name": "pipeline_foo", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.pipelines.foo__", "name": "DABs Revenue Pipeline"}} + { + "schema_version": 0, + "attributes": { + "access_control": [ + { + "group_name": "", + "permission_level": "IS_OWNER", + "service_principal_name": "", + "user_name": "tester@databricks.com" + }, + { + "group_name": "users", + "permission_level": "CAN_VIEW", + "service_principal_name": "", + "user_name": "" + } + ], + "alert_v2_id": null, + "app_name": null, + "authorization": null, + "cluster_id": null, + "cluster_policy_id": null, + "dashboard_id": null, + "database_instance_name": null, + "database_project_name": null, + "directory_id": null, + "directory_path": null, + "experiment_id": null, + "id": "/pipelines/79fe8a02-f7fe-ced0-79fe-8a02f7fed2b8", + "instance_pool_id": null, + "job_id": null, + "knowledge_assistant_id": null, + "notebook_id": null, + "notebook_path": null, + "object_type": "pipelines", + "pipeline_id": "79fe8a02-f7fe-ced0-79fe-8a02f7fed2b8", + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "registered_model_id": null, + "repo_id": null, + "repo_path": null, + "serving_endpoint_id": null, + "sql_alert_id": null, + "sql_dashboard_id": null, + "sql_endpoint_id": null, + "sql_query_id": null, + "supervisor_agent_id": null, + "vector_search_endpoint_id": null, + "workspace_file_id": null, + "workspace_file_path": null + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "databricks_pipeline.foo" + ] + } ] }, { "mode": "managed", - "type": "databricks_permissions", - "name": "pipeline_foo", + "type": "databricks_pipeline", + "name": "foo", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.pipelines.foo.permissions__"}} + { + "schema_version": 0, + "attributes": { + "allow_duplicate_names": false, + "budget_policy_id": null, + "catalog": "main", + "cause": null, + "channel": "CURRENT", + "cluster": [], + "cluster_id": null, + "configuration": null, + "continuous": false, + "creator_user_name": "tester@databricks.com", + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/dabs_revenue-[UNIQUE_NAME]/production/state/metadata.json", + "version_id": "" + } + ], + "development": false, + "edition": "ADVANCED", + "environment": [], + "event_log": [], + "expected_last_modified": 0, + "filters": [], + "gateway_definition": [], + "health": null, + "id": "79fe8a02-f7fe-ced0-79fe-8a02f7fed2b8", + "ingestion_definition": [], + "last_modified": 1790615268029, + "latest_updates": null, + "library": [ + { + "file": [], + "glob": [], + "jar": "", + "maven": [], + "notebook": [ + { + "path": "/Workspace/Users/tester@databricks.com/.bundle/dabs_revenue-[UNIQUE_NAME]/production/files/sql" + } + ], + "whl": "" + } + ], + "name": "DABs Revenue Pipeline", + "notification": [], + "photon": false, + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "restart_window": [], + "root_path": null, + "run_as": [ + { + "group_name": "", + "service_principal_name": "123b0db3-ba48-4e12-be3b-3b7898cdf000", + "user_name": "" + } + ], + "run_as_user_name": "tester@databricks.com", + "schema": null, + "serverless": true, + "serverless_compute_id": null, + "state": "IDLE", + "storage": null, + "tags": null, + "target": "team_eng_deco", + "timeouts": null, + "trigger": [], + "url": "[DATABRICKS_URL]/#joblist/pipelines/79fe8a02-f7fe-ced0-79fe-8a02f7fed2b8", + "usage_policy_id": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19" + } ] } - ] + ], + "check_results": null } diff --git a/acceptance/bundle/migrate/command/var_arg/output.txt b/acceptance/bundle/migrate/command/var_arg/output.txt index 5817be84a28..dbf8e7a3b2d 100644 --- a/acceptance/bundle/migrate/command/var_arg/output.txt +++ b/acceptance/bundle/migrate/command/var_arg/output.txt @@ -1,5 +1,5 @@ ->>> seed_tfstate.py terraform.tfstate --var=job_name=Custom Job Name +>>> replay_tfstate.py terraform-requests.json terraform.tfstate -t dev >>> [CLI] bundle deployment migrate --var=job_name=Custom Job Name Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json @@ -14,18 +14,13 @@ To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/dev/resources.js >>> print_state.py "Custom Job Name" ->>> [CLI] bundle plan --var=job_name=Custom Job Name +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan --var=job_name=Custom Job Name Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged ->>> [CLI] bundle destroy --var=job_name=Custom Job Name --auto-approve -The following resources will be deleted: - delete resources.jobs.test_job +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle destroy --var=job_name=Custom Job Name --auto-approve +No active deployment found to destroy! -All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/migrate-var-test/dev - -Destroy: 1 deleted - ->>> seed_tfstate.py terraform.tfstate --var job_name=Custom Job Name +>>> replay_tfstate.py terraform-2-requests.json terraform-2.tfstate -t dev >>> [CLI] bundle deployment migrate --var job_name=Custom Job Name Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json @@ -40,13 +35,8 @@ To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/dev/resources.js >>> print_state.py "Custom Job Name" ->>> [CLI] bundle plan --var job_name=Custom Job Name +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan --var job_name=Custom Job Name Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged ->>> [CLI] bundle destroy --var=job_name=Custom Job Name --auto-approve -The following resources will be deleted: - delete resources.jobs.test_job - -All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/migrate-var-test/dev - -Destroy: 1 deleted +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle destroy --var=job_name=Custom Job Name --auto-approve +No active deployment found to destroy! diff --git a/acceptance/bundle/migrate/command/var_arg/script b/acceptance/bundle/migrate/command/var_arg/script index f0aaa83dda5..b94521c7899 100644 --- a/acceptance/bundle/migrate/command/var_arg/script +++ b/acceptance/bundle/migrate/command/var_arg/script @@ -1,21 +1,16 @@ -export DATABRICKS_BUNDLE_ENGINE= - -# seed_tfstate.py consumes (deletes) the fixture, and the second block re-seeds, so keep a copy. -FIXTURE=$(cat terraform.tfstate) - -# Seed a terraform deployment made with a variable, then migrate with the same '--var=X'. -trace seed_tfstate.py terraform.tfstate --var="job_name=Custom Job Name" +# Replay a prior terraform deployment (a job named via --var) +trace replay_tfstate.py terraform-requests.json terraform.tfstate -t dev trace $CLI bundle deployment migrate --var="job_name=Custom Job Name" 2>&1 | contains.py 'Migrated 1 resources' trace print_state.py | jq '.state."resources.jobs.test_job".state.name' -trace $CLI bundle plan --var="job_name=Custom Job Name" | contains.py "1 unchanged" -trace $CLI bundle destroy --var="job_name=Custom Job Name" --auto-approve +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan --var="job_name=Custom Job Name" | contains.py "1 unchanged" +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle destroy --var="job_name=Custom Job Name" --auto-approve # Try different syntax, '--var X', instead of '--var=X' rm -fr .databricks -echo "$FIXTURE" > terraform.tfstate -trace seed_tfstate.py terraform.tfstate --var "job_name=Custom Job Name" +# Replay the same deployment again (the second fixture copy; replay consumes its inputs) +trace replay_tfstate.py terraform-2-requests.json terraform-2.tfstate -t dev trace $CLI bundle deployment migrate --var "job_name=Custom Job Name" 2>&1 | contains.py 'Migrated 1 resources' trace print_state.py | jq '.state."resources.jobs.test_job".state.name' -trace $CLI bundle plan --var "job_name=Custom Job Name" | contains.py "1 unchanged" -trace $CLI bundle destroy --var="job_name=Custom Job Name" --auto-approve +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan --var "job_name=Custom Job Name" | contains.py "1 unchanged" +trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle destroy --var="job_name=Custom Job Name" --auto-approve diff --git a/acceptance/bundle/migrate/command/var_arg/terraform-2-requests.json b/acceptance/bundle/migrate/command/var_arg/terraform-2-requests.json new file mode 100644 index 00000000000..6fb9f2341c4 --- /dev/null +++ b/acceptance/bundle/migrate/command/var_arg/terraform-2-requests.json @@ -0,0 +1,28 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-var-test/dev/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Custom Job Name", + "queue": { + "enabled": true + }, + "tasks": [ + { + "notebook_task": { + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-var-test/dev/files/notebook", + "source": "WORKSPACE" + }, + "task_key": "main" + } + ] + } + } +] diff --git a/acceptance/bundle/migrate/command/var_arg/terraform-2.tfstate b/acceptance/bundle/migrate/command/var_arg/terraform-2.tfstate new file mode 100644 index 00000000000..434dbe1f911 --- /dev/null +++ b/acceptance/bundle/migrate/command/var_arg/terraform-2.tfstate @@ -0,0 +1,169 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "72aa60ee-0151-f001-7cd5-ea9bace71dc7", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "test_job", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-var-test/dev/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614985789453000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Custom Job Name", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [ + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "", + "library": [], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [ + { + "base_parameters": null, + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-var-test/dev/files/notebook", + "source": "WORKSPACE", + "warehouse_id": "" + } + ], + "notification_settings": [], + "pipeline_task": [], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "main", + "timeout_seconds": 0, + "webhook_notifications": [] + } + ], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614985789453000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } + ] + } + ], + "check_results": null +} diff --git a/acceptance/bundle/migrate/command/var_arg/terraform-requests.json b/acceptance/bundle/migrate/command/var_arg/terraform-requests.json new file mode 100644 index 00000000000..6fb9f2341c4 --- /dev/null +++ b/acceptance/bundle/migrate/command/var_arg/terraform-requests.json @@ -0,0 +1,28 @@ +[ + { + "method": "POST", + "path": "/api/2.2/jobs/create", + "body": { + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-var-test/dev/state/metadata.json" + }, + "edit_mode": "UI_LOCKED", + "format": "MULTI_TASK", + "max_concurrent_runs": 1, + "name": "Custom Job Name", + "queue": { + "enabled": true + }, + "tasks": [ + { + "notebook_task": { + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-var-test/dev/files/notebook", + "source": "WORKSPACE" + }, + "task_key": "main" + } + ] + } + } +] diff --git a/acceptance/bundle/migrate/command/var_arg/terraform.tfstate b/acceptance/bundle/migrate/command/var_arg/terraform.tfstate index 6ade3b70273..434dbe1f911 100644 --- a/acceptance/bundle/migrate/command/var_arg/terraform.tfstate +++ b/acceptance/bundle/migrate/command/var_arg/terraform.tfstate @@ -2,7 +2,8 @@ "version": 4, "terraform_version": "1.5.5", "serial": 1, - "lineage": "a1b2c3d4-0000-4000-8000-000000000004", + "lineage": "72aa60ee-0151-f001-7cd5-ea9bace71dc7", + "outputs": {}, "resources": [ { "mode": "managed", @@ -10,8 +11,159 @@ "name": "test_job", "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", "instances": [ - {"schema_version": 0, "attributes": {"id": "__ID_resources.jobs.test_job__", "name": "Custom Job Name"}} + { + "schema_version": 2, + "attributes": { + "always_running": false, + "budget_policy_id": null, + "continuous": [], + "control_run_state": false, + "dbt_task": [], + "deployment": [ + { + "deployment_id": "", + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-var-test/dev/state/metadata.json", + "version_id": "" + } + ], + "description": null, + "edit_mode": "UI_LOCKED", + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment": [], + "existing_cluster_id": null, + "format": "MULTI_TASK", + "git_source": [], + "health": [], + "id": "8790614985789453000", + "job_cluster": [], + "library": [], + "max_concurrent_runs": 1, + "max_retries": 0, + "min_retry_interval_millis": 0, + "name": "Custom Job Name", + "new_cluster": [], + "notebook_task": [], + "notification_settings": [], + "parameter": [], + "parent_path": null, + "performance_target": null, + "pipeline_task": [], + "provider_config": [ + { + "workspace_id": "900800700600" + } + ], + "python_wheel_task": [], + "queue": [ + { + "enabled": true + } + ], + "retry_on_timeout": false, + "run_as": [ + { + "group_name": "", + "service_principal_name": "", + "user_name": "tester@databricks.com" + } + ], + "run_job_task": [], + "schedule": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "tags": null, + "task": [ + { + "ai_runtime_task": [], + "alert_task": [], + "clean_rooms_notebook_task": [], + "compute": [], + "condition_task": [], + "dashboard_task": [], + "dbt_cloud_task": [], + "dbt_platform_task": [], + "dbt_task": [], + "depends_on": [], + "description": "", + "disable_auto_optimization": false, + "disabled": false, + "email_notifications": [ + { + "no_alert_for_skipped_runs": false, + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ], + "environment_key": "", + "existing_cluster_id": "", + "for_each_task": [], + "gen_ai_compute_task": [], + "health": [], + "job_cluster_key": "", + "library": [], + "max_retries": 0, + "min_retry_interval_millis": 0, + "new_cluster": [], + "notebook_task": [ + { + "base_parameters": null, + "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-var-test/dev/files/notebook", + "source": "WORKSPACE", + "warehouse_id": "" + } + ], + "notification_settings": [], + "pipeline_task": [], + "power_bi_task": [], + "python_operator_task": [], + "python_wheel_task": [], + "retry_on_timeout": false, + "run_if": "ALL_SUCCESS", + "run_job_task": [], + "spark_jar_task": [], + "spark_python_task": [], + "spark_submit_task": [], + "sql_task": [], + "task_key": "main", + "timeout_seconds": 0, + "webhook_notifications": [] + } + ], + "timeout_seconds": 0, + "timeouts": null, + "trigger": [], + "triggers": [], + "url": "[DATABRICKS_URL]/#job/8790614985789453000", + "usage_policy_id": null, + "webhook_notifications": [ + { + "on_duration_warning_threshold_exceeded": [], + "on_failure": [], + "on_start": [], + "on_streaming_backlog_exceeded": [], + "on_success": [] + } + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" + } ] } - ] + ], + "check_results": null } From bdc34cfc5dc5e34b786a7b92a51ef2cd8c243a01 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 29 Sep 2026 12:09:03 +0200 Subject: [PATCH 10/15] acceptance: replay resource requests directly, not via `databricks api` `databricks api --output json` decodes the response into Go's `any`, so JSON numbers come back as float64 and a freshly minted id above 2^53 (the test server mints ~8.7e18) loses its low digits. replay_tfstate.py read the minted id from that output, so it recorded a rounded id, wrote it into the tfstate, and the post-migration plan/deploy then looked the resource up by an id the backend never had - re-creating a "Migrated" resource instead of leaving it unchanged. It only bit under load (whether rounding changes the value depends on the id's low bits), so it surfaced as flaky migrate tests on the busy CI runners. Talk to the workspace directly with urllib instead: Python keeps the ids exact. Use a stable User-Agent so a test that records the replayed requests does not pin the Python version, and bypass the proxy (these tests only hit the local server). Also match a create to its tfstate resource by any identifying field, not just `name`: dashboards use `display_name`, so their id was never remapped and the follow-up publish call hit a stale id and failed - the dashboards test now performs a real migration instead of capturing that failure. Co-authored-by: Isaac --- acceptance/bin/replay_tfstate.py | 57 +++++++++++----- .../command/dashboards/out.new_state.json | 20 ++++++ .../dashboards/out.original_state.json | 47 ++++++++++++++ .../dashboards/out.plan_after_migrate.json | 65 +++++++++++++++++++ .../migrate/command/dashboards/output.txt | 39 ++++++++++- .../command/runas/out.create_requests.json | 4 +- 6 files changed, 210 insertions(+), 22 deletions(-) create mode 100644 acceptance/bundle/migrate/command/dashboards/out.new_state.json create mode 100644 acceptance/bundle/migrate/command/dashboards/out.original_state.json create mode 100644 acceptance/bundle/migrate/command/dashboards/out.plan_after_migrate.json diff --git a/acceptance/bin/replay_tfstate.py b/acceptance/bin/replay_tfstate.py index df3d8a96137..fb0e217389f 100755 --- a/acceptance/bin/replay_tfstate.py +++ b/acceptance/bin/replay_tfstate.py @@ -9,8 +9,8 @@ backed by real (terraform-shaped) resources. The requests carry the recorded ids; the backend mints fresh ones on replay. We learn each mapping -from the create responses (matching a create to its tfstate resource by name) and rewrite it into -every later request and into the tfstate, so cross-resource references stay consistent. +from the create responses (matching a create to its tfstate resource by an identifying name) and +rewrite it into every later request and into the tfstate, so cross-resource references stay consistent. Usage: replay_tfstate.py REQUESTS.json TFSTATE.json [-t TARGET] """ @@ -19,17 +19,28 @@ import json import os import re -import subprocess import sys +import urllib.error +import urllib.request -CLI = os.environ["CLI"] HOST = os.environ.get("DATABRICKS_HOST", "").rstrip("/") +TOKEN = os.environ.get("DATABRICKS_TOKEN", "") UNIQUE_NAME = os.environ.get("UNIQUE_NAME", "") +# Talk to the (local) workspace directly rather than via `databricks api`: the CLI renders responses +# through Go's `any`, which decodes JSON numbers as float64 and silently mangles the low digits of a +# freshly minted id (they exceed 2^53), so the id we'd record would not match the one the backend +# stored. Python's json keeps ids exact. Bypass any proxy: these tests only hit the local server. +_opener = urllib.request.build_opener(urllib.request.ProxyHandler({})) + # Per resource: which response field carries the new id. Terraform's tfstate stores the same value # as the resource's `id`, keyed here by the create path so we can match a create to its tfstate entry. ID_FIELDS = ["job_id", "pipeline_id", "dashboard_id", "experiment_id", "full_name", "id", "name"] +# A create request is matched to its tfstate resource by a human-supplied identifying field; different +# resource types name it differently (jobs/pipelines use `name`, dashboards use `display_name`, …). +NAME_FIELDS = ["name", "display_name", "full_name"] + # A backend-minted value that another resource may reference (e.g. a volume's storage_location, which # a pipeline tags). We remap these recorded->minted just like ids: a UUID, an s3-style path (which # embeds a UUID), or a long numeric id. Timestamps (13-digit millis) are shorter and excluded. @@ -48,13 +59,19 @@ def apply_map(text, id_map): def api(method, path, body): - cmd = [CLI, "api", method.lower(), path, "--output", "json"] - if body is not None: - cmd += ["--json", json.dumps(body)] - r = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8") - if r.returncode != 0: - sys.exit(f"replay_tfstate.py: {method} {path} failed:\n{r.stdout}\n{r.stderr}") - return json.loads(r.stdout) if r.stdout.strip() else {} + data = json.dumps(body).encode() if body is not None else None + req = urllib.request.Request(HOST + path, data=data, method=method.upper()) + req.add_header("Authorization", "Bearer " + TOKEN) + # Stable UA so tests that record the replayed requests don't pin the Python version. + req.add_header("User-Agent", "replay_tfstate.py") + if data is not None: + req.add_header("Content-Type", "application/json") + try: + with _opener.open(req) as resp: + text = resp.read().decode() + except urllib.error.HTTPError as e: + sys.exit(f"replay_tfstate.py: {method} {path} failed: HTTP {e.code}\n{e.read().decode()}") + return json.loads(text) if text.strip() else {} def main(): @@ -83,14 +100,17 @@ def main(): os.remove(args.requests) os.remove(args.tfstate) - # name -> recorded resource attributes, from the tfstate managed resources. + # identifying name -> recorded resource attributes, from the tfstate managed resources. name_to_attrs = {} for r in tfstate["resources"]: if r.get("mode") != "managed": continue attrs = r["instances"][0]["attributes"] - if "name" in attrs and "id" in attrs: - name_to_attrs[attrs["name"]] = attrs + if "id" not in attrs: + continue + for nf in NAME_FIELDS: + if attrs.get(nf): + name_to_attrs[str(attrs[nf])] = attrs id_map = {} for req in requests: @@ -100,10 +120,13 @@ def main(): body = json.loads(apply_map(json.dumps(body), id_map)) resp = api(req["method"], path, body) - # A create (POST that returns a new id) whose config name matches a tfstate resource: + # A create (POST that returns a new id) whose identifying name matches a tfstate resource: # map its recorded id to the freshly minted one. - if req["method"] == "POST" and isinstance(body, dict) and body.get("name") in name_to_attrs: - attrs = name_to_attrs[body["name"]] + create_name = None + if isinstance(body, dict): + create_name = next((str(body[nf]) for nf in NAME_FIELDS if body.get(nf)), None) + if req["method"] == "POST" and create_name in name_to_attrs: + attrs = name_to_attrs[create_name] new_id = next((str(resp[f]) for f in ID_FIELDS if f in resp), None) if new_id is None: sys.exit(f"replay_tfstate.py: no id in response to {req['path']}: {resp}") diff --git a/acceptance/bundle/migrate/command/dashboards/out.new_state.json b/acceptance/bundle/migrate/command/dashboards/out.new_state.json new file mode 100644 index 00000000000..c1bdc4c7b78 --- /dev/null +++ b/acceptance/bundle/migrate/command/dashboards/out.new_state.json @@ -0,0 +1,20 @@ +{ + "state_version": 3, + "cli_version": "[CLI_VERSION]", + "lineage": "[UUID]", + "serial": 3, + "state": { + "resources.dashboards.dashboard1": { + "__id__": "[DASHBOARD1_ID]", + "state": { + "display_name": "my dashboard", + "embed_credentials": true, + "etag": "[NUMID]", + "parent_path": "/Workspace/Users/[USERNAME]", + "published": true, + "serialized_dashboard": "sha256:[HASH]", + "warehouse_id": "123456" + } + } + } +} diff --git a/acceptance/bundle/migrate/command/dashboards/out.original_state.json b/acceptance/bundle/migrate/command/dashboards/out.original_state.json new file mode 100644 index 00000000000..588895fb3c5 --- /dev/null +++ b/acceptance/bundle/migrate/command/dashboards/out.original_state.json @@ -0,0 +1,47 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "[UUID]", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_dashboard", + "name": "dashboard1", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "create_time": "[TIMESTAMP]", + "dashboard_change_detected": false, + "dashboard_id": "[DASHBOARD1_ID]", + "dataset_catalog": null, + "dataset_schema": null, + "display_name": "my dashboard", + "embed_credentials": true, + "etag": "[NUMID]", + "file_path": null, + "id": "[DASHBOARD1_ID]", + "lifecycle_state": "ACTIVE", + "md5": "b4ab6aee48485b0b5e980761d3efe936", + "parent_path": "/Users/[USERNAME]", + "path": "/Users/[USERNAME]/my dashboard.lvdash.json", + "provider_config": [ + { + "workspace_id": "[NUMID]" + } + ], + "serialized_dashboard": "{\"pages\":[{\"displayName\":\"Dashboard test bundle-deploy-dashboard\",\"name\":\"02724bf2\",\"pageType\":\"PAGE_TYPE_CANVAS\"}]}\n", + "update_time": "[TIMESTAMP]", + "warehouse_id": "123456" + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + } + ], + "check_results": null +} diff --git a/acceptance/bundle/migrate/command/dashboards/out.plan_after_migrate.json b/acceptance/bundle/migrate/command/dashboards/out.plan_after_migrate.json new file mode 100644 index 00000000000..37124a4c407 --- /dev/null +++ b/acceptance/bundle/migrate/command/dashboards/out.plan_after_migrate.json @@ -0,0 +1,65 @@ +{ + "plan_version": [PLAN_VERSION], + "cli_version": "[CLI_VERSION]", + "lineage": "[UUID]", + "serial": 3, + "plan": { + "resources.dashboards.dashboard1": { + "action": "skip", + "remote_state": { + "create_time": "[TIMESTAMP]", + "dashboard_id": "[DASHBOARD1_ID]", + "display_name": "my dashboard", + "embed_credentials": true, + "etag": "[NUMID]", + "lifecycle_state": "ACTIVE", + "parent_path": "/Workspace/Users/[USERNAME]", + "path": "/Users/[USERNAME]/my dashboard.lvdash.json", + "published": true, + "serialized_dashboard": "{\"pages\":[{\"displayName\":\"Dashboard test bundle-deploy-dashboard\",\"name\":\"02724bf2\",\"pageType\":\"PAGE_TYPE_CANVAS\"}]}\n", + "update_time": "[TIMESTAMP]", + "warehouse_id": "123456" + }, + "changes": { + "create_time": { + "action": "skip", + "reason": "spec:output_only", + "remote": "[TIMESTAMP]" + }, + "dashboard_id": { + "action": "skip", + "reason": "spec:output_only", + "remote": "[DASHBOARD1_ID]" + }, + "etag": { + "action": "skip", + "reason": "custom", + "old": "[NUMID]", + "remote": "[NUMID]" + }, + "lifecycle_state": { + "action": "skip", + "reason": "spec:output_only", + "remote": "ACTIVE" + }, + "path": { + "action": "skip", + "reason": "spec:output_only", + "remote": "/Users/[USERNAME]/my dashboard.lvdash.json" + }, + "serialized_dashboard": { + "action": "skip", + "reason": "etag_based", + "old": "sha256:[HASH][0]", + "new": "sha256:[HASH][0]", + "remote": "sha256:[HASH][1]" + }, + "update_time": { + "action": "skip", + "reason": "spec:output_only", + "remote": "[TIMESTAMP]" + } + } + } + } +} diff --git a/acceptance/bundle/migrate/command/dashboards/output.txt b/acceptance/bundle/migrate/command/dashboards/output.txt index 813002efe4a..51be029784b 100644 --- a/acceptance/bundle/migrate/command/dashboards/output.txt +++ b/acceptance/bundle/migrate/command/dashboards/output.txt @@ -1,8 +1,41 @@ >>> replay_tfstate.py terraform-requests.json terraform.tfstate -replay_tfstate.py: POST /api/2.0/lakeview/dashboards/21e426a8882f7de9a42b984dbff36469/published failed: -Error: Not Found +>>> [CLI] bundle deployment migrate +Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json +Validate the migration by running "databricks bundle plan", there should be no actions planned. -Exit code: 1 +The state file is not synchronized to the workspace yet. To do that and finalize the migration, run "bundle deploy". + +To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/default/resources.json and rename [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate.backup to [TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate + + +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged + +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged + +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan -o json + +>>> print_requests.py --get //dashboards + +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deploy --auto-approve +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Files: 5 uploaded, 0 deleted +Resources: 0 created, 0 changed, 0 deleted, 1 unchanged + +>>> print_requests.py --get //dashboards + +=== Should show that it's already migrated +>>> musterr [CLI] bundle deployment migrate +Error: already using direct engine +Details: [TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=3 lineage="[UUID]" + +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states +[TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=3 lineage="[UUID]" + +>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states --force-pull +resources.json: remote direct state serial=3 lineage="[UUID]" +[TEST_TMP_DIR]/.databricks/bundle/default/resources.json: local direct state serial=3 lineage="[UUID]" diff --git a/acceptance/bundle/migrate/command/runas/out.create_requests.json b/acceptance/bundle/migrate/command/runas/out.create_requests.json index d34db87154f..abeb78d7d35 100644 --- a/acceptance/bundle/migrate/command/runas/out.create_requests.json +++ b/acceptance/bundle/migrate/command/runas/out.create_requests.json @@ -1,7 +1,7 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_post cmd-exec-id/[UUID] interactive/none auth/pat" + "replay_tfstate.py" ] }, "method": "POST", @@ -32,7 +32,7 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/api_put cmd-exec-id/[UUID] interactive/none auth/pat" + "replay_tfstate.py" ] }, "method": "PUT", From 5616dda9e6a35eed053f506075ca53d8dfce78c1 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 29 Sep 2026 12:53:41 +0200 Subject: [PATCH 11/15] acceptance: replay pushes the remote terraform state too A real terraform deploy leaves its state both on disk and in the workspace. replay_tfstate.py wrote only the local copy, so a follow-up migrate had no remote state to back up and tests that inspect the remote state dir saw it empty - missing the terraform.tfstate.backup the migration produces (this had already been silently dropped from the artifacts and apply-failure tests). Push the remote copy from replay_tfstate.py itself rather than via a separate push_remote_tfstate.py that every test had to remember to call after replay. Removes push_remote_tfstate.py and its six call sites; the migrate tests that inspect the remote state dir now show the terraform.tfstate a real deploy would have left. Co-authored-by: Isaac --- acceptance/bin/push_remote_tfstate.py | 46 ------------------- acceptance/bin/replay_tfstate.py | 20 +++++++- .../migrate/auto/apply-failure/output.txt | 2 + .../bundle/migrate/auto/artifacts/output.txt | 1 + .../bundle/migrate/auto/destroy/output.txt | 20 +++++++- .../migrate/auto/direct-only/output.txt | 30 +++++++++++- .../migrate/auto/dms-migration/output.txt | 2 - .../bundle/migrate/auto/dms-migration/script | 3 -- .../migrate/auto/plan-missing/output.txt | 2 - .../bundle/migrate/auto/plan-missing/script | 3 -- .../migrate/auto/push-failure/output.txt | 2 - .../bundle/migrate/auto/push-failure/script | 3 -- .../migrate/auto/run-no-commit/output.txt | 5 +- .../auto/schema-storage-change/output.txt | 1 + .../migrate/auto/tfbackup-failure/output.txt | 2 - .../migrate/auto/tfbackup-failure/script | 4 -- .../bundle/migrate/command/basic/output.txt | 1 + .../bundle/migrate/command/runas/output.txt | 11 ++++- .../bundle/migrate/command/var_arg/output.txt | 14 +++++- 19 files changed, 94 insertions(+), 78 deletions(-) delete mode 100755 acceptance/bin/push_remote_tfstate.py diff --git a/acceptance/bin/push_remote_tfstate.py b/acceptance/bin/push_remote_tfstate.py deleted file mode 100755 index c5fe6f36186..00000000000 --- a/acceptance/bin/push_remote_tfstate.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python3 -""" -Push the replayed terraform.tfstate to the bundle's remote state directory, standing in for the -remote state a real terraform deploy leaves behind. - -replay_tfstate.py reconstructs the backend resources and writes the LOCAL terraform.tfstate, but a -real terraform deploy also pushes that state to the workspace. A migrate step that inspects the -remote state dir (workspace list) or backs it up / deletes it (the tfstate-backup path) needs the -remote copy to exist, so those tests run this right after replay_tfstate.py. Tests that only look -at the local state (or use `bundle debug states`) do not need it. - -Usage: push_remote_tfstate.py [-t TARGET] -""" - -import argparse -import os -import subprocess -import sys - -import print_state - -CLI = os.environ["CLI"] - - -def run(*args): - r = subprocess.run([CLI, *args], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8") - if r.returncode != 0: - sys.exit(f"push_remote_tfstate.py: {' '.join(args)} failed:\n{r.stdout}") - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument("-t", "--target", default="default") - args = parser.parse_args() - - local = print_state.get_state_file(args.target, False) - state_dir = print_state.get_remote_state_path(args.target) - - # workspace import does not create parents (see the fake server's requireParentDirectory), so - # mkdirs the state dir first, mirroring how the real deploy pushes state. - run("workspace", "mkdirs", state_dir) - run("workspace", "import", f"{state_dir}/terraform.tfstate", "--file", local, "--format", "AUTO", "--overwrite") - - -if __name__ == "__main__": - main() diff --git a/acceptance/bin/replay_tfstate.py b/acceptance/bin/replay_tfstate.py index fb0e217389f..fbb813c10ce 100755 --- a/acceptance/bin/replay_tfstate.py +++ b/acceptance/bin/replay_tfstate.py @@ -19,10 +19,14 @@ import json import os import re +import subprocess import sys import urllib.error import urllib.request +import print_state + +CLI = os.environ["CLI"] HOST = os.environ.get("DATABRICKS_HOST", "").rstrip("/") TOKEN = os.environ.get("DATABRICKS_TOKEN", "") UNIQUE_NAME = os.environ.get("UNIQUE_NAME", "") @@ -58,6 +62,12 @@ def apply_map(text, id_map): return text +def run_cli(*args): + r = subprocess.run([CLI, *args], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8") + if r.returncode != 0: + sys.exit(f"replay_tfstate.py: {' '.join(args)} failed:\n{r.stdout}") + + def api(method, path, body): data = json.dumps(body).encode() if body is not None else None req = urllib.request.Request(HOST + path, data=data, method=method.upper()) @@ -140,9 +150,17 @@ def main(): out_dir = os.path.join(".databricks", "bundle", args.target, "terraform") os.makedirs(out_dir, exist_ok=True) - with open(os.path.join(out_dir, "terraform.tfstate"), "w") as f: + local_path = os.path.join(out_dir, "terraform.tfstate") + with open(local_path, "w") as f: f.write(apply_map(tfstate_raw, id_map)) + # A real terraform deploy leaves its state both on disk and in the workspace; push the remote + # copy too so a later migrate has a remote state to back up and tests that inspect the remote + # state dir see it. workspace import does not create parents, so mkdirs first. + state_dir = print_state.get_remote_state_path(args.target) + run_cli("workspace", "mkdirs", state_dir) + run_cli("workspace", "import", f"{state_dir}/terraform.tfstate", "--file", local_path, "--format", "AUTO", "--overwrite") + if __name__ == "__main__": main() diff --git a/acceptance/bundle/migrate/auto/apply-failure/output.txt b/acceptance/bundle/migrate/auto/apply-failure/output.txt index cbc98c73532..631211d3000 100644 --- a/acceptance/bundle/migrate/auto/apply-failure/output.txt +++ b/acceptance/bundle/migrate/auto/apply-failure/output.txt @@ -33,6 +33,7 @@ direct_migrated_via_env true ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json +[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate.backup === Retry finishes the apply on the already-migrated direct state (no re-migration) >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy @@ -54,3 +55,4 @@ ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json +[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate.backup diff --git a/acceptance/bundle/migrate/auto/artifacts/output.txt b/acceptance/bundle/migrate/auto/artifacts/output.txt index f85a8ccbd20..1cbab27c9b9 100644 --- a/acceptance/bundle/migrate/auto/artifacts/output.txt +++ b/acceptance/bundle/migrate/auto/artifacts/output.txt @@ -23,6 +23,7 @@ ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json +[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate.backup === Migrated state's library path (should be the resolved remote path, not the local glob) >>> print_state.py diff --git a/acceptance/bundle/migrate/auto/destroy/output.txt b/acceptance/bundle/migrate/auto/destroy/output.txt index 1a2bc094274..491efb78980 100644 --- a/acceptance/bundle/migrate/auto/destroy/output.txt +++ b/acceptance/bundle/migrate/auto/destroy/output.txt @@ -12,6 +12,22 @@ To proceed, use --auto-approve. .databricks/bundle/default/terraform/terraform.tfstate >>> MSYS_NO_PATHCONV=1 [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state -Error: Path (/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state) doesn't exist. +ID Type Language Path +[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate + +=== Destroy on direct: migrate then destroy +>>> [CLI] bundle destroy --auto-approve +Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). +The following resources will be deleted: + delete resources.jobs.job_a + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default + +Migrated 1 resource to direct deployment engine. +Destroy: 1 deleted -Exit code: 1 +=== Destroy leaves no state behind: no local state files, remote deployment removed +>>> find.py \.databricks/.*(\.tfstate|resources.*\.json|\.wal) + +>>> MSYS_NO_PATHCONV=1 musterr [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state +Error: Path (/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state) doesn't exist. diff --git a/acceptance/bundle/migrate/auto/direct-only/output.txt b/acceptance/bundle/migrate/auto/direct-only/output.txt index 5e95ac2b31d..9ce063350da 100644 --- a/acceptance/bundle/migrate/auto/direct-only/output.txt +++ b/acceptance/bundle/migrate/auto/direct-only/output.txt @@ -27,6 +27,32 @@ json.plan.resources.instance_pools.pool.new_state.value.node_type_id = "Standard .databricks/bundle/default/terraform/terraform.tfstate >>> MSYS_NO_PATHCONV=1 [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state -Error: Path (/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state) doesn't exist. +ID Type Language Path +[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate -Exit code: 1 +=== Deploy commits the migration and creates the direct-only resource +>>> [CLI] bundle deploy +Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Migrated 1 resource to direct deployment engine. +Created instance_pools.pool +Files: 1 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 1 unchanged + +>>> print_migration_telemetry +direct_migrated_via_config true + +=== Redeploy is a no-op: state is already on the direct engine +>>> [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Files: 0 uploaded, 0 deleted +Resources: 0 created, 0 changed, 0 deleted, 2 unchanged + +>>> print_requests.py //instance-pools/create + +=== No further actions planned +>>> [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged diff --git a/acceptance/bundle/migrate/auto/dms-migration/output.txt b/acceptance/bundle/migrate/auto/dms-migration/output.txt index 39d9da5c181..980c30afa4f 100644 --- a/acceptance/bundle/migrate/auto/dms-migration/output.txt +++ b/acceptance/bundle/migrate/auto/dms-migration/output.txt @@ -2,8 +2,6 @@ === Replay a prior terraform deployment (captured from a real terraform run) >>> replay_tfstate.py terraform-requests.json terraform.tfstate ->>> push_remote_tfstate.py - === Direct + deployment-history requested against a terraform state is rejected before commit >>> DATABRICKS_BUNDLE_ENGINE=direct DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY=true errcode [CLI] bundle deploy Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). diff --git a/acceptance/bundle/migrate/auto/dms-migration/script b/acceptance/bundle/migrate/auto/dms-migration/script index 78d8a577c58..7ef1ca09f94 100644 --- a/acceptance/bundle/migrate/auto/dms-migration/script +++ b/acceptance/bundle/migrate/auto/dms-migration/script @@ -2,9 +2,6 @@ export DATABRICKS_BUNDLE_ENGINE= title "Replay a prior terraform deployment (captured from a real terraform run)" trace replay_tfstate.py terraform-requests.json terraform.tfstate -# The rejected deploy below never pushes state, so surface the remote terraform.tfstate the deploy -# would have found (replay only wrote the local one) to prove the migration leaks no direct state. -trace push_remote_tfstate.py rm -f "$OUT_REQUESTS" title "Direct + deployment-history requested against a terraform state is rejected before commit" diff --git a/acceptance/bundle/migrate/auto/plan-missing/output.txt b/acceptance/bundle/migrate/auto/plan-missing/output.txt index 4e88ad6b076..5a121dfe386 100644 --- a/acceptance/bundle/migrate/auto/plan-missing/output.txt +++ b/acceptance/bundle/migrate/auto/plan-missing/output.txt @@ -2,8 +2,6 @@ === Replay a prior terraform deployment (captured from a real terraform run) >>> replay_tfstate.py terraform-requests.json terraform.tfstate ->>> push_remote_tfstate.py - === deploy --plan with a missing plan file fails after the migration prepared the direct state >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy --plan does-not-exist.json Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). diff --git a/acceptance/bundle/migrate/auto/plan-missing/script b/acceptance/bundle/migrate/auto/plan-missing/script index 657456e668e..d6721b1ba96 100644 --- a/acceptance/bundle/migrate/auto/plan-missing/script +++ b/acceptance/bundle/migrate/auto/plan-missing/script @@ -2,9 +2,6 @@ export DATABRICKS_BUNDLE_ENGINE= title "Replay a prior terraform deployment (captured from a real terraform run)" trace replay_tfstate.py terraform-requests.json terraform.tfstate -# The failed deploy below never pushes state, so surface the remote terraform.tfstate the deploy -# would have found (replay only wrote the local one) to show the bundle stays on terraform. -trace push_remote_tfstate.py rm -f "$OUT_REQUESTS" title "deploy --plan with a missing plan file fails after the migration prepared the direct state" diff --git a/acceptance/bundle/migrate/auto/push-failure/output.txt b/acceptance/bundle/migrate/auto/push-failure/output.txt index cdd3939e6ad..cea782a12cd 100644 --- a/acceptance/bundle/migrate/auto/push-failure/output.txt +++ b/acceptance/bundle/migrate/auto/push-failure/output.txt @@ -2,8 +2,6 @@ === Replay a prior terraform deployment (captured from a real terraform run) >>> replay_tfstate.py terraform-requests.json terraform.tfstate ->>> push_remote_tfstate.py - === Opt in via env var; inject 403 on the resources.json push so the deploy fails >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). diff --git a/acceptance/bundle/migrate/auto/push-failure/script b/acceptance/bundle/migrate/auto/push-failure/script index d81ad6b3391..da3ffaad3d9 100644 --- a/acceptance/bundle/migrate/auto/push-failure/script +++ b/acceptance/bundle/migrate/auto/push-failure/script @@ -2,9 +2,6 @@ export DATABRICKS_BUNDLE_ENGINE= title "Replay a prior terraform deployment (captured from a real terraform run)" trace replay_tfstate.py terraform-requests.json terraform.tfstate -# Surface the remote terraform.tfstate the deploy would have found (replay only wrote the local -# one) so the migration has a remote state to back up when it commits. -trace push_remote_tfstate.py rm -f "$OUT_REQUESTS" title "Opt in via env var; inject 403 on the resources.json push so the deploy fails" diff --git a/acceptance/bundle/migrate/auto/run-no-commit/output.txt b/acceptance/bundle/migrate/auto/run-no-commit/output.txt index 2c6852779c3..950329c8541 100644 --- a/acceptance/bundle/migrate/auto/run-no-commit/output.txt +++ b/acceptance/bundle/migrate/auto/run-no-commit/output.txt @@ -16,6 +16,5 @@ Run URL: [DATABRICKS_URL]/jobs/[NUMID]/runs/[NUMID]?o=[NUMID] .databricks/bundle/default/terraform/terraform.tfstate >>> MSYS_NO_PATHCONV=1 [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state -Error: Path (/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state) doesn't exist. - -Exit code: 1 +ID Type Language Path +[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate diff --git a/acceptance/bundle/migrate/auto/schema-storage-change/output.txt b/acceptance/bundle/migrate/auto/schema-storage-change/output.txt index 314ffb6b7cf..0902960a2a8 100644 --- a/acceptance/bundle/migrate/auto/schema-storage-change/output.txt +++ b/acceptance/bundle/migrate/auto/schema-storage-change/output.txt @@ -30,6 +30,7 @@ direct_migrate_recreate_planned true >>> MSYS_NO_PATHCONV=1 [CLI] workspace list /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state ID Type Language Path [NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json +[NUMID] FILE /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate === With --auto-approve the migration commits and the recreate is applied on direct >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy --auto-approve diff --git a/acceptance/bundle/migrate/auto/tfbackup-failure/output.txt b/acceptance/bundle/migrate/auto/tfbackup-failure/output.txt index 487b6c88772..4a633e7d7d2 100644 --- a/acceptance/bundle/migrate/auto/tfbackup-failure/output.txt +++ b/acceptance/bundle/migrate/auto/tfbackup-failure/output.txt @@ -2,8 +2,6 @@ === Replay a prior terraform deployment (captured from a real terraform run) >>> replay_tfstate.py terraform-requests.json terraform.tfstate ->>> push_remote_tfstate.py - === Opt in via env var; inject 403 on the DELETE of remote terraform.tfstate >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). diff --git a/acceptance/bundle/migrate/auto/tfbackup-failure/script b/acceptance/bundle/migrate/auto/tfbackup-failure/script index b2b3c7d7013..b2d2d9a6618 100644 --- a/acceptance/bundle/migrate/auto/tfbackup-failure/script +++ b/acceptance/bundle/migrate/auto/tfbackup-failure/script @@ -2,10 +2,6 @@ export DATABRICKS_BUNDLE_ENGINE= title "Replay a prior terraform deployment (captured from a real terraform run)" trace replay_tfstate.py terraform-requests.json terraform.tfstate -# The migration backs up + deletes the REMOTE terraform.tfstate; replay only wrote the local one, -# so push it to the workspace state path (as the terraform deploy used to) to give the faulted -# DELETE a target. -trace push_remote_tfstate.py rm -f "$OUT_REQUESTS" title "Opt in via env var; inject 403 on the DELETE of remote terraform.tfstate" diff --git a/acceptance/bundle/migrate/command/basic/output.txt b/acceptance/bundle/migrate/command/basic/output.txt index 51b08c173c6..75016e0d063 100644 --- a/acceptance/bundle/migrate/command/basic/output.txt +++ b/acceptance/bundle/migrate/command/basic/output.txt @@ -108,4 +108,5 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged [TEST_TMP_DIR]/.databricks/bundle/prod/terraform/terraform.tfstate: local terraform state serial=5 lineage="[UUID]" >>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states -t prod --force-pull +terraform.tfstate: remote terraform state serial=5 lineage="[UUID]" [TEST_TMP_DIR]/.databricks/bundle/prod/terraform/terraform.tfstate: local terraform state serial=5 lineage="[UUID]" diff --git a/acceptance/bundle/migrate/command/runas/output.txt b/acceptance/bundle/migrate/command/runas/output.txt index c956c03808b..c17ffdec425 100644 --- a/acceptance/bundle/migrate/command/runas/output.txt +++ b/acceptance/bundle/migrate/command/runas/output.txt @@ -86,4 +86,13 @@ Consider using a adding a top-level permissions section such as the following: See https://docs.databricks.com/dev-tools/bundles/permissions.html to learn more about permission configuration. in databricks.yml:5:3 -No active deployment found to destroy! +The following resources will be deleted: + delete resources.pipelines.foo + +This action will result in the deletion of the following Lakeflow Spark Declarative Pipelines along with the +Streaming Tables (STs) and Materialized Views (MVs) managed by them. Set 'cascade_on_destroy: false' on a pipeline to retain datasets on pipeline deletion: + delete resources.pipelines.foo + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/dabs_revenue-[UNIQUE_NAME]/production + +Destroy: 1 deleted diff --git a/acceptance/bundle/migrate/command/var_arg/output.txt b/acceptance/bundle/migrate/command/var_arg/output.txt index dbf8e7a3b2d..f0f7e0dc664 100644 --- a/acceptance/bundle/migrate/command/var_arg/output.txt +++ b/acceptance/bundle/migrate/command/var_arg/output.txt @@ -18,7 +18,12 @@ To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/dev/resources.js Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged >>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle destroy --var=job_name=Custom Job Name --auto-approve -No active deployment found to destroy! +The following resources will be deleted: + delete resources.jobs.test_job + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/migrate-var-test/dev + +Destroy: 1 deleted >>> replay_tfstate.py terraform-2-requests.json terraform-2.tfstate -t dev @@ -39,4 +44,9 @@ To undo the migration, remove [TEST_TMP_DIR]/.databricks/bundle/dev/resources.js Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged >>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle destroy --var=job_name=Custom Job Name --auto-approve -No active deployment found to destroy! +The following resources will be deleted: + delete resources.jobs.test_job + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/migrate-var-test/dev + +Destroy: 1 deleted From dea390ab154e82981ab96148538ba2d8a499f18c Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 29 Sep 2026 13:02:24 +0200 Subject: [PATCH 12/15] acceptance: gofmt/ruff formatting for replay_tfstate.py ruff format wraps the long workspace-import argument line; no behavior change. Co-authored-by: Isaac --- acceptance/bin/replay_tfstate.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/acceptance/bin/replay_tfstate.py b/acceptance/bin/replay_tfstate.py index fbb813c10ce..998f871dc63 100755 --- a/acceptance/bin/replay_tfstate.py +++ b/acceptance/bin/replay_tfstate.py @@ -159,7 +159,9 @@ def main(): # state dir see it. workspace import does not create parents, so mkdirs first. state_dir = print_state.get_remote_state_path(args.target) run_cli("workspace", "mkdirs", state_dir) - run_cli("workspace", "import", f"{state_dir}/terraform.tfstate", "--file", local_path, "--format", "AUTO", "--overwrite") + run_cli( + "workspace", "import", f"{state_dir}/terraform.tfstate", "--file", local_path, "--format", "AUTO", "--overwrite" + ) if __name__ == "__main__": From 7a23ef2f04c57d3a0fb8647ac91de31826e13a0a Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 29 Sep 2026 13:17:50 +0200 Subject: [PATCH 13/15] acceptance: keep replay fixtures and out.* files out of the bundle upload The migrate tests keep their replay fixtures (terraform*.tfstate, terraform*-requests.json) and write out.* state dumps into the bundle root, so `bundle deploy` synced them as bundle files and inflated the uploaded file counts. script.prepare now writes a .gitignore - excluding itself too - so the deploy skips them, and test.toml adds .gitignore to Ignore so the harness does not flag it as an unexpected file. With the fixtures no longer uploaded there is no reason to delete them, so replay_tfstate.py is non-destructive; command/var_arg then replays one fixture twice instead of carrying a second identical copy. Co-authored-by: Isaac --- acceptance/bin/replay_tfstate.py | 5 +- .../bundle/migrate/auto/clean/output.txt | 2 +- .../bundle/migrate/command/basic/output.txt | 4 +- .../migrate/command/dashboards/output.txt | 2 +- .../bundle/migrate/command/grants/output.txt | 2 +- .../migrate/command/permissions/output.txt | 2 +- .../bundle/migrate/command/var_arg/output.txt | 2 +- .../bundle/migrate/command/var_arg/script | 4 +- .../command/var_arg/terraform-2-requests.json | 28 --- .../command/var_arg/terraform-2.tfstate | 169 ------------------ acceptance/bundle/migrate/script.prepare | 5 + acceptance/bundle/migrate/test.toml | 9 +- 12 files changed, 21 insertions(+), 213 deletions(-) delete mode 100644 acceptance/bundle/migrate/command/var_arg/terraform-2-requests.json delete mode 100644 acceptance/bundle/migrate/command/var_arg/terraform-2.tfstate diff --git a/acceptance/bin/replay_tfstate.py b/acceptance/bin/replay_tfstate.py index 998f871dc63..e9062af2c48 100755 --- a/acceptance/bin/replay_tfstate.py +++ b/acceptance/bin/replay_tfstate.py @@ -106,9 +106,8 @@ def main(): requests = json.loads(requests_raw) tfstate = json.loads(tfstate_raw) - # Drop the fixtures from the bundle root so a later deploy does not sync them as bundle files. - os.remove(args.requests) - os.remove(args.tfstate) + # The fixtures stay on disk (a later deploy skips them via the .gitignore script.prepare writes), + # so replay is non-destructive and a single fixture can be replayed more than once. # identifying name -> recorded resource attributes, from the tfstate managed resources. name_to_attrs = {} diff --git a/acceptance/bundle/migrate/auto/clean/output.txt b/acceptance/bundle/migrate/auto/clean/output.txt index 5e40684e196..e0cb4f41aaa 100644 --- a/acceptance/bundle/migrate/auto/clean/output.txt +++ b/acceptance/bundle/migrate/auto/clean/output.txt @@ -51,7 +51,7 @@ Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged === Deploy picks up the update (with and without --plan) Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... Updated jobs.test_job -Files: 2 uploaded, 0 deleted +Files: 1 uploaded, 0 deleted Resources: 0 created, 1 changed, 0 deleted, 0 unchanged >>> print_migration_telemetry diff --git a/acceptance/bundle/migrate/command/basic/output.txt b/acceptance/bundle/migrate/command/basic/output.txt index 75016e0d063..06ac288cbf3 100644 --- a/acceptance/bundle/migrate/command/basic/output.txt +++ b/acceptance/bundle/migrate/command/basic/output.txt @@ -60,7 +60,7 @@ Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged >>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files... -Files: 5 uploaded, 0 deleted +Files: 3 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 3 unchanged >>> print_requests.py --get //jobs/get @@ -98,7 +98,7 @@ Plan: 0 to add, 2 to change, 0 to delete, 1 unchanged Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files... Updated jobs.test_job Updated pipelines.test_pipeline -Files: 2 uploaded, 0 deleted +Files: 1 uploaded, 0 deleted Resources: 0 created, 2 changed, 0 deleted, 1 unchanged === Different target, still on the terraform state from a prior deployment diff --git a/acceptance/bundle/migrate/command/dashboards/output.txt b/acceptance/bundle/migrate/command/dashboards/output.txt index 51be029784b..306d160ea38 100644 --- a/acceptance/bundle/migrate/command/dashboards/output.txt +++ b/acceptance/bundle/migrate/command/dashboards/output.txt @@ -23,7 +23,7 @@ Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged >>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deploy --auto-approve Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Files: 5 uploaded, 0 deleted +Files: 2 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged >>> print_requests.py --get //dashboards diff --git a/acceptance/bundle/migrate/command/grants/output.txt b/acceptance/bundle/migrate/command/grants/output.txt index 8a89f3bf7df..bd4d8df3fa5 100644 --- a/acceptance/bundle/migrate/command/grants/output.txt +++ b/acceptance/bundle/migrate/command/grants/output.txt @@ -21,7 +21,7 @@ Plan: 0 to add, 0 to change, 0 to delete, 6 unchanged >>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Files: 3 uploaded, 0 deleted +Files: 1 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 6 unchanged >>> print_requests.py --get //unity-catalog/permissions diff --git a/acceptance/bundle/migrate/command/permissions/output.txt b/acceptance/bundle/migrate/command/permissions/output.txt index c3bcd4df436..182946cfffc 100644 --- a/acceptance/bundle/migrate/command/permissions/output.txt +++ b/acceptance/bundle/migrate/command/permissions/output.txt @@ -45,7 +45,7 @@ Plan: 0 to add, 0 to change, 0 to delete, 4 unchanged >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/default/files... -Files: 5 uploaded, 0 deleted +Files: 3 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 4 unchanged >>> print_requests.py --get //jobs/get diff --git a/acceptance/bundle/migrate/command/var_arg/output.txt b/acceptance/bundle/migrate/command/var_arg/output.txt index f0f7e0dc664..1280cf619da 100644 --- a/acceptance/bundle/migrate/command/var_arg/output.txt +++ b/acceptance/bundle/migrate/command/var_arg/output.txt @@ -25,7 +25,7 @@ All files and directories at the following location will be deleted: /Workspace/ Destroy: 1 deleted ->>> replay_tfstate.py terraform-2-requests.json terraform-2.tfstate -t dev +>>> replay_tfstate.py terraform-requests.json terraform.tfstate -t dev >>> [CLI] bundle deployment migrate --var job_name=Custom Job Name Success! Migrated 1 resources to direct engine state file: [TEST_TMP_DIR]/.databricks/bundle/dev/resources.json diff --git a/acceptance/bundle/migrate/command/var_arg/script b/acceptance/bundle/migrate/command/var_arg/script index b94521c7899..5036336a424 100644 --- a/acceptance/bundle/migrate/command/var_arg/script +++ b/acceptance/bundle/migrate/command/var_arg/script @@ -8,8 +8,8 @@ trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle destroy --var="job_name=Custom Job N # Try different syntax, '--var X', instead of '--var=X' rm -fr .databricks -# Replay the same deployment again (the second fixture copy; replay consumes its inputs) -trace replay_tfstate.py terraform-2-requests.json terraform-2.tfstate -t dev +# Replay the same deployment again (replay is non-destructive, so one fixture serves both) +trace replay_tfstate.py terraform-requests.json terraform.tfstate -t dev trace $CLI bundle deployment migrate --var "job_name=Custom Job Name" 2>&1 | contains.py 'Migrated 1 resources' trace print_state.py | jq '.state."resources.jobs.test_job".state.name' trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan --var "job_name=Custom Job Name" | contains.py "1 unchanged" diff --git a/acceptance/bundle/migrate/command/var_arg/terraform-2-requests.json b/acceptance/bundle/migrate/command/var_arg/terraform-2-requests.json deleted file mode 100644 index 6fb9f2341c4..00000000000 --- a/acceptance/bundle/migrate/command/var_arg/terraform-2-requests.json +++ /dev/null @@ -1,28 +0,0 @@ -[ - { - "method": "POST", - "path": "/api/2.2/jobs/create", - "body": { - "deployment": { - "kind": "BUNDLE", - "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-var-test/dev/state/metadata.json" - }, - "edit_mode": "UI_LOCKED", - "format": "MULTI_TASK", - "max_concurrent_runs": 1, - "name": "Custom Job Name", - "queue": { - "enabled": true - }, - "tasks": [ - { - "notebook_task": { - "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-var-test/dev/files/notebook", - "source": "WORKSPACE" - }, - "task_key": "main" - } - ] - } - } -] diff --git a/acceptance/bundle/migrate/command/var_arg/terraform-2.tfstate b/acceptance/bundle/migrate/command/var_arg/terraform-2.tfstate deleted file mode 100644 index 434dbe1f911..00000000000 --- a/acceptance/bundle/migrate/command/var_arg/terraform-2.tfstate +++ /dev/null @@ -1,169 +0,0 @@ -{ - "version": 4, - "terraform_version": "1.5.5", - "serial": 1, - "lineage": "72aa60ee-0151-f001-7cd5-ea9bace71dc7", - "outputs": {}, - "resources": [ - { - "mode": "managed", - "type": "databricks_job", - "name": "test_job", - "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", - "instances": [ - { - "schema_version": 2, - "attributes": { - "always_running": false, - "budget_policy_id": null, - "continuous": [], - "control_run_state": false, - "dbt_task": [], - "deployment": [ - { - "deployment_id": "", - "kind": "BUNDLE", - "metadata_file_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-var-test/dev/state/metadata.json", - "version_id": "" - } - ], - "description": null, - "edit_mode": "UI_LOCKED", - "email_notifications": [ - { - "no_alert_for_skipped_runs": false, - "on_duration_warning_threshold_exceeded": [], - "on_failure": [], - "on_start": [], - "on_streaming_backlog_exceeded": [], - "on_success": [] - } - ], - "environment": [], - "existing_cluster_id": null, - "format": "MULTI_TASK", - "git_source": [], - "health": [], - "id": "8790614985789453000", - "job_cluster": [], - "library": [], - "max_concurrent_runs": 1, - "max_retries": 0, - "min_retry_interval_millis": 0, - "name": "Custom Job Name", - "new_cluster": [], - "notebook_task": [], - "notification_settings": [], - "parameter": [], - "parent_path": null, - "performance_target": null, - "pipeline_task": [], - "provider_config": [ - { - "workspace_id": "900800700600" - } - ], - "python_wheel_task": [], - "queue": [ - { - "enabled": true - } - ], - "retry_on_timeout": false, - "run_as": [ - { - "group_name": "", - "service_principal_name": "", - "user_name": "tester@databricks.com" - } - ], - "run_job_task": [], - "schedule": [], - "spark_jar_task": [], - "spark_python_task": [], - "spark_submit_task": [], - "tags": null, - "task": [ - { - "ai_runtime_task": [], - "alert_task": [], - "clean_rooms_notebook_task": [], - "compute": [], - "condition_task": [], - "dashboard_task": [], - "dbt_cloud_task": [], - "dbt_platform_task": [], - "dbt_task": [], - "depends_on": [], - "description": "", - "disable_auto_optimization": false, - "disabled": false, - "email_notifications": [ - { - "no_alert_for_skipped_runs": false, - "on_duration_warning_threshold_exceeded": [], - "on_failure": [], - "on_start": [], - "on_streaming_backlog_exceeded": [], - "on_success": [] - } - ], - "environment_key": "", - "existing_cluster_id": "", - "for_each_task": [], - "gen_ai_compute_task": [], - "health": [], - "job_cluster_key": "", - "library": [], - "max_retries": 0, - "min_retry_interval_millis": 0, - "new_cluster": [], - "notebook_task": [ - { - "base_parameters": null, - "notebook_path": "/Workspace/Users/tester@databricks.com/.bundle/migrate-var-test/dev/files/notebook", - "source": "WORKSPACE", - "warehouse_id": "" - } - ], - "notification_settings": [], - "pipeline_task": [], - "power_bi_task": [], - "python_operator_task": [], - "python_wheel_task": [], - "retry_on_timeout": false, - "run_if": "ALL_SUCCESS", - "run_job_task": [], - "spark_jar_task": [], - "spark_python_task": [], - "spark_submit_task": [], - "sql_task": [], - "task_key": "main", - "timeout_seconds": 0, - "webhook_notifications": [] - } - ], - "timeout_seconds": 0, - "timeouts": null, - "trigger": [], - "triggers": [], - "url": "[DATABRICKS_URL]/#job/8790614985789453000", - "usage_policy_id": null, - "webhook_notifications": [ - { - "on_duration_warning_threshold_exceeded": [], - "on_failure": [], - "on_start": [], - "on_streaming_backlog_exceeded": [], - "on_success": [] - } - ] - }, - "sensitive_attributes": [], - "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJ1cGRhdGUiOjE4MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjIifQ==" - } - ] - } - ], - "check_results": null -} diff --git a/acceptance/bundle/migrate/script.prepare b/acceptance/bundle/migrate/script.prepare index e99f29a8307..b43d9d80d1a 100644 --- a/acceptance/bundle/migrate/script.prepare +++ b/acceptance/bundle/migrate/script.prepare @@ -5,3 +5,8 @@ print_migration_telemetry() { print_telemetry_bool_values | grep '^direct_' || true } + +# The replay fixtures and the generated out.* files live in the bundle root but are not bundle +# files, so keep them out of `bundle deploy`'s upload. The list excludes .gitignore itself so it is +# not uploaded either; test.toml adds .gitignore to Ignore so the harness does not flag it. +printf '%s\n' '.gitignore' 'out.*' 'terraform*.tfstate' 'terraform*-requests.json' > .gitignore diff --git a/acceptance/bundle/migrate/test.toml b/acceptance/bundle/migrate/test.toml index 517f5524ecb..ac8aa278036 100644 --- a/acceptance/bundle/migrate/test.toml +++ b/acceptance/bundle/migrate/test.toml @@ -1,14 +1,15 @@ Cloud = false RecordRequests = true IncludeRequestHeaders = ["User-Agent"] -Ignore = [".databricks"] +# .databricks: engine-internal state; .gitignore: written by script.prepare to keep the replay +# fixtures and out.* files out of the bundle upload (it is not a bundle file itself). +Ignore = [".databricks", ".gitignore"] # Each test's script sets DATABRICKS_BUNDLE_ENGINE inline; pin the outer # matrix to ["direct"] so CI's engine filter includes these tests without # also running the same script twice per engine. EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] -# These tests deploy on terraform and then migrate to direct. Recording is direct-only, so -# the terraform half is recorded nowhere and the migration reads state the service lacks. -# Migrating an existing deployment onto the service is its own story. +# These tests replay a prior terraform deployment (replay_tfstate.py) and then migrate to direct. +# Recording is direct-only, and the DMS variant does not apply to the migration story. EnvMatrix.DMS = [""] From e0c837ce3a5eff522ee99fdd961784e3117a77dc Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 29 Sep 2026 14:03:50 +0200 Subject: [PATCH 14/15] acceptance: replay authenticates like the CLI so it works on cloud The Cloud=true migrate tests (schema/volume/catalog migration) replay against a real workspace, where auth is OAuth and DATABRICKS_TOKEN is empty - so replay's `Authorization: Bearer $DATABRICKS_TOKEN` came back HTTP 401 and every one of them failed on every cloud. When DATABRICKS_TOKEN is unset, resolve the token via `databricks auth token` (the same auth the bundle commands use); locally the PAT is still preferred so replay hits the same fake-server workspace as the bundle commands. Co-authored-by: Isaac --- acceptance/bin/replay_tfstate.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/acceptance/bin/replay_tfstate.py b/acceptance/bin/replay_tfstate.py index e9062af2c48..3e37ad08f09 100755 --- a/acceptance/bin/replay_tfstate.py +++ b/acceptance/bin/replay_tfstate.py @@ -28,15 +28,36 @@ CLI = os.environ["CLI"] HOST = os.environ.get("DATABRICKS_HOST", "").rstrip("/") -TOKEN = os.environ.get("DATABRICKS_TOKEN", "") UNIQUE_NAME = os.environ.get("UNIQUE_NAME", "") -# Talk to the (local) workspace directly rather than via `databricks api`: the CLI renders responses -# through Go's `any`, which decodes JSON numbers as float64 and silently mangles the low digits of a -# freshly minted id (they exceed 2^53), so the id we'd record would not match the one the backend -# stored. Python's json keeps ids exact. Bypass any proxy: these tests only hit the local server. +# Talk to the workspace directly rather than via `databricks api`: the CLI renders responses through +# Go's `any`, which decodes JSON numbers as float64 and silently mangles the low digits of a freshly +# minted id (they exceed 2^53), so the id we'd record would not match the one the backend stored. +# Python's json keeps ids exact. Bypass any proxy: these tests only hit the workspace directly. _opener = urllib.request.build_opener(urllib.request.ProxyHandler({})) + +def bearer(): + """The auth token replay authenticates with. Locally the fake server routes by the PAT in + DATABRICKS_TOKEN, so prefer it to hit the same workspace as the bundle commands. On cloud there + is no PAT and auth is OAuth, so ask the CLI for the resolved token (the same auth the bundle + commands use) - a bare Bearer DATABRICKS_TOKEN is empty and unauthorized (HTTP 401) there.""" + tok = os.environ.get("DATABRICKS_TOKEN", "") + if tok: + return tok + r = subprocess.run( + [CLI, "auth", "token", "--output", "json"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8" + ) + if r.returncode == 0 and r.stdout.strip(): + try: + return json.loads(r.stdout)["access_token"] + except (json.JSONDecodeError, KeyError): + pass + return tok + + +TOKEN = bearer() + # Per resource: which response field carries the new id. Terraform's tfstate stores the same value # as the resource's `id`, keyed here by the create path so we can match a create to its tfstate entry. ID_FIELDS = ["job_id", "pipeline_id", "dashboard_id", "experiment_id", "full_name", "id", "name"] From 9bcea5a05bec741dc3552411b552714d285517d9 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 29 Sep 2026 15:22:43 +0200 Subject: [PATCH 15/15] acceptance: make the replay-based migrate tests local-only The migrate tests replay fixtures captured against the fake server, so they reproduce a terraform-shaped state only there. Eight of them were Cloud=true (on main they deployed on terraform against a real workspace), but replaying fake-server fixtures against a real workspace does not work: auth there is OAuth so the raw requests came back 401, and the real backend rejects mock-accepted bodies (catalog create 400). Mark them Cloud=false - they still exercise the migration logic against the fake server. Restoring cloud coverage for these scenarios is a follow-up, once replay can target a real workspace. Also revert the `databricks auth token` fallback in replay_tfstate.py: it was treating the symptom, and with replay local-only DATABRICKS_TOKEN is always the credential the fake server expects. Co-authored-by: Isaac --- acceptance/bin/replay_tfstate.py | 23 +++---------------- .../pipeline-storage-change/out.test.toml | 2 +- .../auto/pipeline-storage-change/test.toml | 5 +++- .../out.test.toml | 2 +- .../registered-model-catalog-change/test.toml | 5 +++- .../registered-model-rename/out.test.toml | 2 +- .../auto/registered-model-rename/test.toml | 5 +++- .../auto/schema-catalog-change/out.test.toml | 2 +- .../auto/schema-catalog-change/test.toml | 5 +++- .../auto/schema-name-normalized/out.test.toml | 2 +- .../auto/schema-name-normalized/test.toml | 5 +++- .../migrate/auto/schema-rename/out.test.toml | 2 +- .../migrate/auto/schema-rename/test.toml | 5 +++- .../auto/volume-name-normalized/out.test.toml | 2 +- .../auto/volume-name-normalized/test.toml | 5 +++- .../migrate/auto/volume-rename/out.test.toml | 2 +- .../migrate/auto/volume-rename/test.toml | 5 +++- 17 files changed, 43 insertions(+), 36 deletions(-) diff --git a/acceptance/bin/replay_tfstate.py b/acceptance/bin/replay_tfstate.py index 3e37ad08f09..070da4284db 100755 --- a/acceptance/bin/replay_tfstate.py +++ b/acceptance/bin/replay_tfstate.py @@ -37,26 +37,9 @@ _opener = urllib.request.build_opener(urllib.request.ProxyHandler({})) -def bearer(): - """The auth token replay authenticates with. Locally the fake server routes by the PAT in - DATABRICKS_TOKEN, so prefer it to hit the same workspace as the bundle commands. On cloud there - is no PAT and auth is OAuth, so ask the CLI for the resolved token (the same auth the bundle - commands use) - a bare Bearer DATABRICKS_TOKEN is empty and unauthorized (HTTP 401) there.""" - tok = os.environ.get("DATABRICKS_TOKEN", "") - if tok: - return tok - r = subprocess.run( - [CLI, "auth", "token", "--output", "json"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8" - ) - if r.returncode == 0 and r.stdout.strip(): - try: - return json.loads(r.stdout)["access_token"] - except (json.JSONDecodeError, KeyError): - pass - return tok - - -TOKEN = bearer() +# The fake server routes by the PAT in DATABRICKS_TOKEN. These fixtures are captured against it, so +# the migrate tests that replay them are local-only (see their test.toml) - there is no cloud path. +TOKEN = os.environ.get("DATABRICKS_TOKEN", "") # Per resource: which response field carries the new id. Terraform's tfstate stores the same value # as the resource's `id`, keyed here by the create path so we can match a create to its tfstate entry. diff --git a/acceptance/bundle/migrate/auto/pipeline-storage-change/out.test.toml b/acceptance/bundle/migrate/auto/pipeline-storage-change/out.test.toml index d73c45e3119..27ec2a7fcd6 100644 --- a/acceptance/bundle/migrate/auto/pipeline-storage-change/out.test.toml +++ b/acceptance/bundle/migrate/auto/pipeline-storage-change/out.test.toml @@ -1,3 +1,3 @@ -Cloud = true +Cloud = false EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/migrate/auto/pipeline-storage-change/test.toml b/acceptance/bundle/migrate/auto/pipeline-storage-change/test.toml index b674c6425f9..6880cf5c651 100644 --- a/acceptance/bundle/migrate/auto/pipeline-storage-change/test.toml +++ b/acceptance/bundle/migrate/auto/pipeline-storage-change/test.toml @@ -1,4 +1,7 @@ -Cloud = true +# Local-only: the replay fixtures are captured against the fake server, so they reproduce a +# terraform state only there, not on a real workspace (replaying them on cloud fails auth and +# hits backend validation the mock does not enforce). +Cloud = false RecordRequests = true Ignore = [ diff --git a/acceptance/bundle/migrate/auto/registered-model-catalog-change/out.test.toml b/acceptance/bundle/migrate/auto/registered-model-catalog-change/out.test.toml index d73c45e3119..27ec2a7fcd6 100644 --- a/acceptance/bundle/migrate/auto/registered-model-catalog-change/out.test.toml +++ b/acceptance/bundle/migrate/auto/registered-model-catalog-change/out.test.toml @@ -1,3 +1,3 @@ -Cloud = true +Cloud = false EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/migrate/auto/registered-model-catalog-change/test.toml b/acceptance/bundle/migrate/auto/registered-model-catalog-change/test.toml index b674c6425f9..6880cf5c651 100644 --- a/acceptance/bundle/migrate/auto/registered-model-catalog-change/test.toml +++ b/acceptance/bundle/migrate/auto/registered-model-catalog-change/test.toml @@ -1,4 +1,7 @@ -Cloud = true +# Local-only: the replay fixtures are captured against the fake server, so they reproduce a +# terraform state only there, not on a real workspace (replaying them on cloud fails auth and +# hits backend validation the mock does not enforce). +Cloud = false RecordRequests = true Ignore = [ diff --git a/acceptance/bundle/migrate/auto/registered-model-rename/out.test.toml b/acceptance/bundle/migrate/auto/registered-model-rename/out.test.toml index d73c45e3119..27ec2a7fcd6 100644 --- a/acceptance/bundle/migrate/auto/registered-model-rename/out.test.toml +++ b/acceptance/bundle/migrate/auto/registered-model-rename/out.test.toml @@ -1,3 +1,3 @@ -Cloud = true +Cloud = false EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/migrate/auto/registered-model-rename/test.toml b/acceptance/bundle/migrate/auto/registered-model-rename/test.toml index b674c6425f9..6880cf5c651 100644 --- a/acceptance/bundle/migrate/auto/registered-model-rename/test.toml +++ b/acceptance/bundle/migrate/auto/registered-model-rename/test.toml @@ -1,4 +1,7 @@ -Cloud = true +# Local-only: the replay fixtures are captured against the fake server, so they reproduce a +# terraform state only there, not on a real workspace (replaying them on cloud fails auth and +# hits backend validation the mock does not enforce). +Cloud = false RecordRequests = true Ignore = [ diff --git a/acceptance/bundle/migrate/auto/schema-catalog-change/out.test.toml b/acceptance/bundle/migrate/auto/schema-catalog-change/out.test.toml index d73c45e3119..27ec2a7fcd6 100644 --- a/acceptance/bundle/migrate/auto/schema-catalog-change/out.test.toml +++ b/acceptance/bundle/migrate/auto/schema-catalog-change/out.test.toml @@ -1,3 +1,3 @@ -Cloud = true +Cloud = false EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/migrate/auto/schema-catalog-change/test.toml b/acceptance/bundle/migrate/auto/schema-catalog-change/test.toml index b674c6425f9..6880cf5c651 100644 --- a/acceptance/bundle/migrate/auto/schema-catalog-change/test.toml +++ b/acceptance/bundle/migrate/auto/schema-catalog-change/test.toml @@ -1,4 +1,7 @@ -Cloud = true +# Local-only: the replay fixtures are captured against the fake server, so they reproduce a +# terraform state only there, not on a real workspace (replaying them on cloud fails auth and +# hits backend validation the mock does not enforce). +Cloud = false RecordRequests = true Ignore = [ diff --git a/acceptance/bundle/migrate/auto/schema-name-normalized/out.test.toml b/acceptance/bundle/migrate/auto/schema-name-normalized/out.test.toml index d73c45e3119..27ec2a7fcd6 100644 --- a/acceptance/bundle/migrate/auto/schema-name-normalized/out.test.toml +++ b/acceptance/bundle/migrate/auto/schema-name-normalized/out.test.toml @@ -1,3 +1,3 @@ -Cloud = true +Cloud = false EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/migrate/auto/schema-name-normalized/test.toml b/acceptance/bundle/migrate/auto/schema-name-normalized/test.toml index 37e1006eb5a..b61ef681ed8 100644 --- a/acceptance/bundle/migrate/auto/schema-name-normalized/test.toml +++ b/acceptance/bundle/migrate/auto/schema-name-normalized/test.toml @@ -1,4 +1,7 @@ -Cloud = true +# Local-only: the replay fixtures are captured against the fake server, so they reproduce a +# terraform state only there, not on a real workspace (replaying them on cloud fails auth and +# hits backend validation the mock does not enforce). +Cloud = false RecordRequests = false Ignore = [ diff --git a/acceptance/bundle/migrate/auto/schema-rename/out.test.toml b/acceptance/bundle/migrate/auto/schema-rename/out.test.toml index d73c45e3119..27ec2a7fcd6 100644 --- a/acceptance/bundle/migrate/auto/schema-rename/out.test.toml +++ b/acceptance/bundle/migrate/auto/schema-rename/out.test.toml @@ -1,3 +1,3 @@ -Cloud = true +Cloud = false EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/migrate/auto/schema-rename/test.toml b/acceptance/bundle/migrate/auto/schema-rename/test.toml index b674c6425f9..6880cf5c651 100644 --- a/acceptance/bundle/migrate/auto/schema-rename/test.toml +++ b/acceptance/bundle/migrate/auto/schema-rename/test.toml @@ -1,4 +1,7 @@ -Cloud = true +# Local-only: the replay fixtures are captured against the fake server, so they reproduce a +# terraform state only there, not on a real workspace (replaying them on cloud fails auth and +# hits backend validation the mock does not enforce). +Cloud = false RecordRequests = true Ignore = [ diff --git a/acceptance/bundle/migrate/auto/volume-name-normalized/out.test.toml b/acceptance/bundle/migrate/auto/volume-name-normalized/out.test.toml index d73c45e3119..27ec2a7fcd6 100644 --- a/acceptance/bundle/migrate/auto/volume-name-normalized/out.test.toml +++ b/acceptance/bundle/migrate/auto/volume-name-normalized/out.test.toml @@ -1,3 +1,3 @@ -Cloud = true +Cloud = false EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/migrate/auto/volume-name-normalized/test.toml b/acceptance/bundle/migrate/auto/volume-name-normalized/test.toml index 37e1006eb5a..b61ef681ed8 100644 --- a/acceptance/bundle/migrate/auto/volume-name-normalized/test.toml +++ b/acceptance/bundle/migrate/auto/volume-name-normalized/test.toml @@ -1,4 +1,7 @@ -Cloud = true +# Local-only: the replay fixtures are captured against the fake server, so they reproduce a +# terraform state only there, not on a real workspace (replaying them on cloud fails auth and +# hits backend validation the mock does not enforce). +Cloud = false RecordRequests = false Ignore = [ diff --git a/acceptance/bundle/migrate/auto/volume-rename/out.test.toml b/acceptance/bundle/migrate/auto/volume-rename/out.test.toml index d73c45e3119..27ec2a7fcd6 100644 --- a/acceptance/bundle/migrate/auto/volume-rename/out.test.toml +++ b/acceptance/bundle/migrate/auto/volume-rename/out.test.toml @@ -1,3 +1,3 @@ -Cloud = true +Cloud = false EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/migrate/auto/volume-rename/test.toml b/acceptance/bundle/migrate/auto/volume-rename/test.toml index 37e1006eb5a..b61ef681ed8 100644 --- a/acceptance/bundle/migrate/auto/volume-rename/test.toml +++ b/acceptance/bundle/migrate/auto/volume-rename/test.toml @@ -1,4 +1,7 @@ -Cloud = true +# Local-only: the replay fixtures are captured against the fake server, so they reproduce a +# terraform state only there, not on a real workspace (replaying them on cloud fails auth and +# hits backend validation the mock does not enforce). +Cloud = false RecordRequests = false Ignore = [