Skip to content

Commit

Permalink
PowerScale User Datasource (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
taohe1012 authored Jul 29, 2023
1 parent 070a35d commit ff2e01a
Show file tree
Hide file tree
Showing 11 changed files with 1,053 additions and 2 deletions.
106 changes: 106 additions & 0 deletions docs/data-sources/user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
# Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
#
# Licensed under the Mozilla Public License Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://mozilla.org/MPL/2.0/
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

title: "powerscale_user data source"
linkTitle: "powerscale_user"
page_title: "powerscale_user Data Source - terraform-provider-powerscale"
subcategory: ""
description: |-
Data source for reading Users in PowerScale cluster.
---

# powerscale_user (Data Source)

Data source for reading Users in PowerScale cluster.



<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `filter` (Block, Optional) (see [below for nested schema](#nestedblock--filter))

### Read-Only

- `id` (String) Unique identifier of the user instance.
- `users` (Attributes List) List of users. (see [below for nested schema](#nestedatt--users))

<a id="nestedblock--filter"></a>
### Nested Schema for `filter`

Optional:

- `cached` (Boolean) If true, only return cached objects.
- `domain` (String) Filter users by domain.
- `member_of` (Boolean) Enumerate all users that a group is a member of.
- `name_prefix` (String) Filter users by name prefix.
- `names` (Attributes List) List of user identity. (see [below for nested schema](#nestedatt--filter--names))
- `provider` (String) Filter users by provider.
- `resolve_names` (Boolean) Resolve names of personas.
- `zone` (String) Filter users by zone.

<a id="nestedatt--filter--names"></a>
### Nested Schema for `filter.names`

Optional:

- `name` (String) Specifies a user name.
- `uid` (Number) Specifies a numeric user identifier.



<a id="nestedatt--users"></a>
### Nested Schema for `users`

Optional:

- `dn` (String) Specifies a principal name for the user.
- `dns_domain` (String) Specifies the DNS domain.
- `domain` (String) Specifies the domain that the object is part of.
- `email` (String) Specifies an email address.
- `enabled` (Boolean) If true, the authenticated user is enabled.
- `expired` (Boolean) If true, the authenticated user has expired.
- `expiry` (Number) Specifies the Unix Epoch time at which the authenticated user will expire.
- `gecos` (String) Specifies the GECOS value, which is usually the full name.
- `generated_gid` (Boolean) If true, the GID was generated.
- `generated_uid` (Boolean) If true, the UID was generated.
- `generated_upn` (Boolean) If true, the UPN was generated.
- `gid` (String) Specifies a group identifier.
- `home_directory` (String) Specifies a home directory for the user.
- `id` (String) Specifies the user ID.
- `locked` (Boolean) If true, indicates that the account is locked.
- `max_password_age` (Number) Specifies the maximum time in seconds allowed before the password expires.
- `name` (String) Specifies a user name.
- `password_expired` (Boolean) If true, the password has expired.
- `password_expires` (Boolean) If true, the password is allowed to expire.
- `password_expiry` (Number) Specifies the time in Unix Epoch seconds that the password will expire.
- `password_last_set` (Number) Specifies the last time the password was set.
- `primary_group_sid` (String) Specifies the persona of the primary group.
- `prompt_password_change` (Boolean) If true, Prompts the user to change their password at the next login.
- `provider` (String) Specifies the authentication provider that the object belongs to.
- `sam_account_name` (String) Specifies a user name.
- `shell` (String) Specifies a path to the shell for the user.
- `sid` (String) Specifies a security identifier.
- `type` (String) Specifies the object type.
- `uid` (String) Specifies a user identifier.
- `upn` (String) Specifies a principal name for the user.
- `user_can_change_password` (Boolean) Specifies whether the password for the user can be changed.

Read-Only:

- `roles` (List of String) List of roles.
4 changes: 2 additions & 2 deletions examples/data-sources/powerscale_access_zone/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ provider "powerscale" {
endpoint = var.endpoint
insecure = var.insecure
group = var.group
volumes_path = var.volumes_path
volumes_path_permissions = var.volumes_path_permissions
volume_path = var.volume_path
volume_path_permissions = var.volume_path_permissions
ignore_unresolvable_hosts = var.ignore_unresolvable_hosts
auth_type = var.auth_type
verbose_logging = var.verbose_logging
Expand Down
51 changes: 51 additions & 0 deletions examples/data-sources/powerscale_user/datasource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

data "powerscale_user" "test_user" {
filter {
names = [
# {
# uid = 0
# },
# {
# name = "admin"
# },
{
name = "tfaccUserDatasource"
uid = 10000
}
]
cached = false
name_prefix = "tfacc"
resolve_names = false
member_of = false
# domain = "testDomain"
# zone = "testZone"
# provider = "testProvider"
}
}

output "powerscale_user_filter" {
value = data.powerscale_user.test_user
}

data "powerscale_user" "test_all_user" {
}

output "powerscale_user_all" {
value = data.powerscale_user.test_all_user
}
36 changes: 36 additions & 0 deletions examples/data-sources/powerscale_user/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
terraform {
required_providers {
powerscale = {
source = "registry.terraform.io/dell/powerscale"
}
}
}

provider "powerscale" {
username = var.username
password = var.password
endpoint = var.endpoint
insecure = var.insecure
group = var.group
volume_path = var.volume_path
volume_path_permissions = var.volume_path_permissions
ignore_unresolvable_hosts = var.ignore_unresolvable_hosts
auth_type = var.auth_type
verbose_logging = var.verbose_logging
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-testing v1.3.0
github.com/joho/godotenv v1.5.1
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
)

require (
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
91 changes: 91 additions & 0 deletions powerscale/helper/user_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
Copyright (c) 2023 Dell Inc., or its subsidiaries. All Rights Reserved.
Licensed under the Mozilla Public License Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://mozilla.org/MPL/2.0/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package helper

import (
powerscale "dell/powerscale-go-client"
"terraform-provider-powerscale/powerscale/models"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
)

// UpdateUserDataSourceState updates datasource state.
func UpdateUserDataSourceState(userState *models.UserDataSourceModel, userResponse []powerscale.V1MappingUsersLookupMappingItemUser, roles []powerscale.V1AuthRoleExtended) {
for _, user := range userResponse {
var model models.UserModel
UpdateUserState(&model, user)

var roleAttrs []attr.Value
for _, r := range roles {
for _, m := range r.Members {
if *m.Id == *user.Uid.Id {
roleAttrs = append(roleAttrs, types.StringValue(r.Name))
}
}
}
model.Roles, _ = types.ListValue(types.StringType, roleAttrs)
userState.Users = append(userState.Users, model)
}
}

// UpdateUserState updates user state.
func UpdateUserState(model *models.UserModel, user powerscale.V1MappingUsersLookupMappingItemUser) {

model.Dn = types.StringValue(user.Dn)
model.DNSDomain = types.StringValue(user.DnsDomain)
model.Domain = types.StringValue(user.Domain)
model.Email = types.StringValue(user.Email)
model.Gecos = types.StringValue(user.Gecos)
model.HomeDirectory = types.StringValue(user.HomeDirectory)
model.ID = types.StringValue(user.Id)
model.Name = types.StringValue(user.Name)
model.Provider = types.StringValue(user.Provider)
model.SamAccountName = types.StringValue(user.SamAccountName)
model.Shell = types.StringValue(user.Shell)
model.Type = types.StringValue(user.Type)
model.Upn = types.StringValue(user.Upn)
if user.Gid.Id != nil {
model.GID = types.StringValue(*user.Gid.Id)
}
if user.PrimaryGroupSid.Id != nil {
model.PrimaryGroupSID = types.StringValue(*user.PrimaryGroupSid.Id)
}
if user.Sid.Id != nil {
model.SID = types.StringValue(*user.Sid.Id)
}
if user.Uid.Id != nil {
model.UID = types.StringValue(*user.Uid.Id)
}

model.Enabled = types.BoolValue(user.Enabled)
model.Expired = types.BoolValue(user.Expired)
model.GeneratedGID = types.BoolValue(user.GeneratedGid)
model.GeneratedUID = types.BoolValue(user.GeneratedUid)
model.GeneratedUpn = types.BoolValue(user.GeneratedUpn)
model.Locked = types.BoolValue(user.Locked)
model.PasswordExpired = types.BoolValue(user.PasswordExpired)
model.PasswordExpires = types.BoolValue(user.PasswordExpires)
model.PromptPasswordChange = types.BoolValue(user.PromptPasswordChange)
model.UserCanChangePassword = types.BoolValue(user.UserCanChangePassword)

model.Expiry = types.Int64Value(int64(user.Expiry))
model.MaxPasswordAge = types.Int64Value(int64(user.MaxPasswordAge))
model.PasswordExpiry = types.Int64Value(int64(user.PasswordExpiry))
model.PasswordLastSet = types.Int64Value(int64(user.PasswordLastSet))
}
Loading

0 comments on commit ff2e01a

Please sign in to comment.