Skip to content

Commit 4dd1336

Browse files
csanxCristina Sánchez Sánchezoarbusi
authored
doc: Adds example & documentation for new mongodbatlas_cloud_user_team_assignment resource (#3578)
* Examples * Templates * Docs * Fix * Fix * Fix * Fix * Fix * Fix * Fix whitespace * fix indent * Fix * Regenerated docs * Revert "Fix" This reverts commit 9f0f5b2. * Fix indent * Addressed comments * Formatting fix * Modified example * Fix indent * Fix indent * Changed org docs * Added default --------- Co-authored-by: Cristina Sánchez Sánchez <[email protected]> Co-authored-by: Oriol Arbusi Abadal <[email protected]>
1 parent ffc9755 commit 4dd1336

File tree

16 files changed

+308
-16
lines changed

16 files changed

+308
-16
lines changed

docs/data-sources/cloud_user_org_assignment.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ resource "mongodbatlas_cloud_user_org_assignment" "example" {
1919
2020
data "mongodbatlas_cloud_user_org_assignment" "example_username" {
2121
org_id = var.org_id
22-
username = var.user_email
22+
username = mongodbatlas_cloud_user_org_assignment.example.username
2323
}
2424
2525
data "mongodbatlas_cloud_user_org_assignment" "example_user_id" {
2626
org_id = var.org_id
27-
user_id = var.user_id
27+
user_id = mongodbatlas_cloud_user_org_assignment.example.user_id
2828
}
2929
```
3030

@@ -33,7 +33,7 @@ data "mongodbatlas_cloud_user_org_assignment" "example_user_id" {
3333

3434
### Required
3535

36-
- `org_id` (String) Unique 24-hexadecimal digit string that identifies the organization that contains your projects. Use the [/orgs](#tag/Organizations/operation/listOrganizations) endpoint to retrieve all organizations to which the authenticated user has access.
36+
- `org_id` (String) Unique 24-hexadecimal digit string that identifies the organization that contains your projects. Use the [/orgs](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/group/endpoint-organizations) endpoint to retrieve all organizations to which the authenticated user has access.
3737

3838
### Optional
3939

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Data Source: mongodbatlas_cloud_user_team_assignment
2+
3+
`mongodbatlas_cloud_user_team_assignment` provides a Cloud User Team Assignment data source. The data source lets you retrieve a user assigned to a team.
4+
5+
-> **NOTE**Users with pending invitations created using the deprecated `mongodbatlas_project_invitation` resource or via the deprecated [Invite One MongoDB Cloud User to One Project](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-getorganizationuser#tag/Projects/operation/createProjectInvitation)
6+
endpoint are not returned with this resource. See [MongoDB Atlas API](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-listteamusers) for details.
7+
To manage such users with this resource, refer to our [migration guide]<link-to-migration-guide>.
8+
9+
## Example Usages
10+
11+
```terraform
12+
resource "mongodbatlas_cloud_user_team_assignment" "example" {
13+
org_id = var.org_id
14+
team_id = var.team_id
15+
user_id = var.user_id
16+
}
17+
18+
data "mongodbatlas_cloud_user_team_assignment" "example_user_id" {
19+
org_id = var.org_id
20+
team_id = var.team_id
21+
user_id = mongodbatlas_cloud_user_team_assignment.example.user_id
22+
}
23+
24+
data "mongodbatlas_cloud_user_team_assignment" "example_username" {
25+
org_id = var.org_id
26+
team_id = var.team_id
27+
username = mongodbatlas_cloud_user_team_assignment.example.username
28+
}
29+
```
30+
31+
<!-- schema generated by tfplugindocs -->
32+
## Schema
33+
34+
### Required
35+
36+
- `org_id` (String) Unique 24-hexadecimal digit string that identifies the organization that contains your projects. Use the [/orgs](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/group/endpoint-organizations) endpoint to retrieve all organizations to which the authenticated user has access.
37+
- `team_id` (String) Unique 24-hexadecimal digit string that identifies the team to which you want to assign the MongoDB Cloud user. Use the [/teams](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/group/endpoint-teams) endpoint to retrieve all teams to which the authenticated user has access.
38+
39+
### Optional
40+
41+
- `user_id` (String) Unique 24-hexadecimal digit string that identifies the MongoDB Cloud user.
42+
- `username` (String) Email address that represents the username of the MongoDB Cloud user.
43+
44+
### Read-Only
45+
46+
- `country` (String) Two-character alphabetical string that identifies the MongoDB Cloud user's geographic location. This parameter uses the ISO 3166-1a2 code format.
47+
- `created_at` (String) Date and time when MongoDB Cloud created the current account. This value is in the ISO 8601 timestamp format in UTC.
48+
- `first_name` (String) First or given name that belongs to the MongoDB Cloud user.
49+
- `invitation_created_at` (String) Date and time when MongoDB Cloud sent the invitation. MongoDB Cloud represents this timestamp in ISO 8601 format in UTC.
50+
- `invitation_expires_at` (String) Date and time when the invitation from MongoDB Cloud expires. MongoDB Cloud represents this timestamp in ISO 8601 format in UTC.
51+
- `inviter_username` (String) Username of the MongoDB Cloud user who sent the invitation to join the organization.
52+
- `last_auth` (String) Date and time when the current account last authenticated. This value is in the ISO 8601 timestamp format in UTC.
53+
- `last_name` (String) Last name, family name, or surname that belongs to the MongoDB Cloud user.
54+
- `mobile_number` (String) Mobile phone number that belongs to the MongoDB Cloud user.
55+
- `org_membership_status` (String) 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.
56+
- `roles` (Attributes) Organization and project level roles to assign the MongoDB Cloud user within one organization. (see [below for nested schema](#nestedatt--roles))
57+
- `team_ids` (Set of String) List of unique 24-hexadecimal digit strings that identifies the teams to which this MongoDB Cloud user belongs.
58+
59+
<a id="nestedatt--roles"></a>
60+
### Nested Schema for `roles`
61+
62+
Read-Only:
63+
64+
- `org_roles` (Set of String) One or more organization level roles to assign the MongoDB Cloud user.
65+
- `project_role_assignments` (Attributes Set) List of project level role assignments to assign the MongoDB Cloud user. (see [below for nested schema](#nestedatt--roles--project_role_assignments))
66+
67+
<a id="nestedatt--roles--project_role_assignments"></a>
68+
### Nested Schema for `roles.project_role_assignments`
69+
70+
Read-Only:
71+
72+
- `project_id` (String) Unique 24-hexadecimal digit string that identifies the project to which these roles belong.
73+
- `project_roles` (Set of String) One or more project-level roles assigned to the MongoDB Cloud user.
74+
75+
For more information see: [MongoDB Atlas API - Cloud Users](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-listteamusers) Documentation.

docs/resources/cloud_user_org_assignment.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ resource "mongodbatlas_cloud_user_org_assignment" "example" {
1919
2020
data "mongodbatlas_cloud_user_org_assignment" "example_username" {
2121
org_id = var.org_id
22-
username = var.user_email
22+
username = mongodbatlas_cloud_user_org_assignment.example.username
2323
}
2424
2525
data "mongodbatlas_cloud_user_org_assignment" "example_user_id" {
2626
org_id = var.org_id
27-
user_id = var.user_id
27+
user_id = mongodbatlas_cloud_user_org_assignment.example.user_id
2828
}
2929
```
3030

@@ -33,7 +33,7 @@ data "mongodbatlas_cloud_user_org_assignment" "example_user_id" {
3333

3434
### Required
3535

36-
- `org_id` (String) Unique 24-hexadecimal digit string that identifies the organization that contains your projects. Use the [/orgs](#tag/Organizations/operation/listOrganizations) endpoint to retrieve all organizations to which the authenticated user has access.
36+
- `org_id` (String) Unique 24-hexadecimal digit string that identifies the organization that contains your projects. Use the [/orgs](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/group/endpoint-organizations) endpoint to retrieve all organizations to which the authenticated user has access.
3737
- `roles` (Attributes) Organization and project level roles to assign the MongoDB Cloud user within one organization. (see [below for nested schema](#nestedatt--roles))
3838
- `username` (String) Email address that represents the username of the MongoDB Cloud user.
3939

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Resource: mongodbatlas_cloud_user_team_assignment
2+
3+
`mongodbatlas_cloud_user_team_assignment` provides a Cloud User Team Assignment resource. It lets you manage the association between a cloud user and a team, enabling you to import, assign, remove, or update the user's membership.
4+
5+
-> **NOTE**Users with pending invitations created using the deprecated `mongodbatlas_project_invitation` resource or via the deprecated [Invite One MongoDB Cloud User to One Project](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-getorganizationuser#tag/Projects/operation/createProjectInvitation)
6+
endpoint cannot be managed with this resource. See [MongoDB Atlas API](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-listteamusers) for details.
7+
To manage such users with this resource, refer to our [migration guide]<link-to-migration-guide>.
8+
9+
## Example Usages
10+
11+
```terraform
12+
resource "mongodbatlas_cloud_user_team_assignment" "example" {
13+
org_id = var.org_id
14+
team_id = var.team_id
15+
user_id = var.user_id
16+
}
17+
18+
data "mongodbatlas_cloud_user_team_assignment" "example_user_id" {
19+
org_id = var.org_id
20+
team_id = var.team_id
21+
user_id = mongodbatlas_cloud_user_team_assignment.example.user_id
22+
}
23+
24+
data "mongodbatlas_cloud_user_team_assignment" "example_username" {
25+
org_id = var.org_id
26+
team_id = var.team_id
27+
username = mongodbatlas_cloud_user_team_assignment.example.username
28+
}
29+
```
30+
31+
<!-- schema generated by tfplugindocs -->
32+
## Schema
33+
34+
### Required
35+
36+
- `org_id` (String) Unique 24-hexadecimal digit string that identifies the organization that contains your projects. Use the [/orgs](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/group/endpoint-organizations) endpoint to retrieve all organizations to which the authenticated user has access.
37+
- `team_id` (String) Unique 24-hexadecimal digit string that identifies the team to which you want to assign the MongoDB Cloud user. Use the [/teams](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/group/endpoint-teams) endpoint to retrieve all teams to which the authenticated user has access.
38+
- `user_id` (String) Unique 24-hexadecimal digit string that identifies the MongoDB Cloud user.
39+
40+
### Read-Only
41+
42+
- `country` (String) Two-character alphabetical string that identifies the MongoDB Cloud user's geographic location. This parameter uses the ISO 3166-1a2 code format.
43+
- `created_at` (String) Date and time when MongoDB Cloud created the current account. This value is in the ISO 8601 timestamp format in UTC.
44+
- `first_name` (String) First or given name that belongs to the MongoDB Cloud user.
45+
- `invitation_created_at` (String) Date and time when MongoDB Cloud sent the invitation. MongoDB Cloud represents this timestamp in ISO 8601 format in UTC.
46+
- `invitation_expires_at` (String) Date and time when the invitation from MongoDB Cloud expires. MongoDB Cloud represents this timestamp in ISO 8601 format in UTC.
47+
- `inviter_username` (String) Username of the MongoDB Cloud user who sent the invitation to join the organization.
48+
- `last_auth` (String) Date and time when the current account last authenticated. This value is in the ISO 8601 timestamp format in UTC.
49+
- `last_name` (String) Last name, family name, or surname that belongs to the MongoDB Cloud user.
50+
- `mobile_number` (String) Mobile phone number that belongs to the MongoDB Cloud user.
51+
- `org_membership_status` (String) 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.
52+
- `roles` (Attributes) Organization and project level roles to assign the MongoDB Cloud user within one organization. (see [below for nested schema](#nestedatt--roles))
53+
- `team_ids` (Set of String) List of unique 24-hexadecimal digit strings that identifies the teams to which this MongoDB Cloud user belongs.
54+
- `username` (String) Email address that represents the username of the MongoDB Cloud user.
55+
56+
<a id="nestedatt--roles"></a>
57+
### Nested Schema for `roles`
58+
59+
Read-Only:
60+
61+
- `org_roles` (Set of String) One or more organization level roles to assign the MongoDB Cloud user.
62+
- `project_role_assignments` (Attributes Set) List of project level role assignments to assign the MongoDB Cloud user. (see [below for nested schema](#nestedatt--roles--project_role_assignments))
63+
64+
<a id="nestedatt--roles--project_role_assignments"></a>
65+
### Nested Schema for `roles.project_role_assignments`
66+
67+
Read-Only:
68+
69+
- `project_id` (String) Unique 24-hexadecimal digit string that identifies the project to which these roles belong.
70+
- `project_roles` (Set of String) One or more project-level roles assigned to the MongoDB Cloud user.
71+
72+
## Import
73+
74+
Cloud User Team Assignment resource can be imported using the Org ID & Team ID & User ID OR Org ID & Team ID & Username, in the format `ORG_ID/TEAM_ID/USER_ID` OR `ORG_ID/TEAM_ID/USERNAME`.
75+
76+
```
77+
$ terraform import mongodbatlas_cloud_user_team_assignment.test 63cfbf302333a3011d98592e/9f3c1e7a4d8b2f6051acde47/5f18367ccb7a503a2b481b7a
78+
OR
79+
$ terraform import mongodbatlas_cloud_user_team_assignment.test 63cfbf302333a3011d98592e/9f3c1e7a4d8b2f6051acde47/[email protected]
80+
```
81+
82+
For more information see: [MongoDB Atlas API - Cloud Users](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-addusertoteam) Documentation.

examples/mongodbatlas_cloud_user_org_assignment/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ resource "mongodbatlas_cloud_user_org_assignment" "example" {
88

99
data "mongodbatlas_cloud_user_org_assignment" "example_username" {
1010
org_id = var.org_id
11-
username = var.user_email
11+
username = mongodbatlas_cloud_user_org_assignment.example.username
1212
}
1313

1414
data "mongodbatlas_cloud_user_org_assignment" "example_user_id" {
1515
org_id = var.org_id
16-
user_id = var.user_id
16+
user_id = mongodbatlas_cloud_user_org_assignment.example.user_id
1717
}

examples/mongodbatlas_cloud_user_org_assignment/variables.tf

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ variable "user_email" {
88
type = string
99
}
1010

11-
variable "user_id" {
12-
description = "The user ID"
13-
type = string
14-
}
15-
1611
variable "public_key" {
1712
description = "Atlas API public key"
1813
type = string
14+
default = ""
1915
}
2016

2117
variable "private_key" {
2218
description = "Atlas API private key"
2319
type = string
20+
default = ""
2421
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Example: mongodbatlas_cloud_user_team_assignment
2+
3+
This example demonstrates how to use the `mongodbatlas_cloud_user_team_assignment` resource to assign a user to a team within a MongoDB Atlas organization.
4+
5+
## Usage
6+
7+
```hcl
8+
provider "mongodbatlas" {
9+
public_key = var.public_key
10+
private_key = var.private_key
11+
}
12+
13+
resource "mongodbatlas_cloud_user_team_assignment" "example" {
14+
org_id = var.org_id
15+
team_id = var.team_id
16+
user_id = var.user_id
17+
}
18+
```
19+
20+
You must set the following variables:
21+
- `public_key`: Your MongoDB Atlas API public key.
22+
- `private_key`: Your MongoDB Atlas API private key.
23+
- `org_id`: The ID of the MongoDB Atlas organization.
24+
- `team_id`: The ID of the team to assign the user to.
25+
- `user_id`: The ID of the user to assign to the team.
26+
27+
28+
To learn more, see the [MongoDB Atlas API - Cloud Users](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-addusertoteam) Documentation.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
resource "mongodbatlas_cloud_user_team_assignment" "example" {
2+
org_id = var.org_id
3+
team_id = var.team_id
4+
user_id = var.user_id
5+
}
6+
7+
data "mongodbatlas_cloud_user_team_assignment" "example_user_id" {
8+
org_id = var.org_id
9+
team_id = var.team_id
10+
user_id = mongodbatlas_cloud_user_team_assignment.example.user_id
11+
}
12+
13+
data "mongodbatlas_cloud_user_team_assignment" "example_username" {
14+
org_id = var.org_id
15+
team_id = var.team_id
16+
username = mongodbatlas_cloud_user_team_assignment.example.username
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
output "user_from_username" {
2+
description = "User details retrieved by username"
3+
value = data.mongodbatlas_cloud_user_team_assignment.example_username
4+
}
5+
6+
output "user_from_user_id" {
7+
description = "User details retrieved by user_id"
8+
value = data.mongodbatlas_cloud_user_team_assignment.example_user_id
9+
}
10+
11+
output "assigned_user" {
12+
description = "Details of the user assigned to the team"
13+
value = mongodbatlas_cloud_user_team_assignment.example
14+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
provider "mongodbatlas" {
2+
public_key = var.public_key
3+
private_key = var.private_key
4+
}

0 commit comments

Comments
 (0)