diff --git a/acceptance/bin/capture_tfstate.py b/acceptance/bin/capture_tfstate.py new file mode 100755 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 new file mode 100755 index 00000000000..070da4284db --- /dev/null +++ b/acceptance/bin/replay_tfstate.py @@ -0,0 +1,171 @@ +#!/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 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] +""" + +import argparse +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("/") +UNIQUE_NAME = os.environ.get("UNIQUE_NAME", "") + +# 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({})) + + +# 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. +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. +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(): + text = text.replace(old, new) + 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()) + 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(): + parser = argparse.ArgumentParser() + parser.add_argument("requests") + parser.add_argument("tfstate") + parser.add_argument("-t", "--target", default="default") + args = parser.parse_args() + + 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) + + # 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 = {} + for r in tfstate["resources"]: + if r.get("mode") != "managed": + continue + attrs = r["instances"][0]["attributes"] + 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: + 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 identifying name matches a tfstate resource: + # map its recorded id to the freshly minted one. + 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}") + 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) + 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 8a3455d4d2b..631211d3000 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 +=== 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) @@ -36,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 [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..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 "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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 new file mode 100644 index 00000000000..a49c4cf4d15 --- /dev/null +++ b/acceptance/bundle/migrate/auto/apply-failure/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "e7b2f099-38a8-3ee6-5873-2f1f2490d94b", + "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/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 c6c6d8516c2..1cbab27c9b9 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 +=== 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 @@ -15,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 bb8bfd89ef7..b351121e54a 100644 --- a/acceptance/bundle/migrate/auto/artifacts/script +++ b/acceptance/bundle/migrate/auto/artifacts/script @@ -1,7 +1,7 @@ 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 +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 new file mode 100644 index 00000000000..1cd81631add --- /dev/null +++ b/acceptance/bundle/migrate/auto/artifacts/terraform.tfstate @@ -0,0 +1,180 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "5855e5a0-b4d4-25c6-1c18-927cf805aab9", + "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/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/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..e0cb4f41aaa 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 +=== Replay a prior terraform deployment +>>> replay_tfstate.py terraform-requests.json terraform.tfstate ->>> print_migration_telemetry -direct_drymigrate_success true -direct_drymigrate_warnings false - -=== 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 @@ -59,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/auto/clean/script b/acceptance/bundle/migrate/auto/clean/script index 29afd6c31cc..d655a9cda1a 100644 --- a/acceptance/bundle/migrate/auto/clean/script +++ b/acceptance/bundle/migrate/auto/clean/script @@ -1,13 +1,12 @@ 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 +title "Replay a prior terraform deployment" +trace replay_tfstate.py terraform-requests.json 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 +29,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-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 new file mode 100644 index 00000000000..142494090fa --- /dev/null +++ b/acceptance/bundle/migrate/auto/clean/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b483d381-20e3-32f5-b2fb-11d5b8939772", + "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/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/default/output.txt b/acceptance/bundle/migrate/auto/default/output.txt index b22d845e772..e5a10caf919 100644 --- a/acceptance/bundle/migrate/auto/default/output.txt +++ b/acceptance/bundle/migrate/auto/default/output.txt @@ -1,21 +1,13 @@ -=== 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 +=== 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 @@ -23,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 07cb3903546..28f598a5dfc 100644 --- a/acceptance/bundle/migrate/auto/default/script +++ b/acceptance/bundle/migrate/auto/default/script @@ -1,8 +1,10 @@ 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 +# 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" @@ -11,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 new file mode 100644 index 00000000000..c04f332a595 --- /dev/null +++ b/acceptance/bundle/migrate/auto/default/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "c39488aa-8f36-06fd-a7cb-3f0c95b4c506", + "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/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 +} diff --git a/acceptance/bundle/migrate/auto/delete-all/output.txt b/acceptance/bundle/migrate/auto/delete-all/output.txt index 9989d35f381..f03f24ba55e 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 +=== 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 bf3ae01ff5b..dfda9de6c85 100644 --- a/acceptance/bundle/migrate/auto/delete-all/script +++ b/acceptance/bundle/migrate/auto/delete-all/script @@ -1,7 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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 new file mode 100644 index 00000000000..d9b084cce37 --- /dev/null +++ b/acceptance/bundle/migrate/auto/delete-all/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "75222e93-2446-500e-da3b-173118f55649", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_a", + "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/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 2dabba9adab..7d6a7b04dd2 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 +=== 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 39116c88f9e..19d1c9f1462 100644 --- a/acceptance/bundle/migrate/auto/delete/script +++ b/acceptance/bundle/migrate/auto/delete/script @@ -1,7 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform with two jobs" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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 new file mode 100644 index 00000000000..21475705f5c --- /dev/null +++ b/acceptance/bundle/migrate/auto/delete/terraform.tfstate @@ -0,0 +1,210 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 3, + "lineage": "b1bd09de-e358-bfbf-88ed-3f2412c885b7", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_drop", + "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/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_keep", + "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/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 7e239d23866..491efb78980 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 +=== 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 @@ -17,8 +13,6 @@ To proceed, use --auto-approve. >>> 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 === Destroy on direct: migrate then destroy diff --git a/acceptance/bundle/migrate/auto/destroy/script b/acceptance/bundle/migrate/auto/destroy/script index 8450b09ada2..d9a0e91ddf1 100644 --- a/acceptance/bundle/migrate/auto/destroy/script +++ b/acceptance/bundle/migrate/auto/destroy/script @@ -5,8 +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. -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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 new file mode 100644 index 00000000000..3ee7ea61161 --- /dev/null +++ b/acceptance/bundle/migrate/auto/destroy/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "2e5d76d4-f80d-57cc-7203-c95306803b1c", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_a", + "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/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 9ac13f5e368..b069e473748 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 +=== 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 d927be0e482..d98281e937f 100644 --- a/acceptance/bundle/migrate/auto/direct-only-envvar/script +++ b/acceptance/bundle/migrate/auto/direct-only-envvar/script @@ -1,7 +1,7 @@ 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 +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 new file mode 100644 index 00000000000..41e3ff52664 --- /dev/null +++ b/acceptance/bundle/migrate/auto/direct-only-envvar/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "df0ab31f-787b-ce52-0046-2f55f43b1a55", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_a", + "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/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 ed4e64d0137..9ce063350da 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 +=== 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 @@ -32,8 +28,6 @@ json.plan.resources.instance_pools.pool.new_state.value.node_type_id = "Standard >>> 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 === Deploy commits the migration and creates the direct-only resource diff --git a/acceptance/bundle/migrate/auto/direct-only/script b/acceptance/bundle/migrate/auto/direct-only/script index 1d01ce69df1..2730c7ba5d9 100644 --- a/acceptance/bundle/migrate/auto/direct-only/script +++ b/acceptance/bundle/migrate/auto/direct-only/script @@ -1,7 +1,7 @@ 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 +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 new file mode 100644 index 00000000000..c1d5e382ae2 --- /dev/null +++ b/acceptance/bundle/migrate/auto/direct-only/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "06b4597d-82c3-9231-5fa6-08450cea3714", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_a", + "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/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/dms-migration/output.txt b/acceptance/bundle/migrate/auto/dms-migration/output.txt index 404c9d0078a..980c30afa4f 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 +=== Replay a prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json 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 @@ -21,6 +17,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 ccd5eeecdb8..7ef1ca09f94 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 "Replay a prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json 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-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 new file mode 100644 index 00000000000..27ce97659cd --- /dev/null +++ b/acceptance/bundle/migrate/auto/dms-migration/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "99f0db23-4ab4-72e5-f20f-bd69f4e61594", + "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/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/envvar/output.txt b/acceptance/bundle/migrate/auto/envvar/output.txt index bfc4e1b677e..e67cc31e1c9 100644 --- a/acceptance/bundle/migrate/auto/envvar/output.txt +++ b/acceptance/bundle/migrate/auto/envvar/output.txt @@ -1,21 +1,13 @@ -=== 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 +=== 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 8fa8c03f8f7..f704b02f97c 100644 --- a/acceptance/bundle/migrate/auto/envvar/script +++ b/acceptance/bundle/migrate/auto/envvar/script @@ -1,8 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy uses terraform engine" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy -trace print_migration_telemetry +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 new file mode 100644 index 00000000000..3ce9175fa48 --- /dev/null +++ b/acceptance/bundle/migrate/auto/envvar/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "01cad7c2-9ba4-5e4e-0624-f39165c6a547", + "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/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/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/output.txt b/acceptance/bundle/migrate/auto/pipeline-storage-change/output.txt index d5b768da87a..962614d258e 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 +=== 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 @@ -21,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 c673a1071ce..7f1172b1ad2 100644 --- a/acceptance/bundle/migrate/auto/pipeline-storage-change/script +++ b/acceptance/bundle/migrate/auto/pipeline-storage-change/script @@ -6,8 +6,8 @@ cleanup() { } trap cleanup EXIT -title "Deploy the pipeline on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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/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/plan-failure/output.txt b/acceptance/bundle/migrate/auto/plan-failure/output.txt index c5f24186a4d..10ddb654639 100644 --- a/acceptance/bundle/migrate/auto/plan-failure/output.txt +++ b/acceptance/bundle/migrate/auto/plan-failure/output.txt @@ -1,14 +1,8 @@ -=== 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 +=== Replay a prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate >>> print_migration_telemetry -direct_drymigrate_success true -direct_drymigrate_warnings false === Inject GET failure so the plan check blocks the migration >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy @@ -18,7 +12,7 @@ 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... -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/plan-failure/script b/acceptance/bundle/migrate/auto/plan-failure/script index 55369b0aa28..06401f1c331 100644 --- a/acceptance/bundle/migrate/auto/plan-failure/script +++ b/acceptance/bundle/migrate/auto/plan-failure/script @@ -1,7 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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" 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 new file mode 100644 index 00000000000..5f749b73a1d --- /dev/null +++ b/acceptance/bundle/migrate/auto/plan-failure/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "115ec518-3f72-3614-4e56-01411863558a", + "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/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 4fd5003d991..5a121dfe386 100644 --- a/acceptance/bundle/migrate/auto/plan-missing/output.txt +++ b/acceptance/bundle/migrate/auto/plan-missing/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 +=== Replay a prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json 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 @@ -20,12 +16,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 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 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... -Files: 0 uploaded, 0 deleted +Migrated 1 resource to direct deployment engine. +Files: 1 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged diff --git a/acceptance/bundle/migrate/auto/plan-missing/script b/acceptance/bundle/migrate/auto/plan-missing/script index 88deeee43d2..d6721b1ba96 100644 --- a/acceptance/bundle/migrate/auto/plan-missing/script +++ b/acceptance/bundle/migrate/auto/plan-missing/script @@ -1,7 +1,8 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +title "Replay a prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json 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 @@ -13,5 +14,5 @@ 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 to direct" +trace $CLI bundle deploy 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 new file mode 100644 index 00000000000..c281c34587e --- /dev/null +++ b/acceptance/bundle/migrate/auto/plan-missing/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "b0ca93bf-2a4f-d420-021b-c0385fe75d21", + "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/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 30207ed86b4..cea782a12cd 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 +=== Replay a prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json 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 @@ -21,7 +13,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 @@ -36,7 +28,6 @@ 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 diff --git a/acceptance/bundle/migrate/auto/push-failure/script b/acceptance/bundle/migrate/auto/push-failure/script index 58e76ba9574..da3ffaad3d9 100644 --- a/acceptance/bundle/migrate/auto/push-failure/script +++ b/acceptance/bundle/migrate/auto/push-failure/script @@ -1,8 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy -trace print_migration_telemetry +title "Replay a prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate 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/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 new file mode 100644 index 00000000000..0526f00a931 --- /dev/null +++ b/acceptance/bundle/migrate/auto/push-failure/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "4f1f3b2b-ddfb-e225-9c17-a7000030c36b", + "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/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/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/output.txt b/acceptance/bundle/migrate/auto/registered-model-catalog-change/output.txt index b49eb6e3004..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,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 +=== 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 @@ -18,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 48f70c61175..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 "Deploy the model on terraform in catalog 'main'" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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 new file mode 100644 index 00000000000..3cf5038c0ba --- /dev/null +++ b/acceptance/bundle/migrate/auto/registered-model-catalog-change/terraform.tfstate @@ -0,0 +1,45 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "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": { + "aliases": [], + "browse_only": false, + "catalog_name": "main", + "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-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/output.txt b/acceptance/bundle/migrate/auto/registered-model-rename/output.txt index f374e9dcb16..fbad32d54f3 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 +=== 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 @@ -14,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 e1278fab249..0b81939d6d4 100644 --- a/acceptance/bundle/migrate/auto/registered-model-rename/script +++ b/acceptance/bundle/migrate/auto/registered-model-rename/script @@ -6,8 +6,8 @@ cleanup() { } trap cleanup EXIT -title "Deploy the schema and registered model on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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/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/run-no-commit/output.txt b/acceptance/bundle/migrate/auto/run-no-commit/output.txt index 8c2bf28a470..950329c8541 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 +=== 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 @@ -21,6 +17,4 @@ Run URL: [DATABRICKS_URL]/jobs/[NUMID]/runs/[NUMID]?o=[NUMID] >>> 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/run-no-commit/script b/acceptance/bundle/migrate/auto/run-no-commit/script index c1e275ff819..4d65ccbf135 100644 --- a/acceptance/bundle/migrate/auto/run-no-commit/script +++ b/acceptance/bundle/migrate/auto/run-no-commit/script @@ -1,7 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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 new file mode 100644 index 00000000000..a9a79a3d5e1 --- /dev/null +++ b/acceptance/bundle/migrate/auto/run-no-commit/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "4d00d92b-65ae-9e2c-2027-3c140eafb60b", + "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/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 +} 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/output.txt b/acceptance/bundle/migrate/auto/schema-catalog-change/output.txt index 388e7977655..5295feaa2e9 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 +=== 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 @@ -24,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 52aa01327d2..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 "Deploy the schema on terraform in catalog 'main'" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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 new file mode 100644 index 00000000000..f303e9926c0 --- /dev/null +++ b/acceptance/bundle/migrate/auto/schema-catalog-change/terraform.tfstate @@ -0,0 +1,41 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "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": { + "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-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/output.txt b/acceptance/bundle/migrate/auto/schema-name-normalized/output.txt index 301f156c314..cdfe47510ee 100644 --- a/acceptance/bundle/migrate/auto/schema-name-normalized/output.txt +++ b/acceptance/bundle/migrate/auto/schema-name-normalized/output.txt @@ -1,17 +1,13 @@ -=== 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 +=== 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 72607f2d689..442b762ee9d 100644 --- a/acceptance/bundle/migrate/auto/schema-name-normalized/script +++ b/acceptance/bundle/migrate/auto/schema-name-normalized/script @@ -11,8 +11,8 @@ trap cleanup EXIT # treats a case-only difference as backend normalization and keeps the config value, so the # migration proceeds with no warning and the plan converges. -title "Deploy on terraform; UC lowercases the schema name" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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/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/output.txt b/acceptance/bundle/migrate/auto/schema-rename/output.txt index 3b81286a990..65e060f08f9 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 +=== 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 @@ -19,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 e5b93830f28..2286ccca1b2 100644 --- a/acceptance/bundle/migrate/auto/schema-rename/script +++ b/acceptance/bundle/migrate/auto/schema-rename/script @@ -6,8 +6,8 @@ cleanup() { } trap cleanup EXIT -title "Deploy the schema on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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/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/schema-storage-change/output.txt b/acceptance/bundle/migrate/auto/schema-storage-change/output.txt index 6201c860667..0902960a2a8 100644 --- a/acceptance/bundle/migrate/auto/schema-storage-change/output.txt +++ b/acceptance/bundle/migrate/auto/schema-storage-change/output.txt @@ -1,14 +1,8 @@ -=== 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 +=== Replay the prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate >>> print_migration_telemetry -direct_drymigrate_success true -direct_drymigrate_warnings false === Change immutable storage_root; without --auto-approve the recreate is refused >>> DATABRICKS_BUNDLE_ENGINE=direct errcode [CLI] bundle deploy @@ -36,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 [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 diff --git a/acceptance/bundle/migrate/auto/schema-storage-change/script b/acceptance/bundle/migrate/auto/schema-storage-change/script index 5c793b9d929..c0ab15856de 100644 --- a/acceptance/bundle/migrate/auto/schema-storage-change/script +++ b/acceptance/bundle/migrate/auto/schema-storage-change/script @@ -4,8 +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 +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" 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 new file mode 100644 index 00000000000..90a6b74d9e4 --- /dev/null +++ b/acceptance/bundle/migrate/auto/schema-storage-change/terraform.tfstate @@ -0,0 +1,41 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "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": { + "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 2a05926d403..ccb8f6f49fa 100644 --- a/acceptance/bundle/migrate/auto/schema-storage-normalized/output.txt +++ b/acceptance/bundle/migrate/auto/schema-storage-normalized/output.txt @@ -1,17 +1,13 @@ -=== 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 +=== 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 ad6ccc2bb64..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 "Deploy on terraform; UC strips the trailing slash from storage_root" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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 new file mode 100644 index 00000000000..306b3eae42c --- /dev/null +++ b/acceptance/bundle/migrate/auto/schema-storage-normalized/terraform.tfstate @@ -0,0 +1,41 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "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": { + "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/tfbackup-failure/output.txt b/acceptance/bundle/migrate/auto/tfbackup-failure/output.txt index ff2808ee6cb..4a633e7d7d2 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 +=== Replay a prior terraform deployment (captured from a real terraform run) +>>> replay_tfstate.py terraform-requests.json terraform.tfstate === Opt in via env var; inject 403 on the DELETE of remote terraform.tfstate >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy @@ -16,7 +8,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 11a74c93106..b2d2d9a6618 100644 --- a/acceptance/bundle/migrate/auto/tfbackup-failure/script +++ b/acceptance/bundle/migrate/auto/tfbackup-failure/script @@ -1,8 +1,7 @@ export DATABRICKS_BUNDLE_ENGINE= -title "Initial deploy on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy -trace print_migration_telemetry +title "Replay a prior terraform deployment (captured from a real terraform run)" +trace replay_tfstate.py terraform-requests.json terraform.tfstate 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/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 new file mode 100644 index 00000000000..99e62630467 --- /dev/null +++ b/acceptance/bundle/migrate/auto/tfbackup-failure/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "0b9afba9-af0a-a76d-c3b1-2d81b54bdc14", + "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/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 +} 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/output.txt b/acceptance/bundle/migrate/auto/volume-name-normalized/output.txt index 9730b1ffc61..38b0ebc578c 100644 --- a/acceptance/bundle/migrate/auto/volume-name-normalized/output.txt +++ b/acceptance/bundle/migrate/auto/volume-name-normalized/output.txt @@ -1,17 +1,13 @@ -=== 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 +=== 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 c9a14dab412..6714d068191 100644 --- a/acceptance/bundle/migrate/auto/volume-name-normalized/script +++ b/acceptance/bundle/migrate/auto/volume-name-normalized/script @@ -11,8 +11,8 @@ trap cleanup EXIT # case-only difference as backend normalization and keeps the config value, so the migration # proceeds with no warning and the plan converges. -title "Deploy on terraform; UC lowercases the volume name" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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/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/output.txt b/acceptance/bundle/migrate/auto/volume-rename/output.txt index 477b35d68c3..762538efab5 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 +=== 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 @@ -14,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 9d2a5f62f09..5ef772365b7 100644 --- a/acceptance/bundle/migrate/auto/volume-rename/script +++ b/acceptance/bundle/migrate/auto/volume-rename/script @@ -6,8 +6,8 @@ cleanup() { } trap cleanup EXIT -title "Deploy the schema and volume on terraform" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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/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 = [ diff --git a/acceptance/bundle/migrate/auto/volume-type-change/output.txt b/acceptance/bundle/migrate/auto/volume-type-change/output.txt index 9c4a10b92fc..40989888210 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 +=== 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 26b253f2d59..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 "Deploy on terraform with volume_type MANAGED" -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +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 new file mode 100644 index 00000000000..16923e4f957 --- /dev/null +++ b/acceptance/bundle/migrate/auto/volume-type-change/terraform.tfstate @@ -0,0 +1,39 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "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": { + "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 +} diff --git a/acceptance/bundle/migrate/command/added-direct-only/output.txt b/acceptance/bundle/migrate/command/added-direct-only/output.txt index b9042b01cc3..21ea762043c 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 +=== 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 without deploying it >>> 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 diff --git a/acceptance/bundle/migrate/command/added-direct-only/script b/acceptance/bundle/migrate/command/added-direct-only/script index e500a603b6d..93627e50a2c 100644 --- a/acceptance/bundle/migrate/command/added-direct-only/script +++ b/acceptance/bundle/migrate/command/added-direct-only/script @@ -1,14 +1,11 @@ -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 +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 without deploying it" 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 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 new file mode 100644 index 00000000000..ce20cbf8f0d --- /dev/null +++ b/acceptance/bundle/migrate/command/added-direct-only/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "fa49fd4c-1db2-384e-33d4-1cc1d0302360", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_a", + "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/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 99fad42f750..e6e923c42c5 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 +>>> 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 diff --git a/acceptance/bundle/migrate/command/added/script b/acceptance/bundle/migrate/command/added/script index 78846a084bf..11ddfaf9b1f 100644 --- a/acceptance/bundle/migrate/command/added/script +++ b/acceptance/bundle/migrate/command/added/script @@ -1,7 +1,7 @@ -export DATABRICKS_BUNDLE_ENGINE=terraform +export DATABRICKS_BUNDLE_ENGINE= -# Deploy with terraform (only job_a; job_b is commented out) -trace $CLI bundle deploy +# 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" 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 new file mode 100644 index 00000000000..42841842794 --- /dev/null +++ b/acceptance/bundle/migrate/command/added/terraform.tfstate @@ -0,0 +1,110 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "98692851-b674-5437-4c69-326971c0e8b2", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_a", + "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-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/output.txt b/acceptance/bundle/migrate/command/basic/output.txt index 255894ca479..06ac288cbf3 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 +>>> 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 @@ -27,14 +21,6 @@ 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 @@ -74,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: 0 uploaded, 0 deleted +Files: 3 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 3 unchanged >>> print_requests.py --get //jobs/get @@ -112,18 +98,11 @@ 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 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 +=== 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 >>> 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]" diff --git a/acceptance/bundle/migrate/command/basic/script b/acceptance/bundle/migrate/command/basic/script index a9944a5a4d8..9922da55b67 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 +# 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' @@ -14,10 +21,6 @@ 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 @@ -46,8 +49,8 @@ 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 +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 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 new file mode 100644 index 00000000000..719e04658d2 --- /dev/null +++ b/acceptance/bundle/migrate/command/basic/terraform-prod.tfstate @@ -0,0 +1,326 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "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": { + "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 new file mode 100644 index 00000000000..79c34bc74b7 --- /dev/null +++ b/acceptance/bundle/migrate/command/basic/terraform.tfstate @@ -0,0 +1,291 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 4, + "lineage": "4b4ef315-59d3-0f6e-900a-27ab3918bd54", + "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/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_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/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_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-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/output.txt b/acceptance/bundle/migrate/command/dashboards/output.txt index a5960b911f5..306d160ea38 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 +>>> 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 @@ -15,14 +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=terraform [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 @@ -35,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: 1 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/dashboards/script b/acceptance/bundle/migrate/command/dashboards/script index 68fc6883eb3..eb983cb8197 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 +# 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 @@ -6,9 +7,6 @@ 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 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 new file mode 100644 index 00000000000..65fdb7316c4 --- /dev/null +++ b/acceptance/bundle/migrate/command/dashboards/terraform.tfstate @@ -0,0 +1,47 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "25d594e8-e1e8-2d7b-3515-d9e97d6cb02a", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_dashboard", + "name": "dashboard1", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "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", + "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/output.txt b/acceptance/bundle/migrate/command/default-python/output.txt index 14fc40642c7..9a3bc0c6689 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 +>>> replay_tfstate.py ../terraform-requests.json ../terraform.tfstate -t dev >>> 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" } ] [ @@ -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", @@ -157,7 +150,7 @@ 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 @@ -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..7f5a1078a20 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 +# 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 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 new file mode 100644 index 00000000000..aefa65b1866 --- /dev/null +++ b/acceptance/bundle/migrate/command/default-python/terraform.tfstate @@ -0,0 +1,498 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 3, + "lineage": "ec477bfd-db39-0f7c-fb69-9c40fa7736dd", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "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/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" + ] + } + ] + }, + { + "mode": "managed", + "type": "databricks_pipeline", + "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": "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/output.txt b/acceptance/bundle/migrate/command/grants/output.txt index c83d3d548be..bd4d8df3fa5 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 +>>> 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 @@ -20,14 +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=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 @@ -38,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: 0 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/grants/script b/acceptance/bundle/migrate/command/grants/script index f53b567d1e2..153af1a1aa9 100755 --- a/acceptance/bundle/migrate/command/grants/script +++ b/acceptance/bundle/migrate/command/grants/script @@ -1,13 +1,11 @@ export DATABRICKS_BUNDLE_ENGINE= -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +# 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 -# 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 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 new file mode 100644 index 00000000000..14b1d3ed46f --- /dev/null +++ b/acceptance/bundle/migrate/command/grants/terraform.tfstate @@ -0,0 +1,265 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 7, + "lineage": "fbb98d27-f582-d0ce-a226-c73269dcf1ea", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_grants", + "name": "registered_model_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": "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_grants", + "name": "schema_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": 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_grants", + "name": "volume_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": [ + "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_registered_model", + "name": "my_registered_model", + "provider": "provider[\"registry.terraform.io/databricks/databricks\"]", + "instances": [ + { + "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_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.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_volume", + "name": "my_volume", + "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": "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/permissions/output.txt b/acceptance/bundle/migrate/command/permissions/output.txt index ce6d0272e4e..182946cfffc 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 +>>> 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 @@ -52,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: 2 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/permissions/script b/acceptance/bundle/migrate/command/permissions/script index f2ef76cc34d..75dcd39490b 100755 --- a/acceptance/bundle/migrate/command/permissions/script +++ b/acceptance/bundle/migrate/command/permissions/script @@ -1,4 +1,8 @@ -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +# 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' 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 new file mode 100644 index 00000000000..a1561224071 --- /dev/null +++ b/acceptance/bundle/migrate/command/permissions/terraform.tfstate @@ -0,0 +1,387 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 5, + "lineage": "a0fc6106-3686-738c-7a93-06c0a226574f", + "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/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_permissions", + "name": "job_test_job", + "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": "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": "pipeline_test_pipeline", + "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": "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_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/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 +} diff --git a/acceptance/bundle/migrate/command/profile_arg/output.txt b/acceptance/bundle/migrate/command/profile_arg/output.txt index 01cb9b893c4..dfa1e9b41dd 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 +>>> 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 @@ -15,12 +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/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 +>>> replay_tfstate.py terraform-prod-requests.json 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 diff --git a/acceptance/bundle/migrate/command/profile_arg/script b/acceptance/bundle/migrate/command/profile_arg/script index 9e3c242cf1e..c8f07b32272 100755 --- a/acceptance/bundle/migrate/command/profile_arg/script +++ b/acceptance/bundle/migrate/command/profile_arg/script @@ -1,7 +1,10 @@ -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +# 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 -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy -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 new file mode 100644 index 00000000000..6e0e3b0f53c --- /dev/null +++ b/acceptance/bundle/migrate/command/profile_arg/terraform-prod.tfstate @@ -0,0 +1,200 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "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": { + "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 new file mode 100644 index 00000000000..4746fa35538 --- /dev/null +++ b/acceptance/bundle/migrate/command/profile_arg/terraform.tfstate @@ -0,0 +1,169 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "25eb53a2-0b56-1698-68f5-f1eff6417572", + "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/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 0450ff7b7aa..948e659773e 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 +>>> 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 diff --git a/acceptance/bundle/migrate/command/removed/script b/acceptance/bundle/migrate/command/removed/script index 9e53c7991b6..01a5d745c31 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 +# 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 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 new file mode 100644 index 00000000000..6a8ad85c9a1 --- /dev/null +++ b/acceptance/bundle/migrate/command/removed/terraform.tfstate @@ -0,0 +1,210 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 1, + "lineage": "37f6c843-91a5-3d5c-457c-2c43d9630444", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_job", + "name": "job_a", + "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-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==" + } + ] + }, + { + "mode": "managed", + "type": "databricks_job", + "name": "job_b", + "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-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 2a195b271c4..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": [ - "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" + "replay_tfstate.py" ] }, "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" + "replay_tfstate.py" ] }, "method": "PUT", diff --git a/acceptance/bundle/migrate/command/runas/output.txt b/acceptance/bundle/migrate/command/runas/output.txt index acc0bd399a9..c17ffdec425 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 +>>> replay_tfstate.py terraform-requests.json terraform.tfstate -t production >>> print_requests.py //pipelines @@ -55,21 +20,6 @@ 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 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..d90cf2235aa 100644 --- a/acceptance/bundle/migrate/command/runas/script +++ b/acceptance/bundle/migrate/command/runas/script @@ -3,7 +3,6 @@ if [ -z "${TEST_SP_APPLICATION_ID+x}" ]; then fi envsubst < databricks.yml.tmpl > databricks.yml -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle plan cleanup() { trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle destroy --auto-approve @@ -12,14 +11,14 @@ cleanup() { trap cleanup EXIT -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +# 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=$(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 DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle plan trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle deployment migrate trace print_state.py > out.new_state.json trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle plan 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 new file mode 100644 index 00000000000..8b3c0b6ec3d --- /dev/null +++ b/acceptance/bundle/migrate/command/runas/terraform.tfstate @@ -0,0 +1,166 @@ +{ + "version": 4, + "terraform_version": "1.5.5", + "serial": 3, + "lineage": "077aa86d-dff4-9481-ecbe-357801f46445", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "databricks_permissions", + "name": "pipeline_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": "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_pipeline", + "name": "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": "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 620f8994f9b..1280cf619da 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 +>>> 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 @@ -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 +>>> 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 722b0527f86..5036336a424 100644 --- a/acceptance/bundle/migrate/command/var_arg/script +++ b/acceptance/bundle/migrate/command/var_arg/script @@ -1,4 +1,5 @@ -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy --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 DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle plan --var="job_name=Custom Job Name" | contains.py "1 unchanged" @@ -7,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 -# Deploy with Terraform using a variable -trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy --var "job_name=Custom Job Name" +# 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-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 new file mode 100644 index 00000000000..434dbe1f911 --- /dev/null +++ b/acceptance/bundle/migrate/command/var_arg/terraform.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/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 = [""]