Skip to content

Commit fd7f42b

Browse files
authored
direct: apps: support deletes & recreates (#3485)
## Changes - Implement missing delete functionality for apps on direct. - Set "name" as recreate triggering field. ## Tests Existing tests extend to destroy bundle, recreate an app.
1 parent cd81117 commit fd7f42b

File tree

7 files changed

+156
-12
lines changed

7 files changed

+156
-12
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
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
resources:
22
apps:
3-
myapp:
4-
name: myapp
3+
mykey:
4+
name: myappname
55
description: my_app_description
66
source_code_path: ./app

acceptance/bundle/resources/apps/output.txt

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

2+
>>> [CLI] bundle plan
3+
create apps.mykey
4+
25
>>> [CLI] bundle deploy
36
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
47
Deploying resources...
@@ -9,16 +12,30 @@ Deployment complete!
912
{
1013
"body": {
1114
"description": "my_app_description",
12-
"name": "myapp"
15+
"name": "myappname"
1316
},
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+
mykey:
30+
Name: myappname
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.mykey
38+
2239
>>> [CLI] bundle deploy
2340
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
2441
Deploying resources...
@@ -29,9 +46,89 @@ Deployment complete!
2946
{
3047
"body": {
3148
"description": "MY_APP_DESCRIPTION",
32-
"name": "myapp"
49+
"name": "myappname"
3350
},
3451
"method": "PATCH",
35-
"path": "/api/2.0/apps/myapp"
52+
"path": "/api/2.0/apps/myappname"
53+
}
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+
mykey:
64+
Name: myappname
65+
URL: (not deployed)
66+
67+
=== Update name and re-deploy
68+
>>> update_file.py databricks.yml myappname mynewappname
69+
70+
>>> [CLI] bundle plan
71+
recreate apps.mykey
72+
73+
>>> [CLI] bundle summary
74+
Name: test-bundle
75+
Target: default
76+
Workspace:
77+
User: [USERNAME]
78+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
79+
Resources:
80+
Apps:
81+
mykey:
82+
Name: myappname
83+
URL: (not deployed)
84+
85+
>>> [CLI] bundle deploy
86+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
87+
Deploying resources...
88+
Updating deployment state...
89+
Deployment complete!
90+
91+
>>> print_requests
92+
{
93+
"body": {},
94+
"method": "DELETE",
95+
"path": "/api/2.0/apps/myappname"
96+
}
97+
{
98+
"body": {
99+
"description": "MY_APP_DESCRIPTION",
100+
"name": "mynewappname"
101+
},
102+
"method": "POST",
103+
"path": "/api/2.0/apps"
104+
}
105+
106+
>>> [CLI] bundle plan
107+
108+
>>> [CLI] bundle summary
109+
Name: test-bundle
110+
Target: default
111+
Workspace:
112+
User: [USERNAME]
113+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
114+
Resources:
115+
Apps:
116+
mykey:
117+
Name: mynewappname
118+
URL: (not deployed)
119+
120+
>>> [CLI] bundle destroy --auto-approve
121+
The following resources will be deleted:
122+
delete app mykey
123+
124+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
125+
126+
Deleting files...
127+
Destroy complete!
128+
129+
>>> print_requests
130+
{
131+
"body": {},
132+
"method": "DELETE",
133+
"path": "/api/2.0/apps/mynewappname"
36134
}
37-
apps myapp name='myapp' description='MY_APP_DESCRIPTION'

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 myappname mynewappname
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/resource.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ var SupportedResources = map[string]ResourceSettings{
100100
New: reflect.ValueOf(tnresources.NewResourceApp),
101101
ConfigType: TypeOfConfig(&tnresources.ResourceApp{}),
102102
DeleteFN: tnresources.DeleteApp,
103+
RecreateFields: mkMap(
104+
".name",
105+
),
103106
},
104107
"sql_warehouses": {
105108
New: reflect.ValueOf(tnresources.NewResourceSqlWarehouse),

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)