Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions common/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions common/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,12 @@ func TestClientForHost(t *testing.T) {
})
assert.NoError(t, err)
assert.True(t, dc.IsAws())
cc, err := dc.ClientForHost(context.Background(), "https://e2-workspace.cloud.databricks.com/")
cc, err := dc.ClientForHost(context.Background(), "https://e2-workspace.cloud.databricks.com/", 12345)
assert.NoError(t, err)
assert.Equal(t, dc.Config.Username, cc.Config.Username)
assert.Equal(t, dc.Config.Password, cc.Config.Password)
assert.NotEqual(t, dc.Config.Host, cc.Config.Host)
assert.Equal(t, "12345", cc.Config.WorkspaceId)
}

func TestClientForHostAuthError(t *testing.T) {
Expand All @@ -254,7 +255,7 @@ func TestClientForHostAuthError(t *testing.T) {
},
},
}
_, err := c.ClientForHost(context.Background(), "https://e2-workspace.cloud.databricks.com/")
_, err := c.ClientForHost(context.Background(), "https://e2-workspace.cloud.databricks.com/", 12345)
assert.NoError(t, err)
}

Expand Down
3 changes: 2 additions & 1 deletion exporter/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"time"

"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/config"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/databricks-sdk-go/service/compute"
"golang.org/x/exp/maps"
Expand Down Expand Up @@ -397,7 +398,7 @@ func (ic *importContext) Run() error {
return fmt.Errorf("the path %s is not a directory", ic.Directory)
}

