-
Notifications
You must be signed in to change notification settings - Fork 188
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
fix: Adds pagination in mongodbatlas_team
resource & data source
#2919
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
59e635a
update to use AllPages
maastha 6af76f5
minor
maastha 827d93b
changelog
maastha 22fd4f6
update resource
maastha 5c56753
undo
maastha 489f55c
min
maastha 5ad54f3
min
maastha aad2f70
minor
maastha 2e6a222
changelog
maastha 1bc70a3
Merge branch 'master' into CLOUDP-289122-teams-ds
maastha 040f973
minor
maastha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```release-note:bug | ||
data-source/mongodbatlas_team: Fixes pagination logic when retrieved users of a team | ||
``` | ||
|
||
```release-note:bug | ||
resource/mongodbatlas_team: Fixes pagination logic when retrieved users of a team | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,17 @@ import ( | |
"context" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"go.mongodb.org/atlas-sdk/v20241113003/admin" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" | ||
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" | ||
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/dsschema" | ||
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config" | ||
|
||
"go.mongodb.org/atlas-sdk/v20241113003/admin" | ||
) | ||
|
||
func DataSource() *schema.Resource { | ||
|
@@ -77,21 +80,26 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag. | |
} | ||
|
||
if err := d.Set("team_id", team.GetId()); err != nil { | ||
return diag.FromErr(fmt.Errorf(errorTeamSetting, "name", d.Id(), err)) | ||
return diag.FromErr(fmt.Errorf(errorTeamSetting, "team_id", d.Id(), err)) | ||
} | ||
|
||
if err := d.Set("name", team.GetName()); err != nil { | ||
return diag.FromErr(fmt.Errorf(errorTeamSetting, "name", d.Id(), err)) | ||
} | ||
|
||
users, _, err := connV2.TeamsApi.ListTeamUsers(ctx, orgID, team.GetId()).Execute() | ||
teamUsers, err := dsschema.AllPages(ctx, func(ctx context.Context, pageNum int) (dsschema.PaginateResponse[admin.CloudAppUser], *http.Response, error) { | ||
maastha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
request := connV2.TeamsApi.ListTeamUsers(ctx, orgID, team.GetId()) | ||
request = request.PageNum(pageNum) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have to provide There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, not required |
||
return request.Execute() | ||
}) | ||
|
||
if err != nil { | ||
return diag.FromErr(fmt.Errorf(errorTeamRead, err)) | ||
} | ||
|
||
usernames := []string{} | ||
for i := range users.GetResults() { | ||
usernames = append(usernames, users.GetResults()[i].GetUsername()) | ||
for i := range teamUsers { | ||
usernames = append(usernames, teamUsers[i].GetUsername()) | ||
} | ||
|
||
if err := d.Set("usernames", usernames); err != nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice spotted