Skip to content

Commit c33368a

Browse files
csanxCristina Sánchez Sánchez
andauthored
feat: Adds users attribute to mongodbatlas_projects plural data source (#3451)
* WIP * Fixed acceptance test * Added a comment * Added changelog * Added users attribute to projects data source * Added changelog and fixed docs * Factored out users schema * Refactored schemas and fixed test and doc * Minor code review suggestions and fixed doc --------- Co-authored-by: Cristina Sánchez Sánchez <cristina.sanchez@mongodb.com>
1 parent 77b1965 commit c33368a

File tree

7 files changed

+173
-373
lines changed

7 files changed

+173
-373
lines changed

.changelog/3451.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
data-source/mongodbatlas_projects: Adds `users` attribute
3+
```

docs/data-sources/project.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,7 @@ In addition to all arguments above, the following attributes are exported:
124124
* `lastName`- Last name, family name, or surname that belongs to the MongoDB Cloud user.
125125
* `mobileNumber` - Mobile phone number that belongs to the MongoDB Cloud user.
126126

127+
~> **NOTE:** - Does not return pending users invited via the deprecated [Invite One MongoDB Cloud User to Join One Project](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-createprojectinvitation) endpoint or pending invitations created using [`mongodbatlas_project_invitation`](../resources/project_invitation.md) resource.
128+
127129

128130
See [MongoDB Atlas API - Project](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Projects) - [and MongoDB Atlas API - Teams](https://docs.atlas.mongodb.com/reference/api/project-get-teams/) Documentation for more information.

docs/data-sources/projects.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ data "mongodbatlas_projects" "test" {
5151

5252
* `name` - The name of the project you want to create.
5353
* `org_id` - The ID of the organization you want to create the project within.
54+
* `project_id`- Unique 24-hexadecimal digit string that identifies the MongoDB Cloud project.
5455
* `cluster_count` - The number of Atlas clusters deployed in the project.
5556
* `created` - The ISO-8601-formatted timestamp of when Atlas created the project.
5657
* `tags` - Map that contains key-value pairs between 1 to 255 characters in length for tagging and categorizing the project. To learn more, see [Resource Tags](https://www.mongodb.com/docs/atlas/tags/)
5758
* `teams` - Returns all teams to which the authenticated user has access in the project. See [Teams](#teams).
5859
* `limits` - The limits for the specified project. See [Limits](#limits).
5960
* `ip_addresses` - IP addresses in a project categorized by services. See [IP Addresses](#ip-addresses). **WARNING:** This attribute is deprecated, use the `mongodbatlas_project_ip_addresses` data source instead.
60-
61+
* `users` - Returns list of all pending and active MongoDB Cloud users associated with the specified project.
6162
* `is_collect_database_specifics_statistics_enabled` - Flag that indicates whether to enable statistics in [cluster metrics](https://www.mongodb.com/docs/atlas/monitor-cluster-metrics/) collection for the project.
6263
* `is_data_explorer_enabled` - Flag that indicates whether to enable Data Explorer for the project. If enabled, you can query your database with an easy to use interface.
6364
* `is_extended_storage_sizes_enabled` - Flag that indicates whether to enable extended storage sizes for the specified project.
@@ -87,5 +88,18 @@ data "mongodbatlas_projects" "test" {
8788
* `services.clusters.#.inbound` - List of inbound IP addresses associated with the cluster. If your network allows outbound HTTP requests only to specific IP addresses, you must allow access to the following IP addresses so that your application can connect to your Atlas cluster.
8889
* `services.clusters.#.outbound` - List of outbound IP addresses associated with the cluster. If your network allows inbound HTTP requests only from specific IP addresses, you must allow access from the following IP addresses so that your Atlas cluster can communicate with your webhooks and KMS.
8990

91+
### Users
92+
* `id`- Unique 24-hexadecimal digit string that identifies the MongoDB Cloud user.
93+
* `orgMembershipStatus`- String enum that indicates whether the MongoDB Cloud user has a pending invitation to join the organization or they are already active in the organization.
94+
* `roles`- One or more project-level roles assigned to the MongoDB Cloud user.
95+
* `username`- Email address that represents the username of the MongoDB Cloud user.
96+
* `country`- Two-character alphabetical string that identifies the MongoDB Cloud user's geographic location. This parameter uses the ISO 3166-1a2 code format.
97+
* `createdAt`- Date and time when MongoDB Cloud created the current account. This value is in the ISO 8601 timestamp format in UTC.
98+
* `firstName`- First or given name that belongs to the MongoDB Cloud user.
99+
* `lastAuth` - Date and time when the current account last authenticated. This value is in the ISO 8601 timestamp format in UTC.
100+
* `lastName`- Last name, family name, or surname that belongs to the MongoDB Cloud user.
101+
* `mobileNumber` - Mobile phone number that belongs to the MongoDB Cloud user.
102+
103+
~> **NOTE:** - Does not return pending users invited via the deprecated [Invite One MongoDB Cloud User to Join One Project](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-createprojectinvitation) endpoint or pending invitations created using [`mongodbatlas_project_invitation`](../resources/project_invitation.md) resource.
90104

91105
See [MongoDB Atlas API - Projects](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Projects) - [and MongoDB Atlas API - Teams](https://docs.atlas.mongodb.com/reference/api/project-get-teams/) Documentation for more information.

internal/service/project/data_source_project.go

Lines changed: 3 additions & 219 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ import (
77

88
"go.mongodb.org/atlas-sdk/v20250312004/admin"
99

10-
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1110
"github.com/hashicorp/terraform-plugin-framework/datasource"
12-
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
13-
"github.com/hashicorp/terraform-plugin-framework/path"
14-
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
15-
"github.com/hashicorp/terraform-plugin-framework/types"
16-
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant"
1711
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
1812
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/dsschema"
1913
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
@@ -34,220 +28,10 @@ type projectDS struct {
3428
config.DSCommon
3529
}
3630

37-
type TFProjectDSModel struct {
38-
Tags types.Map `tfsdk:"tags"`
39-
IPAddresses types.Object `tfsdk:"ip_addresses"`
40-
Created types.String `tfsdk:"created"`
41-
OrgID types.String `tfsdk:"org_id"`
42-
RegionUsageRestrictions types.String `tfsdk:"region_usage_restrictions"`
43-
ID types.String `tfsdk:"id"`
44-
Name types.String `tfsdk:"name"`
45-
ProjectID types.String `tfsdk:"project_id"`
46-
Teams []*TFTeamDSModel `tfsdk:"teams"`
47-
Limits []*TFLimitModel `tfsdk:"limits"`
48-
Users []*TFCloudUsersDSModel `tfsdk:"users"`
49-
ClusterCount types.Int64 `tfsdk:"cluster_count"`
50-
IsCollectDatabaseSpecificsStatisticsEnabled types.Bool `tfsdk:"is_collect_database_specifics_statistics_enabled"`
51-
IsRealtimePerformancePanelEnabled types.Bool `tfsdk:"is_realtime_performance_panel_enabled"`
52-
IsSchemaAdvisorEnabled types.Bool `tfsdk:"is_schema_advisor_enabled"`
53-
IsPerformanceAdvisorEnabled types.Bool `tfsdk:"is_performance_advisor_enabled"`
54-
IsExtendedStorageSizesEnabled types.Bool `tfsdk:"is_extended_storage_sizes_enabled"`
55-
IsDataExplorerEnabled types.Bool `tfsdk:"is_data_explorer_enabled"`
56-
IsSlowOperationThresholdingEnabled types.Bool `tfsdk:"is_slow_operation_thresholding_enabled"`
57-
}
58-
59-
type TFTeamDSModel struct {
60-
TeamID types.String `tfsdk:"team_id"`
61-
RoleNames types.List `tfsdk:"role_names"`
62-
}
63-
64-
type TFCloudUsersDSModel struct {
65-
ID types.String `tfsdk:"id"`
66-
OrgMembershipStatus types.String `tfsdk:"org_membership_status"`
67-
Roles types.List `tfsdk:"roles"`
68-
Username types.String `tfsdk:"username"`
69-
InvitationCreatedAt types.String `tfsdk:"invitation_created_at"`
70-
InvitationExpiresAt types.String `tfsdk:"invitation_expires_at"`
71-
InviterUsername types.String `tfsdk:"inviter_username"`
72-
Country types.String `tfsdk:"country"`
73-
CreatedAt types.String `tfsdk:"created_at"`
74-
FirstName types.String `tfsdk:"first_name"`
75-
LastAuth types.String `tfsdk:"last_auth"`
76-
LastName types.String `tfsdk:"last_name"`
77-
MobileNumber types.String `tfsdk:"mobile_number"`
78-
}
79-
8031
func (d *projectDS) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
81-
resp.Schema = schema.Schema{
82-
Attributes: map[string]schema.Attribute{
83-
"id": schema.StringAttribute{
84-
Computed: true,
85-
},
86-
"project_id": schema.StringAttribute{
87-
Optional: true,
88-
Validators: []validator.String{
89-
stringvalidator.ConflictsWith(path.MatchRoot("name")),
90-
},
91-
},
92-
"name": schema.StringAttribute{
93-
Optional: true,
94-
Validators: []validator.String{
95-
stringvalidator.ConflictsWith(path.MatchRoot("project_id")),
96-
},
97-
},
98-
"org_id": schema.StringAttribute{
99-
Computed: true,
100-
},
101-
"cluster_count": schema.Int64Attribute{
102-
Computed: true,
103-
},
104-
"created": schema.StringAttribute{
105-
Computed: true,
106-
},
107-
"is_collect_database_specifics_statistics_enabled": schema.BoolAttribute{
108-
Computed: true,
109-
},
110-
"is_data_explorer_enabled": schema.BoolAttribute{
111-
Computed: true,
112-
},
113-
"is_extended_storage_sizes_enabled": schema.BoolAttribute{
114-
Computed: true,
115-
},
116-
"is_performance_advisor_enabled": schema.BoolAttribute{
117-
Computed: true,
118-
},
119-
"is_realtime_performance_panel_enabled": schema.BoolAttribute{
120-
Computed: true,
121-
},
122-
"is_schema_advisor_enabled": schema.BoolAttribute{
123-
Computed: true,
124-
},
125-
"is_slow_operation_thresholding_enabled": schema.BoolAttribute{
126-
DeprecationMessage: constant.DeprecationParam, // added deprecation in CLOUDP-293855 because was deprecated in the doc
127-
Computed: true,
128-
},
129-
"region_usage_restrictions": schema.StringAttribute{
130-
Computed: true,
131-
},
132-
"teams": schema.ListNestedAttribute{
133-
Computed: true,
134-
NestedObject: schema.NestedAttributeObject{
135-
Attributes: map[string]schema.Attribute{
136-
"team_id": schema.StringAttribute{
137-
Computed: true,
138-
},
139-
"role_names": schema.ListAttribute{
140-
Computed: true,
141-
ElementType: types.StringType,
142-
},
143-
},
144-
},
145-
},
146-
"limits": schema.SetNestedAttribute{
147-
Computed: true,
148-
NestedObject: schema.NestedAttributeObject{
149-
Attributes: map[string]schema.Attribute{
150-
"name": schema.StringAttribute{
151-
Computed: true,
152-
},
153-
"value": schema.Int64Attribute{
154-
Computed: true,
155-
},
156-
"current_usage": schema.Int64Attribute{
157-
Computed: true,
158-
},
159-
"default_limit": schema.Int64Attribute{
160-
Computed: true,
161-
},
162-
"maximum_limit": schema.Int64Attribute{
163-
Computed: true,
164-
},
165-
},
166-
},
167-
},
168-
"ip_addresses": schema.SingleNestedAttribute{
169-
Computed: true,
170-
DeprecationMessage: fmt.Sprintf(constant.DeprecationParamWithReplacement, "mongodbatlas_project_ip_addresses data source"),
171-
Attributes: map[string]schema.Attribute{
172-
"services": schema.SingleNestedAttribute{
173-
Computed: true,
174-
Attributes: map[string]schema.Attribute{
175-
"clusters": schema.ListNestedAttribute{
176-
Computed: true,
177-
NestedObject: schema.NestedAttributeObject{
178-
Attributes: map[string]schema.Attribute{
179-
"cluster_name": schema.StringAttribute{
180-
Computed: true,
181-
},
182-
"inbound": schema.ListAttribute{
183-
ElementType: types.StringType,
184-
Computed: true,
185-
},
186-
"outbound": schema.ListAttribute{
187-
ElementType: types.StringType,
188-
Computed: true,
189-
},
190-
},
191-
},
192-
},
193-
},
194-
},
195-
},
196-
},
197-
"tags": schema.MapAttribute{
198-
ElementType: types.StringType,
199-
Computed: true,
200-
},
201-
"users": schema.SetNestedAttribute{
202-
Computed: true,
203-
NestedObject: schema.NestedAttributeObject{
204-
Attributes: map[string]schema.Attribute{
205-
"id": schema.StringAttribute{
206-
Computed: true,
207-
},
208-
"org_membership_status": schema.StringAttribute{
209-
Computed: true,
210-
},
211-
"roles": schema.ListAttribute{
212-
Computed: true,
213-
ElementType: types.StringType,
214-
},
215-
"username": schema.StringAttribute{
216-
Computed: true,
217-
},
218-
"invitation_created_at": schema.StringAttribute{
219-
Computed: true,
220-
},
221-
"invitation_expires_at": schema.StringAttribute{
222-
Computed: true,
223-
},
224-
"inviter_username": schema.StringAttribute{
225-
Computed: true,
226-
},
227-
"country": schema.StringAttribute{
228-
Computed: true,
229-
},
230-
"created_at": schema.StringAttribute{
231-
Computed: true,
232-
},
233-
"first_name": schema.StringAttribute{
234-
Computed: true,
235-
},
236-
"last_auth": schema.StringAttribute{
237-
Computed: true,
238-
},
239-
"last_name": schema.StringAttribute{
240-
Computed: true,
241-
},
242-
"mobile_number": schema.StringAttribute{
243-
Computed: true,
244-
},
245-
},
246-
},
247-
},
248-
},
249-
}
250-
conversion.UpdateSchemaDescription(&resp.Schema)
32+
resp.Schema = conversion.DataSourceSchemaFromResource(ResourceSchema(ctx), &conversion.DataSourceSchemaRequest{
33+
OverridenFields: dataSourceOverridenFields(),
34+
})
25135
}
25236

25337
func (d *projectDS) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {

0 commit comments

Comments
 (0)