Skip to content

Commit 0628314

Browse files
authored
[Fix] Treat trashed dashboard as deleted (#4251)
## Changes This is a follow-up to #4235, where the deletion of a trashed dashboard was fixed. This change treats trashed dashboards as deleted at read time, such that the resource shows up in the plan as new instead of a delete+create. ## Tests - [x] `make test` run locally - [ ] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] relevant acceptance tests are passing - [ ] using Go SDK
1 parent 589f538 commit 0628314

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

dashboards/resource_dashboard.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ func ResourceDashboard() common.Resource {
126126
if err != nil {
127127
return err
128128
}
129+
130+
// Deletion of a dashboard moves it to the trash and subsequent reads still return the trashed dashboard.
131+
// It cannot be updated unless it is untrashed, so we treat it as deleted to force recreation.
132+
if resp.LifecycleState == dashboards.LifecycleStateTrashed {
133+
d.SetId("")
134+
return nil
135+
}
136+
129137
d.Set("dashboard_change_detected", (resp.Etag != d.Get("etag").(string)))
130138
return common.StructToData(resp, dashboardSchema, d)
131139
},

dashboards/resource_dashboard_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,23 @@ func TestDashboardRead(t *testing.T) {
157157
})
158158
}
159159

160+
func TestDashboardReadTrashed(t *testing.T) {
161+
qa.ResourceFixture{
162+
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
163+
w.GetMockLakeviewAPI().EXPECT().Get(mock.Anything, dashboards.GetDashboardRequest{
164+
DashboardId: "xyz",
165+
}).Return(&dashboards.Dashboard{
166+
DashboardId: "xyz",
167+
LifecycleState: dashboards.LifecycleStateTrashed,
168+
}, nil)
169+
},
170+
Resource: ResourceDashboard(),
171+
Read: true,
172+
Removed: true,
173+
ID: "xyz",
174+
}.ApplyNoError(t)
175+
}
176+
160177
func TestDashboardUpdate(t *testing.T) {
161178
qa.ResourceFixture{
162179
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {

0 commit comments

Comments
 (0)