Skip to content

Commit 1f8e5e1

Browse files
authored
[Dependency] Bump databricks-sdk-go to 0.44.0 (#3896)
## Changes This PR bumps the Databricks SDK for Go to v0.44.0. This version removes the Impl()/WithImpl() methods of the SDK. The cachedMe implementation is slightly dependent on this interface, so I changed how it is initialized to work with the new version of the SDK. Additionally, there were two tests depending on this and one line in the exporter. The tests are probably left-over from when the provider contained its own client implementation, but now that it uses the SDK's client for these resources, they can be removed. ## 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 96f6c9c commit 1f8e5e1

File tree

9 files changed

+34
-66
lines changed

9 files changed

+34
-66
lines changed

access/resource_ip_access_list_test.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package access
33
// REST API: https://docs.databricks.com/dev-tools/api/latest/ip-access-list.html#operation/create-list
44

55
import (
6-
"context"
76
"fmt"
87
"net/http"
98
"testing"
@@ -13,7 +12,6 @@ import (
1312
"github.com/databricks/terraform-provider-databricks/qa"
1413

1514
"github.com/stretchr/testify/assert"
16-
"github.com/stretchr/testify/require"
1715
)
1816

1917
var (
@@ -311,26 +309,3 @@ func TestIPACLDelete_Error(t *testing.T) {
311309
ID: TestingId,
312310
}.ExpectError(t, "Something went wrong")
313311
}
314-
315-
func TestListIpAccessLists(t *testing.T) {
316-
client, server, err := qa.HttpFixtureClient(t, []qa.HTTPFixture{
317-
{
318-
Method: "GET",
319-
Resource: "/api/2.0/ip-access-lists",
320-
Response: map[string]any{},
321-
},
322-
})
323-
require.NoError(t, err)
324-
325-
w, err := client.WorkspaceClient()
326-
require.NoError(t, err)
327-
328-
defer server.Close()
329-
require.NoError(t, err)
330-
331-
ctx := context.Background()
332-
ipLists, err := w.IpAccessLists.Impl().List(ctx)
333-
334-
require.NoError(t, err)
335-
assert.Equal(t, 0, len(ipLists.IpAccessLists))
336-
}

catalog/resource_volume_test.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package catalog
22

33
import (
4-
"context"
54
"fmt"
65
"net/http"
76
"testing"
@@ -10,7 +9,6 @@ import (
109
"github.com/databricks/terraform-provider-databricks/common"
1110
"github.com/databricks/terraform-provider-databricks/qa"
1211
"github.com/stretchr/testify/assert"
13-
"github.com/stretchr/testify/require"
1412
)
1513

1614
func TestVolumesCornerCases(t *testing.T) {
@@ -740,26 +738,3 @@ func TestVolumeDelete_Error(t *testing.T) {
740738
ID: "testCatalogName.testSchemaName.testName",
741739
}.ExpectError(t, "Something went wrong")
742740
}
743-
744-
func TestVolumesList(t *testing.T) {
745-
client, server, err := qa.HttpFixtureClient(t, []qa.HTTPFixture{
746-
{
747-
Method: http.MethodGet,
748-
Resource: "/api/2.1/unity-catalog/volumes?catalog_name=&schema_name=",
749-
Response: map[string]any{},
750-
},
751-
})
752-
require.NoError(t, err)
753-
754-
w, err := client.WorkspaceClient()
755-
require.NoError(t, err)
756-
757-
defer server.Close()
758-
require.NoError(t, err)
759-
760-
ctx := context.Background()
761-
vLists, err := w.Volumes.Impl().List(ctx, catalog.ListVolumesRequest{})
762-
763-
require.NoError(t, err)
764-
assert.Equal(t, 0, len(vLists.Volumes))
765-
}

clusters/data_spark_version.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ func DataSourceSparkVersion() common.Resource {
2121
return nil
2222
}, func(s map[string]*schema.Schema) map[string]*schema.Schema {
2323
common.CustomizeSchemaPath(s, "photon").SetDeprecated("Specify runtime_engine=\"PHOTON\" in the cluster configuration")
24-
common.CustomizeSchemaPath(s).AddNewField("graviton", &schema.Schema{
25-
Type: schema.TypeBool,
26-
Optional: true,
27-
Deprecated: "Not required anymore - it's automatically enabled on the Graviton-based node types",
28-
})
24+
common.CustomizeSchemaPath(s, "graviton").SetDeprecated("Not required anymore - it's automatically enabled on the Graviton-based node types")
2925
return s
3026
})
3127
}

common/client.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ type cachedMe struct {
2222
mu sync.Mutex
2323
}
2424

25+
func newCachedMe(inner iam.CurrentUserService) *cachedMe {
26+
return &cachedMe{
27+
internalImpl: inner,
28+
}
29+
}
30+
2531
func (a *cachedMe) Me(ctx context.Context) (*iam.User, error) {
2632
a.mu.Lock()
2733
defer a.mu.Unlock()
@@ -60,10 +66,7 @@ func (c *DatabricksClient) WorkspaceClient() (*databricks.WorkspaceClient, error
6066
if err != nil {
6167
return nil, err
6268
}
63-
internalImpl := w.CurrentUser.Impl()
64-
w.CurrentUser.WithImpl(&cachedMe{
65-
internalImpl: internalImpl,
66-
})
69+
w.CurrentUser = newCachedMe(w.CurrentUser)
6770
c.cachedWorkspaceClient = w
6871
return w, nil
6972
}

common/client_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/databricks/databricks-sdk-go/client"
1212
"github.com/databricks/databricks-sdk-go/config"
13+
"github.com/databricks/databricks-sdk-go/service/iam"
1314
"github.com/stretchr/testify/assert"
1415
"github.com/stretchr/testify/require"
1516
)
@@ -315,3 +316,22 @@ func TestGetJWTProperty_Authenticate_Fail(t *testing.T) {
315316
assert.True(t, strings.HasPrefix(err.Error(),
316317
"default auth: azure-cli: cannot get access token: This is just a failing script"))
317318
}
319+
320+
type mockInternalUserService struct {
321+
count int
322+
}
323+
324+
func (m *mockInternalUserService) Me(ctx context.Context) (user *iam.User, err error) {
325+
m.count++
326+
return &iam.User{
327+
UserName: "test",
328+
}, nil
329+
}
330+
331+
func TestCachedMe_Me_MakesSingleRequest(t *testing.T) {
332+
mock := &mockInternalUserService{}
333+
cm := newCachedMe(mock)
334+
cm.Me(context.Background())
335+
cm.Me(context.Background())
336+
assert.Equal(t, 1, mock.count)
337+
}

exporter/importables.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,12 +1536,11 @@ var resourcesMap map[string]importable = map[string]importable{
15361536
return d.Get("list_type").(string) + "_" + d.Get("label").(string)
15371537
},
15381538
List: func(ic *importContext) error {
1539-
ipListsResp, err := ic.workspaceClient.IpAccessLists.Impl().List(ic.Context)
1539+
ipLists, err := ic.workspaceClient.IpAccessLists.ListAll(ic.Context)
15401540

15411541
if err != nil {
15421542
return err
15431543
}
1544-
ipLists := ipListsResp.IpAccessLists
15451544
for offset, ipList := range ipLists {
15461545
ic.EmitIfUpdatedAfterMillis(&resource{
15471546
Resource: "databricks_ip_access_list",

exporter/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,15 +556,15 @@ func dltIsMatchingCatalogAndSchema(ic *importContext, res *resource, ra *resourc
556556
}
557557

558558
func (ic *importContext) emitWorkspaceBindings(securableType, securableName string) {
559-
bindings, err := ic.workspaceClient.WorkspaceBindings.GetBindings(ic.Context, catalog.GetBindingsRequest{
559+
bindings, err := ic.workspaceClient.WorkspaceBindings.GetBindingsAll(ic.Context, catalog.GetBindingsRequest{
560560
SecurableName: securableName,
561561
SecurableType: catalog.GetBindingsSecurableType(securableType),
562562
})
563563
if err != nil {
564564
log.Printf("[ERROR] listing %s bindings for %s: %s", securableType, securableName, err.Error())
565565
return
566566
}
567-
for _, binding := range bindings.Bindings {
567+
for _, binding := range bindings {
568568
id := fmt.Sprintf("%d|%s|%s", binding.WorkspaceId, securableType, securableName)
569569
// We were creating Data instance explicitly because of the bug in the databricks_catalog_workspace_binding
570570
// implementation. Technically, after the fix is merged we can remove this, but we're keeping it as-is now

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.43.3-0.20240725113401-33ef9dbf3727
6+
github.com/databricks/databricks-sdk-go v0.44.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.43.3-0.20240725113401-33ef9dbf3727 h1:EwEUcWBPFBsosUGpyiiMXYbOfn+i5PM5hatP6gsDyXQ=
30-
github.com/databricks/databricks-sdk-go v0.43.3-0.20240725113401-33ef9dbf3727/go.mod h1:ds+zbv5mlQG7nFEU5ojLtgN/u0/9YzZmKQES/CfedzU=
29+
github.com/databricks/databricks-sdk-go v0.44.0 h1:9/FZACv4EFQIOYxfwYVKnY7v46xio9FKCw9tpKB2O/s=
30+
github.com/databricks/databricks-sdk-go v0.44.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=

0 commit comments

Comments
 (0)