Skip to content

Commit 739a132

Browse files
Add error for when an etag is specified in dashboard configuration (#3723)
## Changes Users should never set etags in their configuration. It's meant to be a pure internal state. ## Why This validation can potentially help simplify downstream code since we can read etags directly from a merged view of (config + state) and be confident that the etag values come from state. Note: This is not a breaking change since existing users would see errors when they try to update their dashboard if they specified etags in their configuration today: ``` databricks_dashboard.dashboard: Modifying... [id=01f0a29746cd1d1991ae7cc9e6331576] ╷ │ Error: cannot update dashboard: Entity etag provided does not match currently stored etag. Please reload the entity and try the action again. │ │ with databricks_dashboard.dashboard, │ on main.tf line 13, in resource "databricks_dashboard" "dashboard": │ 13: resource "databricks_dashboard" "dashboard" { │ ╵ ``` ## Tests New acceptance test.
1 parent 18cab43 commit 739a132

File tree

7 files changed

+68
-0
lines changed

7 files changed

+68
-0
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
### Bundles
1212
* Fix processing short pip flags in environment dependencies ([#3708](https://github.com/databricks/cli/pull/3708))
1313
* Add support for referencing local files in -e pip flag for environment dependencies ([#3708](https://github.com/databricks/cli/pull/3708))
14+
* Add error for when an etag is specified in dashboard configuration. Setting etags was never supported / valid in bundles but now users will see this error during validation rather than deployment. ([#3723](https://github.com/databricks/cli/pull/3723))
1415
* Fix PIP flag processing in pipeline environment dependencies ([#3734](https://github.com/databricks/cli/pull/3734))
1516

1617
### API Changes
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resources:
2+
dashboards:
3+
foobar:
4+
display_name: foobar
5+
etag: "1234567890"
6+
serialized_dashboard: "{}"

acceptance/bundle/validate/no_dashboard_etag/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 "foobar" has an etag set. Etags must not be set in bundle configuration
4+
at resources.dashboards.foobar
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
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trace $CLI bundle validate
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package validate
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/databricks/cli/bundle"
8+
"github.com/databricks/cli/libs/diag"
9+
"github.com/databricks/cli/libs/dyn"
10+
)
11+
12+
func ValidateDashboardEtags() bundle.ReadOnlyMutator {
13+
return &validateDashboardEtags{}
14+
}
15+
16+
type validateDashboardEtags struct{ bundle.RO }
17+
18+
func (v *validateDashboardEtags) Name() string {
19+
return "validate:validate_dashboard_etags"
20+
}
21+
22+
func (v *validateDashboardEtags) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
23+
// No dashboards should have etags set. They are purely internal state.
24+
for k, dashboard := range b.Config.Resources.Dashboards {
25+
if dashboard.Etag != "" {
26+
return diag.Diagnostics{
27+
{
28+
Severity: diag.Error,
29+
Summary: fmt.Sprintf("dashboard %q has an etag set. Etags must not be set in bundle configuration", dashboard.DisplayName),
30+
Paths: []dyn.Path{dyn.MustPathFromString("resources.dashboards." + k)},
31+
Locations: b.Config.GetLocations("resources.dashboards." + k),
32+
},
33+
}
34+
}
35+
}
36+
return nil
37+
}

bundle/phases/initialize.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ func Initialize(ctx context.Context, b *bundle.Bundle) {
142142
// Validate that all fields with enum values specified are set to a valid value.
143143
validate.Enum(),
144144

145+
// Validate that no dashboard etags are set. They are purely internal state and should not be set by the user.
146+
validate.ValidateDashboardEtags(),
147+
145148
// Reads (typed): b.Config.Permissions (checks if current user or their groups have CAN_MANAGE permissions)
146149
// Reads (typed): b.Config.Workspace.CurrentUser (gets current user information)
147150
// Provides diagnostic recommendations if the current deployment identity isn't explicitly granted CAN_MANAGE permissions

0 commit comments

Comments
 (0)