Skip to content

Commit 17641de

Browse files
authored
[Dependency] Bump Go SDK to v0.50.0 (#4178)
## Changes Use the latest Go SDK in the Terraform provider. The main changes affect Dashboards and Online Tables, whose Create and Update RPCs now accept an instance of the resource, rather than inlining the fields of the resource. Additionally, Online Tables introduced a waiter configuration, so we can remove hand-written waiter logic used before. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [ ] `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 5daf2ed commit 17641de

File tree

15 files changed

+395
-419
lines changed

15 files changed

+395
-419
lines changed

.codegen/_openapi_sha

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cf9c61453990df0f9453670f2fe68e1b128647a2
1+
25b2478e5a18c888f0d423249abde5499dc58424

catalog/resource_online_table.go

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,6 @@ import (
1616

1717
const onlineTableDefaultProvisionTimeout = 90 * time.Minute
1818

19-
func waitForOnlineTableCreation(w *databricks.WorkspaceClient, ctx context.Context, onlineTableName string) error {
20-
return retry.RetryContext(ctx, onlineTableDefaultProvisionTimeout, func() *retry.RetryError {
21-
endpoint, err := w.OnlineTables.GetByName(ctx, onlineTableName)
22-
if err != nil {
23-
return retry.NonRetryableError(err)
24-
}
25-
if endpoint.Status == nil {
26-
return retry.RetryableError(fmt.Errorf("online table status is not available yet"))
27-
}
28-
switch endpoint.Status.DetailedState {
29-
case catalog.OnlineTableStateOnline, catalog.OnlineTableStateOnlineContinuousUpdate,
30-
catalog.OnlineTableStateOnlineNoPendingUpdate, catalog.OnlineTableStateOnlineTriggeredUpdate:
31-
return nil
32-
33-
// does catalog.OnlineTableStateOffline means that it's failed?
34-
case catalog.OnlineTableStateOfflineFailed, catalog.OnlineTableStateOnlinePipelineFailed:
35-
return retry.NonRetryableError(fmt.Errorf("online table status returned %s for online table: %s",
36-
endpoint.Status.DetailedState.String(), onlineTableName))
37-
}
38-
return retry.RetryableError(fmt.Errorf("online table %s is still pending", onlineTableName))
39-
})
40-
}
41-
4219
func waitForOnlineTableDeletion(w *databricks.WorkspaceClient, ctx context.Context, onlineTableName string) error {
4320
return retry.RetryContext(ctx, onlineTableDefaultProvisionTimeout, func() *retry.RetryError {
4421
_, err := w.OnlineTables.GetByName(ctx, onlineTableName)
@@ -75,17 +52,17 @@ func ResourceOnlineTable() common.Resource {
7552
if err != nil {
7653
return err
7754
}
78-
var req catalog.CreateOnlineTableRequest
79-
common.DataToStructPointer(d, s, &req)
80-
res, err := w.OnlineTables.Create(ctx, req)
55+
var table catalog.OnlineTable
56+
common.DataToStructPointer(d, s, &table)
57+
res, err := w.OnlineTables.Create(ctx, catalog.CreateOnlineTableRequest{Table: &table})
8158
if err != nil {
8259
return err
8360
}
8461
// Note: We should set the id right after creation and before waiting for online table to be available.
8562
// If the resource creation timeout is exceeded while waiting for the online table to be ready, this ensures the online table is persisted in the state.
8663
d.SetId(res.Name)
8764
// this should be specified in the API Spec - filed a ticket to add it
88-
err = waitForOnlineTableCreation(w, ctx, res.Name)
65+
_, err = res.GetWithTimeout(onlineTableDefaultProvisionTimeout)
8966
if err != nil {
9067
return err
9168
}

catalog/resource_online_table_test.go

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package catalog
22

33
import (
4+
"errors"
45
"fmt"
56
"testing"
7+
"time"
68

79
"github.com/databricks/databricks-sdk-go/apierr"
810
"github.com/databricks/databricks-sdk-go/experimental/mocks"
@@ -47,6 +49,13 @@ func TestOnlineTableCreate(t *testing.T) {
4749
PrimaryKeyColumns: []string{"id"},
4850
},
4951
}
52+
otStatusNotSetWait := &catalog.WaitGetOnlineTableActive[catalog.OnlineTable]{
53+
Response: otStatusNotSet,
54+
Name: "main.default.online_table",
55+
Poll: func(d time.Duration, f func(*catalog.OnlineTable)) (*catalog.OnlineTable, error) {
56+
return otStatusOnline, nil
57+
},
58+
}
5059
// otStatusUnknown := &catalog.OnlineTable{
5160
// Name: "main.default.online_table",
5261
// Spec: &catalog.OnlineTableSpec{
@@ -60,16 +69,15 @@ func TestOnlineTableCreate(t *testing.T) {
6069
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
6170
e := w.GetMockOnlineTablesAPI().EXPECT()
6271
e.Create(mock.Anything, catalog.CreateOnlineTableRequest{
63-
Name: "main.default.online_table",
64-
Spec: &catalog.OnlineTableSpec{
65-
RunTriggered: &catalog.OnlineTableSpecTriggeredSchedulingPolicy{},
66-
SourceTableFullName: "main.default.test",
67-
PrimaryKeyColumns: []string{"id"},
72+
Table: &catalog.OnlineTable{
73+
Name: "main.default.online_table",
74+
Spec: &catalog.OnlineTableSpec{
75+
RunTriggered: &catalog.OnlineTableSpecTriggeredSchedulingPolicy{},
76+
SourceTableFullName: "main.default.test",
77+
PrimaryKeyColumns: []string{"id"},
78+
},
6879
},
69-
}).Return(otStatusNotSet, nil)
70-
// TODO: how to emulate the status change
71-
// e.GetByName(mock.Anything, "main.default.online_table").Return(otStatusNotSet, nil)
72-
// e.GetByName(mock.Anything, "main.default.online_table").Return(otStatusUnknown, nil)
80+
}).Return(otStatusNotSetWait, nil)
7381
e.GetByName(mock.Anything, "main.default.online_table").Return(otStatusOnline, nil)
7482
},
7583
Resource: ResourceOnlineTable(),
@@ -85,11 +93,13 @@ func TestOnlineTableCreate_ErrorImmediately(t *testing.T) {
8593
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
8694
e := w.GetMockOnlineTablesAPI().EXPECT()
8795
e.Create(mock.Anything, catalog.CreateOnlineTableRequest{
88-
Name: "main.default.online_table",
89-
Spec: &catalog.OnlineTableSpec{
90-
RunTriggered: &catalog.OnlineTableSpecTriggeredSchedulingPolicy{},
91-
SourceTableFullName: "main.default.test",
92-
PrimaryKeyColumns: []string{"id"},
96+
Table: &catalog.OnlineTable{
97+
Name: "main.default.online_table",
98+
Spec: &catalog.OnlineTableSpec{
99+
RunTriggered: &catalog.OnlineTableSpecTriggeredSchedulingPolicy{},
100+
SourceTableFullName: "main.default.test",
101+
PrimaryKeyColumns: []string{"id"},
102+
},
93103
},
94104
}).Return(nil, fmt.Errorf("error!"))
95105
},
@@ -100,33 +110,41 @@ func TestOnlineTableCreate_ErrorImmediately(t *testing.T) {
100110
}
101111

102112
func TestOnlineTableCreate_ErrorInWait(t *testing.T) {
103-
otStatusError := &catalog.OnlineTable{
113+
otStatusProvisioning := &catalog.OnlineTable{
104114
Name: "main.default.online_table",
105115
Spec: &catalog.OnlineTableSpec{
106116
RunTriggered: &catalog.OnlineTableSpecTriggeredSchedulingPolicy{},
107117
SourceTableFullName: "main.default.test",
108118
PrimaryKeyColumns: []string{"id"},
109119
},
110-
Status: &catalog.OnlineTableStatus{DetailedState: catalog.OnlineTableStateOfflineFailed},
120+
Status: &catalog.OnlineTableStatus{DetailedState: catalog.OnlineTableStateProvisioning},
121+
}
122+
otStatusErrorWait := &catalog.WaitGetOnlineTableActive[catalog.OnlineTable]{
123+
Response: otStatusProvisioning,
124+
Name: "main.default.online_table",
125+
Poll: func(d time.Duration, f func(*catalog.OnlineTable)) (*catalog.OnlineTable, error) {
126+
return nil, errors.New("failed to reach ACTIVE, got OFFLINE_FAILED: error!")
127+
},
111128
}
112129
d, err := qa.ResourceFixture{
113130
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
114131
e := w.GetMockOnlineTablesAPI().EXPECT()
115132
e.Create(mock.Anything, catalog.CreateOnlineTableRequest{
116-
Name: "main.default.online_table",
117-
Spec: &catalog.OnlineTableSpec{
118-
RunTriggered: &catalog.OnlineTableSpecTriggeredSchedulingPolicy{},
119-
SourceTableFullName: "main.default.test",
120-
PrimaryKeyColumns: []string{"id"},
133+
Table: &catalog.OnlineTable{
134+
Name: "main.default.online_table",
135+
Spec: &catalog.OnlineTableSpec{
136+
RunTriggered: &catalog.OnlineTableSpecTriggeredSchedulingPolicy{},
137+
SourceTableFullName: "main.default.test",
138+
PrimaryKeyColumns: []string{"id"},
139+
},
121140
},
122-
}).Return(otStatusError, nil)
123-
e.GetByName(mock.Anything, "main.default.online_table").Return(otStatusError, nil)
141+
}).Return(otStatusErrorWait, nil)
124142
},
125143
Resource: ResourceOnlineTable(),
126144
HCL: onlineTableHcl,
127145
Create: true,
128146
}.Apply(t)
129-
qa.AssertErrorStartsWith(t, err, "online table status returned OFFLINE_FAILED for online table: main.default.online_table")
147+
qa.AssertErrorStartsWith(t, err, "failed to reach ACTIVE, got OFFLINE_FAILED: error!")
130148
assert.Equal(t, "main.default.online_table", d.Id())
131149
}
132150

dashboards/resource_dashboard.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,22 @@ func ResourceDashboard() common.Resource {
6868
if err != nil {
6969
return err
7070
}
71-
var newDashboardRequest dashboards.CreateDashboardRequest
72-
common.DataToStructPointer(d, dashboardSchema, &newDashboardRequest)
71+
var dashboard dashboards.Dashboard
72+
common.DataToStructPointer(d, dashboardSchema, &dashboard)
7373
content, md5Hash, err := common.ReadSerializedJsonContent(d.Get("serialized_dashboard").(string), d.Get("file_path").(string))
7474
if err != nil {
7575
return err
7676
}
7777
d.Set("md5", md5Hash)
78-
newDashboardRequest.SerializedDashboard = content
79-
createdDashboard, err := w.Lakeview.Create(ctx, newDashboardRequest)
78+
dashboard.SerializedDashboard = content
79+
createdDashboard, err := w.Lakeview.Create(ctx, dashboards.CreateDashboardRequest{Dashboard: &dashboard})
8080
if err != nil && isParentDoesntExistError(err) {
81-
log.Printf("[DEBUG] Parent folder '%s' doesn't exist, creating...", newDashboardRequest.ParentPath)
82-
err = w.Workspace.MkdirsByPath(ctx, newDashboardRequest.ParentPath)
81+
log.Printf("[DEBUG] Parent folder '%s' doesn't exist, creating...", dashboard.ParentPath)
82+
err = w.Workspace.MkdirsByPath(ctx, dashboard.ParentPath)
8383
if err != nil {
8484
return err
8585
}
86-
createdDashboard, err = w.Lakeview.Create(ctx, newDashboardRequest)
86+
createdDashboard, err = w.Lakeview.Create(ctx, dashboards.CreateDashboardRequest{Dashboard: &dashboard})
8787
}
8888
if err != nil {
8989
return err
@@ -132,16 +132,19 @@ func ResourceDashboard() common.Resource {
132132
if err != nil {
133133
return err
134134
}
135-
var updateDashboardRequest dashboards.UpdateDashboardRequest
136-
common.DataToStructPointer(d, dashboardSchema, &updateDashboardRequest)
137-
updateDashboardRequest.DashboardId = d.Id()
135+
var dashboard dashboards.Dashboard
136+
common.DataToStructPointer(d, dashboardSchema, &dashboard)
137+
dashboard.DashboardId = d.Id()
138138
content, md5Hash, err := common.ReadSerializedJsonContent(d.Get("serialized_dashboard").(string), d.Get("file_path").(string))
139139
if err != nil {
140140
return err
141141
}
142142
d.Set("md5", md5Hash)
143-
updateDashboardRequest.SerializedDashboard = content
144-
updatedDashboard, err := w.Lakeview.Update(ctx, updateDashboardRequest)
143+
dashboard.SerializedDashboard = content
144+
updatedDashboard, err := w.Lakeview.Update(ctx, dashboards.UpdateDashboardRequest{
145+
DashboardId: dashboard.DashboardId,
146+
Dashboard: &dashboard,
147+
})
145148
if err != nil {
146149
return err
147150
}

dashboards/resource_dashboard_test.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ func TestDashboardCreate(t *testing.T) {
1616
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
1717
e := w.GetMockLakeviewAPI().EXPECT()
1818
e.Create(mock.Anything, dashboards.CreateDashboardRequest{
19-
DisplayName: "Dashboard name",
20-
WarehouseId: "abc",
21-
ParentPath: "/path",
22-
SerializedDashboard: "serialized_json",
19+
Dashboard: &dashboards.Dashboard{
20+
DisplayName: "Dashboard name",
21+
WarehouseId: "abc",
22+
ParentPath: "/path",
23+
SerializedDashboard: "serialized_json",
24+
},
2325
}).Return(&dashboards.Dashboard{
2426
DashboardId: "xyz",
2527
DisplayName: "Dashboard name",
@@ -67,17 +69,21 @@ func TestDashboardCreate_NoParent(t *testing.T) {
6769
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
6870
lv := w.GetMockLakeviewAPI().EXPECT()
6971
lv.Create(mock.Anything, dashboards.CreateDashboardRequest{
70-
DisplayName: "Dashboard name",
71-
WarehouseId: "abc",
72-
ParentPath: "/path",
73-
SerializedDashboard: "serialized_json",
72+
Dashboard: &dashboards.Dashboard{
73+
DisplayName: "Dashboard name",
74+
WarehouseId: "abc",
75+
ParentPath: "/path",
76+
SerializedDashboard: "serialized_json",
77+
},
7478
}).Return(nil, fmt.Errorf("Path (/path) doesn't exist.")).Once()
7579
w.GetMockWorkspaceAPI().EXPECT().MkdirsByPath(mock.Anything, "/path").Return(nil)
7680
lv.Create(mock.Anything, dashboards.CreateDashboardRequest{
77-
DisplayName: "Dashboard name",
78-
WarehouseId: "abc",
79-
ParentPath: "/path",
80-
SerializedDashboard: "serialized_json",
81+
Dashboard: &dashboards.Dashboard{
82+
DisplayName: "Dashboard name",
83+
WarehouseId: "abc",
84+
ParentPath: "/path",
85+
SerializedDashboard: "serialized_json",
86+
},
8187
}).Return(&dashboards.Dashboard{
8288
DashboardId: "xyz",
8389
DisplayName: "Dashboard name",
@@ -154,10 +160,14 @@ func TestDashboardUpdate(t *testing.T) {
154160
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
155161
e := w.GetMockLakeviewAPI().EXPECT()
156162
e.Update(mock.Anything, dashboards.UpdateDashboardRequest{
157-
DashboardId: "xyz",
158-
DisplayName: "Dashboard name",
159-
WarehouseId: "abc",
160-
SerializedDashboard: "serialized_dashboard_updated",
163+
DashboardId: "xyz",
164+
Dashboard: &dashboards.Dashboard{
165+
DashboardId: "xyz",
166+
DisplayName: "Dashboard name",
167+
WarehouseId: "abc",
168+
SerializedDashboard: "serialized_dashboard_updated",
169+
ParentPath: "/path",
170+
},
161171
}).Return(&dashboards.Dashboard{
162172
DashboardId: "xyz",
163173
DisplayName: "Dashboard name",

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/databricks/terraform-provider-databricks
33
go 1.22
44

55
require (
6-
github.com/databricks/databricks-sdk-go v0.49.0
6+
github.com/databricks/databricks-sdk-go v0.50.0
77
github.com/golang-jwt/jwt/v4 v4.5.0
88
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
99
github.com/hashicorp/hcl v1.0.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBS
2626
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
2727
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
2828
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
29-
github.com/databricks/databricks-sdk-go v0.49.0 h1:VBTeZZMLIuBSM4kxOCfUcW9z4FUQZY2QeNRD5qm9FUQ=
30-
github.com/databricks/databricks-sdk-go v0.49.0/go.mod h1:ds+zbv5mlQG7nFEU5ojLtgN/u0/9YzZmKQES/CfedzU=
29+
github.com/databricks/databricks-sdk-go v0.50.0 h1:Zl4uBhYMT5z6aDojCQJPT2zCYjjfqxBQSQn8uLTphpo=
30+
github.com/databricks/databricks-sdk-go v0.50.0/go.mod h1:ds+zbv5mlQG7nFEU5ojLtgN/u0/9YzZmKQES/CfedzU=
3131
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3232
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3333
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

internal/acceptance/dashboard_test.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,14 @@ func TestAccDashboardWithRemoteChange(t *testing.T) {
315315
w, err := databricks.NewWorkspaceClient(&databricks.Config{})
316316
require.NoError(t, err)
317317
_, err = w.Lakeview.Update(context.Background(), dashboards.UpdateDashboardRequest{
318-
DashboardId: dashboard_id,
319-
DisplayName: display_name,
320-
Etag: etag,
321-
WarehouseId: warehouse_id,
322-
SerializedDashboard: "{\"pages\":[{\"name\":\"b532570b\",\"displayName\":\"New Page Modified Remote\"}]}",
318+
DashboardId: dashboard_id,
319+
Dashboard: &dashboards.Dashboard{
320+
DashboardId: dashboard_id,
321+
DisplayName: display_name,
322+
Etag: etag,
323+
WarehouseId: warehouse_id,
324+
SerializedDashboard: "{\"pages\":[{\"name\":\"b532570b\",\"displayName\":\"New Page Modified Remote\"}]}",
325+
},
323326
})
324327
require.NoError(t, err)
325328
},
@@ -419,11 +422,14 @@ func TestAccDashboardTestAll(t *testing.T) {
419422
w, err := databricks.NewWorkspaceClient(&databricks.Config{})
420423
require.NoError(t, err)
421424
_, err = w.Lakeview.Update(context.Background(), dashboards.UpdateDashboardRequest{
422-
DashboardId: dashboard_id,
423-
DisplayName: display_name,
424-
Etag: etag,
425-
WarehouseId: warehouse_id,
426-
SerializedDashboard: "{\"pages\":[{\"name\":\"b532570b\",\"displayName\":\"New Page Modified Remote\"}]}",
425+
DashboardId: dashboard_id,
426+
Dashboard: &dashboards.Dashboard{
427+
DashboardId: dashboard_id,
428+
DisplayName: display_name,
429+
Etag: etag,
430+
WarehouseId: warehouse_id,
431+
SerializedDashboard: "{\"pages\":[{\"name\":\"b532570b\",\"displayName\":\"New Page Modified Remote\"}]}",
432+
},
427433
})
428434
require.NoError(t, err)
429435
},

0 commit comments

Comments
 (0)