Skip to content

Commit 33fadff

Browse files
denikpietern
andauthored
Add "bundle deployment migrate" command (#3847)
## Changes New migrate command to convert terraform state to direct engine state. Depends on #3875 ## Tests Acceptance tests. Extended print_state.py utility to accept -t/--target and --backup args. --------- Co-authored-by: Pieter Noordhuis <[email protected]>
1 parent 5db4531 commit 33fadff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2347
-46
lines changed

acceptance/bin/print_state.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99
import os
10+
import argparse
1011

1112

1213
def write(filename):
@@ -16,10 +17,30 @@ def write(filename):
1617
print()
1718

1819

19-
filename = ".databricks/bundle/default/terraform/terraform.tfstate"
20-
if os.path.exists(filename):
21-
write(filename)
20+
def main():
21+
parser = argparse.ArgumentParser()
22+
parser.add_argument("-t", "--target", default="default")
23+
parser.add_argument("--backup", action="store_true")
24+
args = parser.parse_args()
2225

23-
filename = ".databricks/bundle/default/resources.json"
24-
if os.path.exists(filename):
25-
write(filename)
26+
if args.target:
27+
target_dir = f".databricks/bundle/{args.target}"
28+
if not os.path.exists(target_dir):
29+
raise SystemExit(f"Invalid target {args.target!r}: {target_dir} does not exist")
30+
31+
if args.backup:
32+
filename = f".databricks/bundle/{args.target}/terraform/terraform.tfstate.backup"
33+
if os.path.exists(filename):
34+
write(filename)
35+
else:
36+
filename = f".databricks/bundle/{args.target}/terraform/terraform.tfstate"
37+
if os.path.exists(filename):
38+
write(filename)
39+
40+
filename = f".databricks/bundle/{args.target}/resources.json"
41+
if os.path.exists(filename):
42+
write(filename)
43+
44+
45+
if __name__ == "__main__":
46+
main()

acceptance/bundle/help/bundle-deployment-migrate/out.test.toml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
>>> [CLI] bundle deployment migrate --help
3+
This command converts your bundle from using Terraform for deployment to using
4+
the Direct deployment engine. It reads resource IDs from the existing Terraform
5+
state and creates a Direct deployment state file (resources.json) with the same
6+
lineage and incremented serial number.
7+
8+
Note, the migration is performed locally only. To finalize it, run 'bundle deploy'. This will synchronize the state file
9+
to the workspace so that subsequent deploys of this bundle use direct deployment engine as well.
10+
11+
WARNING: Both direct deployment engine and this command are experimental and not recommended for production targets yet.
12+
13+
Usage:
14+
databricks bundle deployment migrate [flags]
15+
16+
Flags:
17+
-h, --help help for migrate
18+
19+
Global Flags:
20+
--debug enable debug logging
21+
-o, --output type output type: text or json (default text)
22+
-p, --profile string ~/.databrickscfg profile
23+
-t, --target string bundle target to use (if applicable)
24+
--var strings set values for variables defined in bundle config. Example: --var="foo=bar"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trace $CLI bundle deployment migrate --help

acceptance/bundle/help/bundle-deployment/output.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Usage:
2121

2222
Available Commands:
2323
bind Bind bundle-defined resources to existing resources
24+
migrate Migrate from Terraform to Direct deployment engine
2425
unbind Unbind bundle-defined resources from its managed remote resource
2526

2627
Flags:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
bundle:
2+
name: migrate-basic-test
3+
4+
resources:
5+
jobs:
6+
test_job:
7+
name: "Test Migration Job"
8+
tasks:
9+
- task_key: "main"
10+
notebook_task:
11+
notebook_path: "./notebook.py"
12+
volumes:
13+
test_volume:
14+
catalog_name: "mycat"
15+
schema_name: "myschema"
16+
name: "myvol"
17+
18+
pipelines:
19+
test_pipeline:
20+
name: "Test Migration Pipeline"
21+
tags:
22+
# ids
23+
myjob_id: ${resources.jobs.test_job.id}
24+
myvolume_id: ${resources.volumes.test_volume.id}
25+
26+
# local field, string:
27+
myjob_name: ${resources.jobs.test_job.name}
28+
volume_catalog_name: ${resources.volumes.test_volume.catalog_name}
29+
30+
# remote field, int, null
31+
myjob_timeout: ${resources.jobs.test_job.timeout_seconds}
32+
33+
# remote field, string:
34+
volume_storage_location: ${resources.volumes.test_volume.storage_location}
35+
libraries:
36+
- notebook:
37+
path: "./pipeline.py"
38+
39+
targets:
40+
dev:
41+
default: true
42+
prod:
43+
resources:
44+
schemas:
45+
test_schema:
46+
catalog_name: mycat
47+
name: myschema
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Databricks notebook source
2+
print("Hello from test migration job")
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"lineage": "[UUID]",
3+
"serial": 5,
4+
"state": {
5+
"resources.jobs.test_job": {
6+
"__id__": "[NUMID]",
7+
"state": {
8+
"deployment": {
9+
"kind": "BUNDLE",
10+
"metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/state/metadata.json"
11+
},
12+
"edit_mode": "UI_LOCKED",
13+
"format": "MULTI_TASK",
14+
"max_concurrent_runs": 1,
15+
"name": "Test Migration Job",
16+
"queue": {
17+
"enabled": true
18+
},
19+
"tasks": [
20+
{
21+
"notebook_task": {
22+
"notebook_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files/notebook"
23+
},
24+
"task_key": "main"
25+
}
26+
]
27+
}
28+
},
29+
"resources.pipelines.test_pipeline": {
30+
"__id__": "[UUID]",
31+
"state": {
32+
"channel": "CURRENT",
33+
"deployment": {
34+
"kind": "BUNDLE",
35+
"metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/state/metadata.json"
36+
},
37+
"edition": "ADVANCED",
38+
"libraries": [
39+
{
40+
"notebook": {
41+
"path": "/Workspace/Users/[USERNAME]/.bundle/migrate-basic-test/dev/files/pipeline"
42+
}
43+
}
44+
],
45+
"name": "Test Migration Pipeline",
46+
"tags": {
47+
"myjob_id": "[NUMID]",
48+
"myjob_name": "Test Migration Job",
49+
"myjob_timeout": "",
50+
"myvolume_id": "mycat.myschema.myvol",
51+
"volume_catalog_name": "mycat",
52+
"volume_storage_location": "s3://deco-uc-prod-isolated-aws-us-east-1/metastore/[UUID]/volumes/[UUID]"
53+
}
54+
}
55+
},
56+
"resources.volumes.test_volume": {
57+
"__id__": "mycat.myschema.myvol",
58+
"state": {
59+
"catalog_name": "mycat",
60+
"name": "myvol",
61+
"schema_name": "myschema",
62+
"volume_type": "MANAGED"
63+
}
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)