Skip to content

Commit

Permalink
Fix Update method of databricks_user (#2878)
Browse files Browse the repository at this point in the history
The `Update` method wasn't reading the correct set of attributes when updating
user (i.e. when having `force = true`) - this lead that groups were reset to empty state,
and users were losing their groups association.

This fixes #2648
  • Loading branch information
alexott authored Nov 4, 2023
1 parent a380ae7 commit 3d91d69
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions scim/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func ResourceUser() *schema.Resource {
if err != nil {
return err
}
return NewUsersAPI(ctx, c).Update(d.Id(), "userName,displayName,active,externalId,entitlements", u)
return NewUsersAPI(ctx, c).Update(d.Id(), u)
},
Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
user := NewUsersAPI(ctx, c)
Expand Down Expand Up @@ -181,5 +181,5 @@ func createForceOverridesManuallyAddedUser(err error, d *schema.ResourceData, us
}
user := userList[0]
d.SetId(user.ID)
return usersAPI.Update(d.Id(), "userName,displayName,active,externalId,entitlements", u)
return usersAPI.Update(d.Id(), u)
}
6 changes: 3 additions & 3 deletions scim/resource_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func TestResourceUserUpdate(t *testing.T) {
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Users/abc?attributes=userName,displayName,active,externalId,entitlements",
Resource: "/api/2.0/preview/scim/v2/Users/abc?attributes=groups,roles",
Response: User{
DisplayName: "Example user",
Active: true,
Expand Down Expand Up @@ -659,7 +659,7 @@ func TestCreateForceOverwriteFindsAndSetsID(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Users/abc?attributes=userName,displayName,active,externalId,entitlements",
Resource: "/api/2.0/preview/scim/v2/Users/abc?attributes=groups,roles",
Response: User{
ID: "abc",
},
Expand Down Expand Up @@ -701,7 +701,7 @@ func TestCreateForceOverwriteFindsAndSetsAccID(t *testing.T) {
},
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Users/abc?attributes=userName,displayName,active,externalId,entitlements",
Resource: "/api/2.0/preview/scim/v2/Users/abc?attributes=groups,roles",
Response: User{
ID: "abc",
},
Expand Down
4 changes: 2 additions & 2 deletions scim/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (a UsersAPI) readByPath(userPath string) (user User, err error) {
}

// Update replaces user information for given ID
func (a UsersAPI) Update(userID, attributes string, updateRequest User) error {
user, err := a.Read(userID, attributes)
func (a UsersAPI) Update(userID string, updateRequest User) error {
user, err := a.Read(userID, "groups,roles")
if err != nil {
return err
}
Expand Down

0 comments on commit 3d91d69

Please sign in to comment.