Skip to content

Commit c496214

Browse files
authored
Proactively create the resource path for dashboards (#4608)
## Changes Proactively create the resource path for dashboards ## Why Previously, we relied on TF implementation to create it, but it can be fragile (for example, an API response message can change, and the path won't be created). Explicitly creating it in DABs makes it more resilient. ## Tests Existing tests pass <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 8ebc0f9 commit c496214

7 files changed

Lines changed: 29 additions & 67 deletions

File tree

acceptance/bundle/resources/dashboards/change-embed-credentials/out.post.requests.txt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
{
2-
"method": "POST",
3-
"path": "/api/2.0/lakeview/dashboards",
4-
"body": {
5-
"display_name": "test dashboard",
6-
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/change-embed-credentials-[UNIQUE_NAME]/default/resources",
7-
"serialized_dashboard": "{}\n",
8-
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
9-
}
10-
}
111
{
122
"method": "POST",
133
"path": "/api/2.0/workspace/mkdirs",
@@ -33,6 +23,13 @@
3323
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
3424
}
3525
}
26+
{
27+
"method": "POST",
28+
"path": "/api/2.0/workspace/mkdirs",
29+
"body": {
30+
"path": "/Workspace/Users/[USERNAME]/.bundle/change-embed-credentials-[UNIQUE_NAME]/default/resources"
31+
}
32+
}
3633
{
3734
"method": "POST",
3835
"path": "/api/2.0/lakeview/dashboards/[DASHBOARD_ID]/published",

acceptance/bundle/resources/dashboards/change-name/out.post.requests.txt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
{
2-
"method": "POST",
3-
"path": "/api/2.0/lakeview/dashboards",
4-
"body": {
5-
"display_name": "dashboard1",
6-
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/change-name-[UNIQUE_NAME]/default/resources",
7-
"serialized_dashboard": "{}\n",
8-
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
9-
}
10-
}
111
{
122
"method": "POST",
133
"path": "/api/2.0/workspace/mkdirs",
@@ -33,6 +23,13 @@
3323
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
3424
}
3525
}
26+
{
27+
"method": "POST",
28+
"path": "/api/2.0/workspace/mkdirs",
29+
"body": {
30+
"path": "/Workspace/Users/[USERNAME]/.bundle/change-name-[UNIQUE_NAME]/default/resources"
31+
}
32+
}
3633
{
3734
"method": "POST",
3835
"path": "/api/2.0/lakeview/dashboards/[DASHBOARD_ID]/published",

acceptance/bundle/resources/dashboards/change-parent-path/out.dashboardrequests.txt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
{
2-
"method": "POST",
3-
"path": "/api/2.0/lakeview/dashboards",
4-
"body": {
5-
"display_name": "test dashboard",
6-
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/change-parent-path-[UNIQUE_NAME]/default/resources",
7-
"serialized_dashboard": "{}\n",
8-
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
9-
}
10-
}
111
{
122
"method": "POST",
133
"path": "/api/2.0/workspace/mkdirs",
@@ -33,6 +23,13 @@
3323
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
3424
}
3525
}
26+
{
27+
"method": "POST",
28+
"path": "/api/2.0/workspace/mkdirs",
29+
"body": {
30+
"path": "/Workspace/Users/[USERNAME]/.bundle/change-parent-path-[UNIQUE_NAME]/default/resources"
31+
}
32+
}
3633
{
3734
"method": "DELETE",
3835
"path": "/api/2.0/lakeview/dashboards/[ORIGINAL_DASHBOARD_ID]"

acceptance/bundle/resources/dashboards/change-serialized-dashboard/out.post.requests.txt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
{
2-
"method": "POST",
3-
"path": "/api/2.0/lakeview/dashboards",
4-
"body": {
5-
"display_name": "test dashboard",
6-
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/change-serialized-dashboard-[UNIQUE_NAME]/default/resources",
7-
"serialized_dashboard": "{\"pages\":[{\"name\":\"name1\",\"displayName\":\"name1\",\"pageType\":\"PAGE_TYPE_CANVAS\"}]}\n",
8-
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
9-
}
10-
}
111
{
122
"method": "POST",
133
"path": "/api/2.0/workspace/mkdirs",
@@ -33,6 +23,13 @@
3323
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
3424
}
3525
}
26+
{
27+
"method": "POST",
28+
"path": "/api/2.0/workspace/mkdirs",
29+
"body": {
30+
"path": "/Workspace/Users/[USERNAME]/.bundle/change-serialized-dashboard-[UNIQUE_NAME]/default/resources"
31+
}
32+
}
3633
{
3734
"method": "POST",
3835
"path": "/api/2.0/lakeview/dashboards/[DASHBOARD_ID]/published",

acceptance/bundle/resources/dashboards/detect-change/out.post.requests.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
99
}
1010
}
11-
{
12-
"method": "POST",
13-
"path": "/api/2.0/lakeview/dashboards",
14-
"body": {
15-
"display_name": "test-dashboard-[UNIQUE_NAME]",
16-
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/resources",
17-
"serialized_dashboard": "{\n \"pages\": [\n {\n \"displayName\": \"New Page\",\n \"layout\": [\n {\n \"position\": {\n \"height\": 2,\n \"width\": 6,\n \"x\": 0,\n \"y\": 0\n },\n \"widget\": {\n \"name\": \"82eb9107\",\n \"textbox_spec\": \"# I'm a title\"\n }\n },\n {\n \"position\": {\n \"height\": 2,\n \"width\": 6,\n \"x\": 0,\n \"y\": 2\n },\n \"widget\": {\n \"name\": \"ffa6de4f\",\n \"textbox_spec\": \"Text\"\n }\n }\n ],\n \"name\": \"fdd21a3c\"\n }\n ]\n}\n",
18-
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
19-
}
20-
}
2111
{
2212
"method": "POST",
2313
"path": "/api/2.0/lakeview/dashboards/[DASHBOARD_ID]/published",

acceptance/bundle/resources/dashboards/publish-failure-cleans-up-dashboard/out.dashboardrequests.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212
"path": "/Workspace/Users/[USERNAME]/.bundle/publish-failure-cleans-up-dashboard/default/files"
1313
}
1414
}
15-
{
16-
"method": "POST",
17-
"path": "/api/2.0/lakeview/dashboards",
18-
"body": {
19-
"display_name": "my dashboard",
20-
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/publish-failure-cleans-up-dashboard/default/resources",
21-
"serialized_dashboard": "{\"pages\":[{\"name\":\"test-page\",\"displayName\":\"Test Dashboard\"}]}\n",
22-
"warehouse_id": "doesnotexist"
23-
}
24-
}
2515
{
2616
"method": "POST",
2717
"path": "/api/2.0/workspace/mkdirs",

bundle/deploy/resource_path_mkdir.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ func (m *resourcePathMkdir) Name() string {
2121

2222
func (m *resourcePathMkdir) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
2323
// Only dashboards and alerts need ${workspace.resource_path} to exist.
24-
//
25-
// We'll defer to TF to create resource_path for for dashboards.
26-
// ref: https://github.com/databricks/terraform-provider-databricks/blob/d84bc6f28d8aa0fd77d110a41f745970299142b1/dashboards/resource_dashboard.go#L83.
27-
//
28-
// For alerts we proactively create it here because the TF implementation
29-
// is autogenerated and cannot be easily customized.
30-
if len(b.Config.Resources.Alerts) == 0 {
24+
if len(b.Config.Resources.Alerts) == 0 && len(b.Config.Resources.Dashboards) == 0 {
3125
return nil
3226
}
3327

0 commit comments

Comments
 (0)