-
Notifications
You must be signed in to change notification settings - Fork 205
feat: Add new singular data source mongodbatlas_cloud_user_project_assignment #3569
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
88fb77b
Add schema and Read() method
85de1f1
Add data source to provider
6e96ca3
Merge branch 'CLOUDP-333176' into CLOUDP-333177
57ebddb
WIP
e5fee7d
Tests
d262341
Merge branch 'CLOUDP-333176' into CLOUDP-333177
8705e44
Merge branch 'CLOUDP-333176' into CLOUDP-333177
19dc803
Changed tests
f7f8ed1
Changelog
8ee68e8
Merge branch 'CLOUDP-333176' into CLOUDP-333177
4200827
Merge branch 'CLOUDP-333176' into CLOUDP-333177
10752de
Refactor
0be853d
Merge branch 'CLOUDP-333176' into CLOUDP-333177
08dae31
Typo
78a17e0
Fix
47634de
Merge branch 'CLOUDP-333176' into CLOUDP-333177
3b40596
Updated tests
dc3404e
Fixed test
23632d3
Fix test naming
e30f800
Added error
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 hidden or 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,3 @@ | ||
```release-note:new-datasource | ||
data-source/mongodbatlas_cloud_user_project_assignment | ||
``` |
This file contains hidden or 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
61 changes: 61 additions & 0 deletions
61
internal/service/clouduserprojectassignment/data_source.go
This file contains hidden or 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,61 @@ | ||
package clouduserprojectassignment | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config" | ||
) | ||
|
||
var _ datasource.DataSource = &cloudUserProjectAssignmentDS{} | ||
var _ datasource.DataSourceWithConfigure = &cloudUserProjectAssignmentDS{} | ||
|
||
func DataSource() datasource.DataSource { | ||
return &cloudUserProjectAssignmentDS{ | ||
DSCommon: config.DSCommon{ | ||
DataSourceName: resourceName, | ||
}, | ||
} | ||
} | ||
|
||
type cloudUserProjectAssignmentDS struct { | ||
config.DSCommon | ||
} | ||
|
||
func (d *cloudUserProjectAssignmentDS) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = dataSourceSchema() | ||
} | ||
|
||
func (d *cloudUserProjectAssignmentDS) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var state TFModel | ||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
connV2 := d.Client.AtlasV2 | ||
projectID := state.ProjectId.ValueString() | ||
userID := state.UserId.ValueString() | ||
username := state.Username.ValueString() | ||
|
||
if username == "" && userID == "" { | ||
resp.Diagnostics.AddError("invalid configuration", "either username or user_id must be provided") | ||
return | ||
} | ||
userResp, err := fetchProjectUser(ctx, connV2, projectID, userID, username) | ||
if err != nil { | ||
resp.Diagnostics.AddError(errorReadingUser, err.Error()) | ||
return | ||
} | ||
if userResp == nil { | ||
resp.Diagnostics.AddError("resource not found", "no user found with the specified identifier") | ||
return | ||
} | ||
|
||
newCloudUserProjectAssignmentModel, diags := NewTFModel(ctx, projectID, userResp) | ||
if diags.HasError() { | ||
resp.Diagnostics.Append(diags...) | ||
return | ||
} | ||
resp.Diagnostics.Append(resp.State.Set(ctx, newCloudUserProjectAssignmentModel)...) | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.