Skip to content

Commit e1a9c36

Browse files
authored
direct: apps: support deletes (#3485)
## Changes Implement missing delete functionality for apps on direct. ## Tests Existing tests extend to destroy bundle, recreate an app.
1 parent 5053e0e commit e1a9c36

File tree

5 files changed

+152
-7
lines changed

5 files changed

+152
-7
lines changed

acceptance/bundle/apps/app_yaml/output.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,28 @@ Workspace:
88

99
Validation OK!
1010

11+
>>> [CLI] bundle plan
12+
create apps.myapp
13+
1114
>>> [CLI] bundle deploy
1215
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
1316
Deploying resources...
1417
Updating deployment state...
1518
Deployment complete!
19+
20+
>>> jq select(.path | test("app.yml")) out.requests.txt
21+
22+
>>> [CLI] bundle destroy --auto-approve
23+
The following resources will be deleted:
24+
delete app myapp
25+
26+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
27+
28+
Deleting files...
29+
Destroy complete!
30+
31+
>>> print_requests
32+
{
33+
"method": "DELETE",
34+
"path": "/api/2.0/apps/myapp"
35+
}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
print_requests() {
2+
jq --sort-keys 'select(.method != "GET" and (.path | contains("/apps")))' < out.requests.txt
3+
rm out.requests.txt
4+
}
5+
16
trace $CLI bundle validate
7+
trace $CLI bundle plan
28
trace $CLI bundle deploy
3-
jq 'select(.path | test("app.yml"))' out.requests.txt | sed 's/\\r//g' > out.app.yml.txt
9+
trace jq 'select(.path | test("app.yml"))' out.requests.txt | sed 's/\\r//g' > out.app.yml.txt
10+
#trace print_requests # currently fails due to TF inserting description=""
411
rm out.requests.txt
12+
13+
trace $CLI bundle destroy --auto-approve
14+
trace print_requests

acceptance/bundle/resources/apps/output.txt

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
>>> [CLI] bundle plan
3+
create apps.myapp
4+
25
>>> [CLI] bundle deploy
36
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
47
Deploying resources...
@@ -14,11 +17,25 @@ Deployment complete!
1417
"method": "POST",
1518
"path": "/api/2.0/apps"
1619
}
17-
apps myapp name='myapp' description='my_app_description'
20+
21+
>>> [CLI] bundle summary
22+
Name: test-bundle
23+
Target: default
24+
Workspace:
25+
User: [USERNAME]
26+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
27+
Resources:
28+
Apps:
29+
myapp:
30+
Name: myapp
31+
URL: (not deployed)
1832

1933
=== Update description and re-deploy
2034
>>> update_file.py databricks.yml my_app_description MY_APP_DESCRIPTION
2135

36+
>>> [CLI] bundle plan
37+
update apps.myapp
38+
2239
>>> [CLI] bundle deploy
2340
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
2441
Deploying resources...
@@ -34,4 +51,88 @@ Deployment complete!
3451
"method": "PATCH",
3552
"path": "/api/2.0/apps/myapp"
3653
}
37-
apps myapp name='myapp' description='MY_APP_DESCRIPTION'
54+
55+
>>> [CLI] bundle summary
56+
Name: test-bundle
57+
Target: default
58+
Workspace:
59+
User: [USERNAME]
60+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
61+
Resources:
62+
Apps:
63+
myapp:
64+
Name: myapp
65+
URL: (not deployed)
66+
67+
=== Update name and re-deploy
68+
>>> update_file.py databricks.yml myapp mynewapp
69+
70+
>>> [CLI] bundle plan
71+
delete apps.myapp
72+
create apps.mynewapp
73+
74+
>>> [CLI] bundle summary
75+
Name: test-bundle
76+
Target: default
77+
Workspace:
78+
User: [USERNAME]
79+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
80+
Resources:
81+
Apps:
82+
myapp:
83+
Name: myapp
84+
URL: [DATABRICKS_URL]/apps/myapp?o=[NUMID]
85+
mynewapp:
86+
Name: mynewapp
87+
URL: (not deployed)
88+
89+
>>> [CLI] bundle deploy
90+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
91+
Deploying resources...
92+
Updating deployment state...
93+
Deployment complete!
94+
95+
>>> print_requests
96+
{
97+
"body": {},
98+
"method": "DELETE",
99+
"path": "/api/2.0/apps/myapp"
100+
}
101+
{
102+
"body": {
103+
"description": "MY_APP_DESCRIPTION",
104+
"name": "mynewapp"
105+
},
106+
"method": "POST",
107+
"path": "/api/2.0/apps"
108+
}
109+
110+
>>> [CLI] bundle plan
111+
112+
>>> [CLI] bundle summary
113+
Name: test-bundle
114+
Target: default
115+
Workspace:
116+
User: [USERNAME]
117+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
118+
Resources:
119+
Apps:
120+
mynewapp:
121+
Name: mynewapp
122+
URL: (not deployed)
123+
124+
>>> [CLI] bundle destroy --auto-approve
125+
The following resources will be deleted:
126+
delete app mynewapp
127+
128+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
129+
130+
Deleting files...
131+
Destroy complete!
132+
133+
>>> print_requests
134+
{
135+
"body": {},
136+
"method": "DELETE",
137+
"path": "/api/2.0/apps/mynewapp"
138+
}

acceptance/bundle/resources/apps/script

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,26 @@ print_requests() {
44
rm out.requests.txt
55
}
66

7+
trace $CLI bundle plan
78
trace $CLI bundle deploy
89
trace print_requests
9-
read_state.py apps myapp name description
10+
trace $CLI bundle summary
1011

1112
title "Update description and re-deploy"
1213
trace update_file.py databricks.yml my_app_description MY_APP_DESCRIPTION
14+
trace $CLI bundle plan
1315
trace $CLI bundle deploy
1416
trace print_requests
15-
read_state.py apps myapp name description
17+
trace $CLI bundle summary
18+
19+
title "Update name and re-deploy"
20+
trace update_file.py databricks.yml myapp mynewapp
21+
trace $CLI bundle plan
22+
trace $CLI bundle summary
23+
trace $CLI bundle deploy
24+
trace print_requests
25+
26+
trace $CLI bundle plan
27+
trace $CLI bundle summary
28+
trace $CLI bundle destroy --auto-approve
29+
trace print_requests

bundle/terranova/tnresources/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ func (r *ResourceApp) DoUpdate(ctx context.Context, id string) error {
5959
}
6060

6161
func DeleteApp(ctx context.Context, client *databricks.WorkspaceClient, id string) error {
62-
// TODO: implement app deletion
63-
return nil
62+
_, err := client.Apps.DeleteByName(ctx, id)
63+
return err
6464
}
6565

6666
func (r *ResourceApp) WaitAfterCreate(ctx context.Context) error {

0 commit comments

Comments
 (0)