Skip to content

Commit

Permalink
update user group ds
Browse files Browse the repository at this point in the history
  • Loading branch information
cheelim1 committed May 25, 2023
1 parent e40e6b4 commit 10966ea
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions jumpcloud/data_source_user_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,20 @@ func dataSourceJumpCloudUserGroupRead(d *schema.ResourceData, m interface{}) err

filter := fmt.Sprintf(`{"name":"%s"}`, groupName)

page := 0
limit := 100 // Adjust the limit as per your requirement

for {
groups, _, err := client.UserGroupsApi.GroupsUserList(context.Background(), "_id, name", filter, nil)
if err != nil {
return err
}

for _, group := range groups {
if group.Name == groupName {
d.SetId(group.Id)
return nil
}
}
groups, _, err := client.UserGroupsApi.GroupsUserList(context.Background(), "application/json", "application/json", map[string]interface{}{
"filter": filter,
"limit": 0, // No limit specified to retrieve all matching groups
"sort": []string{},
})
if err != nil {
return err
}

if len(groups) < limit {
break
for _, group := range groups {
if group.Name == groupName {
d.SetId(group.Id)
return nil
}

page++
}

return fmt.Errorf("No user group found with name: %s", groupName)
Expand Down

0 comments on commit 10966ea

Please sign in to comment.