-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathdata_source_user_roles.go
43 lines (35 loc) · 1.15 KB
/
data_source_user_roles.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package octopusdeploy
import (
"context"
"time"
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceUserRoles() *schema.Resource {
return &schema.Resource{
Description: "Provides information about existing user roles.",
ReadContext: dataSourceUserRolesRead,
Schema: getUserRoleDataSchema(),
}
}
func dataSourceUserRolesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
query := octopusdeploy.UserRolesQuery{
IDs: expandArray(d.Get("ids").([]interface{})),
PartialName: d.Get("partial_name").(string),
Skip: d.Get("skip").(int),
Take: d.Get("take").(int),
}
client := meta.(*octopusdeploy.Client)
users, err := client.UserRoles.Get(query)
if err != nil {
return diag.FromErr(err)
}
flattenedUserRoles := []interface{}{}
for _, user := range users.Items {
flattenedUserRoles = append(flattenedUserRoles, flattenUserRole(user))
}
d.Set("user_roles", flattenedUserRoles)
d.SetId("UserRoles " + time.Now().UTC().String())
return nil
}