Skip to content

Commit

Permalink
removed unnecesary tests, switched to use a filter field to leverage …
Browse files Browse the repository at this point in the history
…REST API's flexibility
  • Loading branch information
dgomez04 committed Nov 1, 2024
1 parent 6f6d19e commit 88608c1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
11 changes: 7 additions & 4 deletions internal/providers/pluginfw/resources/user/data_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package user

import (
"context"
"go/types"

"github.com/databricks/databricks-sdk-go/service/iam"
"github.com/databricks/terraform-provider-databricks/common"
Expand All @@ -12,6 +11,7 @@ import (
"github.com/databricks/terraform-provider-databricks/internal/service/iam_tf"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)

func DataSourceUsers() datasource.DataSource {
Expand Down Expand Up @@ -55,14 +55,17 @@ func (d *UsersDataSource) Read(ctx context.Context, req datasource.ReadRequest,
return
}

var users []iam.User
var err error

if d.Client.Config.IsAccountClient() {
a, diags := d.Client.GetAccountClient()
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

users, err := a.Users.ListAll(ctx, iam.ListAccountUsersRequest{Filter: usersInfo.Filter})
users, err = a.Users.ListAll(ctx, iam.ListAccountUsersRequest{Filter: usersInfo.Filter.ValueString()})
if err != nil {
resp.Diagnostics.AddError("Error listing account users", err.Error())
}
Expand All @@ -73,7 +76,7 @@ func (d *UsersDataSource) Read(ctx context.Context, req datasource.ReadRequest,
return
}

users, err := w.Users.ListAll(ctx, iam.ListUsersRequest{Filter: filter})
users, err = w.Users.ListAll(ctx, iam.ListUsersRequest{Filter: usersInfo.Filter.ValueString()})
if err != nil {
resp.Diagnostics.AddError("Error listing workspace users", err.Error())
}
Expand All @@ -85,7 +88,7 @@ func (d *UsersDataSource) Read(ctx context.Context, req datasource.ReadRequest,
if resp.Diagnostics.HasError() {
return
}
usersInfo.Users = append(usersInfo.Users, user)
usersInfo.Users = append(usersInfo.Users, tfUser)
}

resp.Diagnostics.Append(resp.State.Set(ctx, usersInfo)...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const dataSourceTemplate = `
}
data "databricks_users" "this" {
user_name_contains = "testuser"
filter = "userName co \"testuser\""
depends_on = [databricks_user.user1, databricks_user.user2]
}
`
Expand Down
19 changes: 0 additions & 19 deletions internal/providers/pluginfw/resources/user/data_users_test.go

This file was deleted.

0 comments on commit 88608c1

Please sign in to comment.