ic.accountLevel = ic.Client.Config.IsAccountClient()
ic.accountLevel = ic.Client.Config.ConfigType() == config.AccountConfig
if ic.accountLevel {
ic.meAdmin = true
// TODO: check if we can get the current user from the account client
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ module github.com/databricks/terraform-provider-databricks
go 1.24.0

require (
github.com/databricks/databricks-sdk-go v0.86.0
github.com/databricks/databricks-sdk-go v0.90.0
github.com/golang-jwt/jwt/v4 v4.5.2
github.com/hashicorp/go-cty v1.5.0
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/hcl/v2 v2.24.0
github.com/hashicorp/terraform-json v0.27.2
github.com/hashicorp/terraform-plugin-framework v1.16.1
github.com/hashicorp/terraform-plugin-framework-validators v0.19.0
github.com/hashicorp/terraform-plugin-go v0.29.0
Expand Down Expand Up @@ -59,6 +58,7 @@ require (
github.com/hashicorp/hc-install v0.9.2 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.23.1 // indirect
github.com/hashicorp/terraform-json v0.27.2 // indirect
github.com/hashicorp/terraform-registry-address v0.4.0 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
github.com/cyphar/filepath-securejoin v0.4.1 h1:JyxxyPEaktOD+GAnqIqTf9A8tHyAG22rowi7HkoSU1s=
github.com/cyphar/filepath-securejoin v0.4.1/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI=
github.com/databricks/databricks-sdk-go v0.86.0 h1:Di1+NBQlfzBMUhY6w6gS2mtmNXIWycowoCsLCGFQPyU=
github.com/databricks/databricks-sdk-go v0.86.0/go.mod h1:hWoHnHbNLjPKiTm5K/7bcIv3J3Pkgo5x9pPzh8K3RVE=
github.com/databricks/databricks-sdk-go v0.90.0 h1:yS9kBd/4LEp3WzzFZ/th49A+WXn0bb6rEWLAYL4T6/8=
github.com/databricks/databricks-sdk-go v0.90.0/go.mod h1:hWoHnHbNLjPKiTm5K/7bcIv3J3Pkgo5x9pPzh8K3RVE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand Down
13 changes: 11 additions & 2 deletions mws/mws_workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"regexp"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -146,8 +147,12 @@ func TestMwsAccWorkspacesTokenUpdate(t *testing.T) {
func(ctx context.Context, client *common.DatabricksClient, state *terraform.InstanceState) error {
workspaceUrl, ok := state.Attributes["workspace_url"]
assert.True(t, ok, "workspace_url is absent from databricks_mws_workspaces instance state")
workspaceIdStr, ok := state.Attributes["workspace_id"]
assert.True(t, ok, "workspace_id is absent from databricks_mws_workspaces instance state")
workspaceId, err := strconv.ParseInt(workspaceIdStr, 10, 64)
assert.NoError(t, err)

workspaceClient, err := client.ClientForHost(ctx, workspaceUrl)
workspaceClient, err := client.ClientForHost(ctx, workspaceUrl, workspaceId)
assert.NoError(t, err)

tokensAPI := tokens.NewTokensAPI(ctx, workspaceClient)
Expand Down Expand Up @@ -219,8 +224,12 @@ func TestMwsAccWorkspacesTokenUpdate(t *testing.T) {
func(ctx context.Context, client *common.DatabricksClient, state *terraform.InstanceState) error {
workspaceUrl, ok := state.Attributes["workspace_url"]
assert.True(t, ok, "workspace_url is absent from databricks_mws_workspaces instance state")
workspaceIdStr, ok := state.Attributes["workspace_id"]
assert.True(t, ok, "workspace_id is absent from databricks_mws_workspaces instance state")
workspaceId, err := strconv.ParseInt(workspaceIdStr, 10, 64)
assert.NoError(t, err)

workspaceClient, err := client.ClientForHost(ctx, workspaceUrl)
workspaceClient, err := client.ClientForHost(ctx, workspaceUrl, workspaceId)
assert.NoError(t, err)

tokensAPI := tokens.NewTokensAPI(ctx, workspaceClient)
Expand Down
11 changes: 7 additions & 4 deletions mws/resource_mws_workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (a WorkspacesAPI) verifyWorkspaceReachable(ws Workspace) *resource.RetryErr
defer cancel()
// wait for DNS caches to refresh, as sometimes we cannot make
// API calls to new workspaces immediately after it's created
wsClient, err := a.client.ClientForHost(a.context, ws.WorkspaceURL)
wsClient, err := a.client.ClientForHost(a.context, ws.WorkspaceURL, ws.WorkspaceID)
if err != nil {
return resource.NonRetryableError(err)
}
Expand Down Expand Up @@ -410,6 +410,7 @@ func (s SensitiveString) String() string {
// ephemeral entity to use with StructToData()
type WorkspaceToken struct {
WorkspaceURL string `json:"workspace_url,omitempty"`
WorkspaceId int64 `json:"workspace_id,omitempty"`
Token *Token `json:"token,omitempty"`
}

Expand All @@ -420,7 +421,7 @@ func CreateTokenIfNeeded(workspacesAPI WorkspacesAPI,
if wsToken.Token == nil {
return nil
}
client, err := workspacesAPI.client.ClientForHost(workspacesAPI.context, wsToken.WorkspaceURL)
client, err := workspacesAPI.client.ClientForHost(workspacesAPI.context, wsToken.WorkspaceURL, wsToken.WorkspaceId)
if err != nil {
return err
}
Expand Down Expand Up @@ -458,7 +459,7 @@ func EnsureTokenExistsIfNeeded(a WorkspacesAPI,
if wsToken.Token == nil {
return nil
}
client, err := a.client.ClientForHost(a.context, wsToken.WorkspaceURL)
client, err := a.client.ClientForHost(a.context, wsToken.WorkspaceURL, wsToken.WorkspaceId)
if err != nil {
return err
}
Expand All @@ -481,7 +482,9 @@ func EnsureTokenExistsIfNeeded(a WorkspacesAPI,
}

func removeTokenIfNeeded(a WorkspacesAPI, tokenID string, d *schema.ResourceData) error {
client, err := a.client.ClientForHost(a.context, d.Get("workspace_url").(string))
workspaceID := int64(d.Get("workspace_id").(int))
workspaceURL := d.Get("workspace_url").(string)
client, err := a.client.ClientForHost(a.context, workspaceURL, workspaceID)
if err != nil {
return err
}
Expand Down
Loading