Skip to content

Commit a3bea05

Browse files
Add validation for required dashboard fields (#3761)
## Summary This PR adds validation to ensure dashboards have both required fields: `display_name` (name) and `warehouse_id`. The validation returns **errors** (not warnings) for missing required fields, preventing deployment until they are added. ## Changes **bundle/config/validate/required.go:** - Split `Apply()` method into two helper functions: - `warnForMissingFields()` - Validates fields based on OpenAPI spec annotations (existing behavior) - `errorForMissingFields()` - Bespoke validation for fields not marked as required in SDK/OpenAPI - Added dashboard-specific validation in `errorForMissingFields()`: - Checks `display_name` is not empty - Checks `warehouse_id` is not empty - Updated `Apply()` to call `errorForMissingFields()` first, then `warnForMissingFields()` ## Why This Change? These fields are marked as required in Terraform: https://github.com/databricks/terraform-provider-databricks/blob/0c0272a8ae678a12e6d7c106245b083d10ba5e07/dashboards/resource_dashboard.go#L33 Adding this here has to benefits: 1. catch missing values without needing to go to Terraform or waiting for deployment. These will surface early during bundle validate. 2. We ensure that these fields remain required for direct deployment. ## Test Coverage New acceptance tests --------- Co-authored-by: Claude <[email protected]>
1 parent e53ca69 commit a3bea05

File tree

20 files changed

+157
-10
lines changed

20 files changed

+157
-10
lines changed

acceptance/bundle/generate/dashboard-inplace/databricks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ resources:
55
dashboards:
66
test_dashboard:
77
display_name: "test dashboard"
8-
warehouse_id: ""
8+
warehouse_id: "my-warehouse-1234"
99
file_path: ./dash.lvdash.json

acceptance/bundle/generate/dashboard-inplace/output.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Deployment complete!
2020
"parent_path":"/Users/[USERNAME]/.bundle/dashboard update inplace/default/resources",
2121
"path":"/Users/[USERNAME]/.bundle/dashboard update inplace/default/resources/test dashboard.lvdash.json",
2222
"serialized_dashboard":"{\"a\":\"b\"}",
23-
"update_time":"[TIMESTAMP]Z"
23+
"update_time":"[TIMESTAMP]Z",
24+
"warehouse_id":"my-warehouse-1234"
2425
}
2526

2627
=== update the dashboard file using bundle generate

acceptance/bundle/sync/databricks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ resources:
22
dashboards:
33
dashboard1:
44
display_name: My dashboard
5+
warehouse_id: "my-warehouse-1234"
56

67
sync:
78
exclude:

acceptance/bundle/sync/dryrun/databricks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ resources:
22
dashboards:
33
dashboard1:
44
display_name: My dashboard
5+
warehouse_id: "my-warehouse-1234"

acceptance/bundle/validate/dashboard_defaults/databricks.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,34 @@ workspace:
44
resources:
55
dashboards:
66
empty_string:
7+
warehouse_id: "my-warehouse-1234"
8+
display_name: "empty-string"
9+
710
# unchanged
811
parent_path: ""
912

1013
non_empty_string:
14+
warehouse_id: "my-warehouse-1234"
15+
display_name: "non-empty-string"
16+
1117
# unchanged
1218
parent_path: "already-set"
1319

1420
other_fields:
21+
warehouse_id: "my-warehouse-1234"
1522
display_name: hello
23+
1624
# parent_path set default
1725

1826
set_to_true:
27+
warehouse_id: "my-warehouse-1234"
28+
display_name: "set-to-true"
29+
1930
embed_credentials: true
2031

21-
completely_empty: {}
32+
neither_parent_path_nor_embed_credentials:
33+
warehouse_id: "my-warehouse-1234"
34+
display_name: "neither-parent-path-nor-embed-credentials"
35+
36+
# parent_path set default
37+
# embed_credentials set default

acceptance/bundle/validate/dashboard_defaults/output.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
{
2-
"completely_empty": {
3-
"embed_credentials": false,
4-
"parent_path": "/Workspace/foo/bar"
5-
},
62
"empty_string": {
73
"embed_credentials": false,
84
"parent_path": ""
95
},
6+
"neither_parent_path_nor_embed_credentials": {
7+
"embed_credentials": false,
8+
"parent_path": "/Workspace/foo/bar"
9+
},
1010
"non_empty_string": {
1111
"embed_credentials": false,
1212
"parent_path": "already-set"
1313
},
1414
"other_fields": {
15-
"display_name": "hello",
1615
"embed_credentials": false,
1716
"parent_path": "/Workspace/foo/bar"
1817
},
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
$CLI bundle validate -o json | jq .resources.dashboards
1+
$CLI bundle validate -o json | jq '.resources.dashboards | map_values({embed_credentials: .embed_credentials, parent_path: .parent_path})'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resources:
2+
dashboards:
3+
# Missing display_name (name)
4+
my_dashboard:
5+
warehouse_id: "test"
6+
serialized_dashboard: "{}"

acceptance/bundle/validate/dashboard_required_name/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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
>>> [CLI] bundle validate
3+
Error: dashboard display_name is required
4+
at resources.dashboards.my_dashboard
5+
in databricks.yml:6:7
6+
7+
Name: test-bundle
8+
Target: default
9+
Workspace:
10+
User: [USERNAME]
11+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
12+
13+
Found 1 error
14+
15+
Exit code: 1

0 commit comments

Comments
 (0)