Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add active attribute to databricks_user data source #3733

Merged
merged 1 commit into from
Jul 28, 2024
Merged
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
1 change: 1 addition & 0 deletions docs/data-sources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Data source exposes the following attributes:
- `home` - Home folder of the [user](../resources/user.md), e.g. `/Users/mr.foo@example.com`.
- `repos` - Personal Repos location of the [user](../resources/user.md), e.g. `/Repos/mr.foo@example.com`.
- `alphanumeric` - Alphanumeric representation of user local name. e.g. `mr_foo`.
- `active` - Whether the [user](../resources/user.md) is active.

* `acl_principal_id` - identifier for use in [databricks_access_control_rule_set](../resources/access_control_rule_set.md), e.g. `users/mr.foo@example.com`.

Expand Down
5 changes: 5 additions & 0 deletions scim/data_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func DataSourceUser() common.Resource {
Type: schema.TypeString,
Computed: true,
},
"active": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we switch to GoSDK & common.WorkspaceDataWithParams for this data source?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the issue is that this data source is being used for both the workspace- and account-level. Resources that are being used at both levels cannot use common.WorkspaceDataWithParams, right?

Type: schema.TypeBool,
Computed: true,
},
},
Read: func(ctx context.Context, d *schema.ResourceData, m *common.DatabricksClient) error {
usersAPI := NewUsersAPI(ctx, m)
Expand All @@ -81,6 +85,7 @@ func DataSourceUser() common.Resource {
d.Set("acl_principal_id", fmt.Sprintf("users/%s", user.UserName))
d.Set("external_id", user.ExternalID)
d.Set("application_id", user.ApplicationID)
d.Set("active", user.Active)
splits := strings.Split(user.UserName, "@")
norm := nonAlphanumeric.ReplaceAllLiteralString(splits[0], "_")
norm = strings.ToLower(norm)
Expand Down
2 changes: 2 additions & 0 deletions scim/data_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestDataSourceUser(t *testing.T) {
{
ID: "123",
UserName: "mr.test@example.com",
Active: true,
},
},
},
Expand All @@ -41,6 +42,7 @@ func TestDataSourceUser(t *testing.T) {
assert.Equal(t, d.Get("home"), "/Users/mr.test@example.com")
assert.Equal(t, d.Get("acl_principal_id"), "users/mr.test@example.com")
assert.Equal(t, d.Get("alphanumeric"), "mr_test")
assert.Equal(t, d.Get("active"), true)
}

func TestDataSourceUserGerUser(t *testing.T) {
Expand Down
Loading