Skip to content

doc: Adds example & documentation for new mongodbatlas_cloud_user_team_assignment resource #3578

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

Open
wants to merge 19 commits into
base: CLOUDP-320243-dev-2.0.0
Choose a base branch
from
75 changes: 75 additions & 0 deletions docs/data-sources/cloud_user_team_assignment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Data Source: mongodbatlas_cloud_user_team_assignment
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related to this PR, but in case you didn't know, you can use https://registry.terraform.io/tools/doc-preview - learned it from @AgustinBettati

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's also in the makefile

@echo "Use this site to preview markdown rendering: https://registry.terraform.io/tools/doc-preview"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already used that! It was super helpful for detecting small issues 👍🏻


`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.

-> **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)
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.
To manage such users with this resource, refer to our [migration guide]<link-to-migration-guide>.

## Example Usages

```terraform
resource "mongodbatlas_cloud_user_team_assignment" "example" {
org_id = var.org_id
team_id = var.team_id
user_id = var.user_id
}

data "mongodbatlas_cloud_user_team_assignment" "example_user_id" {
org_id = var.org_id
team_id = var.team_id
user_id = var.user_id
}

data "mongodbatlas_cloud_user_team_assignment" "example_username" {
org_id = var.org_id
team_id = var.team_id
username = var.user_email
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data types here should all be lowercase. i.e. (String) -> (string)

another question here: do we usually add the data type? looking over a smattering of resource and data source examples and I don't see this as a common convention. Is this from the generated schema?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, autogenerated

- `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](#tag/Teams/operation/listTeams) endpoint to retrieve all teams to which the authenticated user has access.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace relative link with absolute link to API docs. Or should this be updated to link to a terraform construct?


### Optional

- `user_id` (String) Unique 24-hexadecimal digit string that identifies the MongoDB Cloud user.
- `username` (String) Email address that represents the username of the MongoDB Cloud user.

### Read-Only

- `country` (String) Two-character alphabetical string that identifies the MongoDB Cloud user's geographic location. This parameter uses the ISO 3166-1a2 code format.
- `created_at` (String) Date and time when MongoDB Cloud created the current account. This value is in the ISO 8601 timestamp format in UTC.
- `first_name` (String) First or given name that belongs to the MongoDB Cloud user.
- `invitation_created_at` (String) Date and time when MongoDB Cloud sent the invitation. MongoDB Cloud represents this timestamp in ISO 8601 format in UTC.
- `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.
- `inviter_username` (String) Username of the MongoDB Cloud user who sent the invitation to join the organization.
- `last_auth` (String) Date and time when the current account last authenticated. This value is in the ISO 8601 timestamp format in UTC.
- `last_name` (String) Last name, family name, or surname that belongs to the MongoDB Cloud user.
- `mobile_number` (String) Mobile phone number that belongs to the MongoDB Cloud user.
- `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.
- `roles` (Attributes) Organization and project level roles to assign the MongoDB Cloud user within one organization. (see [below for nested schema](#nestedatt--roles))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't often use "attributes" in the docs. Is this an object / list of objects?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autogenerated

- `team_ids` (Set of String) List of unique 24-hexadecimal digit strings that identifies the teams to which this MongoDB Cloud user belongs.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment below as well re: set

Suggested change
- `team_ids` (Set of String) List of unique 24-hexadecimal digit strings that identifies the teams to which this MongoDB Cloud user belongs.
- `team_ids` (set of strings) List of unique 24-hexadecimal digit strings that identifies the teams to which this MongoDB Cloud user belongs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autogenerated


<a id="nestedatt--roles"></a>
### Nested Schema for `roles`

Read-Only:

- `org_roles` (Set of String) One or more organization level roles to assign the MongoDB Cloud user.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we usually use "list" or "array" in the docs instead of "set". Does the distinction matter here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autogenerated

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string should be plural

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autogenerated

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is incorrect grammatically in english. is there anything we can do to tweak it?

- `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))

<a id="nestedatt--roles--project_role_assignments"></a>
### Nested Schema for `roles.project_role_assignments`

Read-Only:

- `project_id` (String) Unique 24-hexadecimal digit string that identifies the project to which these roles belong.
- `project_roles` (Set of String) One or more project-level roles assigned to the MongoDB Cloud user.

For more information see: [MongoDB Atlas API - Cloud Users](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-listteamusers) Documentation.
82 changes: 82 additions & 0 deletions docs/resources/cloud_user_team_assignment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Resource: mongodbatlas_cloud_user_team_assignment

`mongodbatlas_cloud_user_team_assignment` provides a Cloud User Team Assignment resource. The resource lets you import, assign, remove, or update a user to a team.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"update a user to a team" is somewhat uncommon construction. Is there a different verb we could use to better describe the behavior?


-> **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)
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.
To manage such users with this resource, refer to our [migration guide]<link-to-migration-guide>.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one note: to make sure we really don't forget these placeholder links (<link-to-migration-guide>) I would probably stay consistent with the same keyword (the one you've used <link-to-migration-guide> is ok) and then create a CLOUDP ticket to search for all those occurrences.

This is valid if you're planning to merge this PR with that placeholder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we already have a ticket CLOUDP-329711
I updated the description to flag that this is the specific keyword.


## Example Usages

```terraform
resource "mongodbatlas_cloud_user_team_assignment" "example" {
org_id = var.org_id
team_id = var.team_id
user_id = var.user_id
}

data "mongodbatlas_cloud_user_team_assignment" "example_user_id" {
org_id = var.org_id
team_id = var.team_id
user_id = var.user_id
}

data "mongodbatlas_cloud_user_team_assignment" "example_username" {
org_id = var.org_id
team_id = var.team_id
username = var.user_email
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `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.
- `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](#tag/Teams/operation/listTeams) endpoint to retrieve all teams to which the authenticated user has access.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this relative link should be replaced with an absolute one

- `user_id` (String) Unique 24-hexadecimal digit string that identifies the MongoDB Cloud user.

### Read-Only

- `country` (String) Two-character alphabetical string that identifies the MongoDB Cloud user's geographic location. This parameter uses the ISO 3166-1a2 code format.
- `created_at` (String) Date and time when MongoDB Cloud created the current account. This value is in the ISO 8601 timestamp format in UTC.
- `first_name` (String) First or given name that belongs to the MongoDB Cloud user.
- `invitation_created_at` (String) Date and time when MongoDB Cloud sent the invitation. MongoDB Cloud represents this timestamp in ISO 8601 format in UTC.
- `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.
- `inviter_username` (String) Username of the MongoDB Cloud user who sent the invitation to join the organization.
- `last_auth` (String) Date and time when the current account last authenticated. This value is in the ISO 8601 timestamp format in UTC.
- `last_name` (String) Last name, family name, or surname that belongs to the MongoDB Cloud user.
- `mobile_number` (String) Mobile phone number that belongs to the MongoDB Cloud user.
- `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.
- `roles` (Attributes) Organization and project level roles to assign the MongoDB Cloud user within one organization. (see [below for nested schema](#nestedatt--roles))
- `team_ids` (Set of String) List of unique 24-hexadecimal digit strings that identifies the teams to which this MongoDB Cloud user belongs.
- `username` (String) Email address that represents the username of the MongoDB Cloud user.

<a id="nestedatt--roles"></a>
### Nested Schema for `roles`

Read-Only:

- `org_roles` (Set of String) One or more organization level roles to assign the MongoDB Cloud user.
- `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))

<a id="nestedatt--roles--project_role_assignments"></a>
### Nested Schema for `roles.project_role_assignments`

Read-Only:

- `project_id` (String) Unique 24-hexadecimal digit string that identifies the project to which these roles belong.
- `project_roles` (Set of String) One or more project-level roles assigned to the MongoDB Cloud user.

## Import

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`.

```
$ terraform import mongodbatlas_cloud_user_team_assignment.test 63cfbf302333a3011d98592e/9f3c1e7a4d8b2f6051acde47/5f18367ccb7a503a2b481b7a
OR
$ terraform import mongodbatlas_cloud_user_team_assignment.test 63cfbf302333a3011d98592e/9f3c1e7a4d8b2f6051acde47/[email protected]
```

For more information see: [MongoDB Atlas API - Cloud Users](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-addusertoteam) Documentation.
28 changes: 28 additions & 0 deletions examples/mongodbatlas_cloud_user_team_assignment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Example: mongodbatlas_cloud_user_team_assignment
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maastha @csanx this example is great. Will we have one example created specifically for the migration though? Like we had when we've created mongodbatlas_api_key_assignment and had to provide a migration path for mongodbatlas_project_api_key (https://github.com/mongodb/terraform-provider-mongodbatlas/tree/master/examples/mongodbatlas_api_key_assignment/module/old_module)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what you are suggesting will be done in the following tickets, that are specifically for designing the migration guides.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect!


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.

## Usage

```hcl
provider "mongodbatlas" {
public_key = var.public_key
private_key = var.private_key
}

resource "mongodbatlas_cloud_user_team_assignment" "example" {
org_id = var.org_id
team_id = var.team_id
user_id = var.user_id
}
```

You must set the following variables:
- `public_key`: Your MongoDB Atlas API public key.
- `private_key`: Your MongoDB Atlas API private key.
- `org_id`: The ID of the MongoDB Atlas organization.
- `team_id`: The ID of the team to assign the user to.
- `user_id`: The ID of the user to assign to the team.


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.
17 changes: 17 additions & 0 deletions examples/mongodbatlas_cloud_user_team_assignment/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "mongodbatlas_cloud_user_team_assignment" "example" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the data sources depend on the resource?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same question earlier but couldn’t find an example where depends_on is used, only data sources using it when a different resource is needed.
Also, we didn’t include this in cloud_user_org_assignment docs #3493, so I did not included it here for consistency.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you run the example? I suspect it will fail, since the data source will get NOT FOUND until the resource is created. But maybe we are handling that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it fails. The cloud_user_org_assignment example fails for the same reason. Agustin pointed out that the other examples I reviewed without depends_on implicitly depend on the resource because they reference its attributes, so it’s a different situation.
I’ll update both examples to include a depends_on

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually after reading this comment now, I think it would be more straightforward to not use the depends_on & instead reference the resource attribute, WDYT @csanx ?

org_id = var.org_id
team_id = var.team_id
user_id = var.user_id
}

data "mongodbatlas_cloud_user_team_assignment" "example_user_id" {
org_id = var.org_id
team_id = var.team_id
user_id = var.user_id
}

data "mongodbatlas_cloud_user_team_assignment" "example_username" {
org_id = var.org_id
team_id = var.team_id
username = var.user_email
}
14 changes: 14 additions & 0 deletions examples/mongodbatlas_cloud_user_team_assignment/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
output "user_from_username" {
description = "User details retrieved by username"
value = data.mongodbatlas_cloud_user_team_assignment.example_username
}

output "user_from_user_id" {
description = "User details retrieved by user_id"
value = data.mongodbatlas_cloud_user_team_assignment.example_user_id
}

output "assigned_user" {
description = "Details of the user assigned to the team"
value = mongodbatlas_cloud_user_team_assignment.example
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "mongodbatlas" {
public_key = var.public_key
private_key = var.private_key
}
29 changes: 29 additions & 0 deletions examples/mongodbatlas_cloud_user_team_assignment/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
variable "org_id" {
description = "The MongoDB Atlas organization ID"
type = string
}

variable "team_id" {
description = "The team ID"
type = string
}

variable "user_id" {
description = "The user ID"
type = string
}

variable "user_email" {
description = "The email address of the user"
type = string
}

variable "public_key" {
description = "Atlas API public key"
type = string
}

variable "private_key" {
description = "Atlas API private key"
type = string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "~> 1.38"
}
}
required_version = ">= 1.0"
}
15 changes: 15 additions & 0 deletions templates/data-sources/cloud_user_team_assignment.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# {{.Type}}: {{.Name}}

`{{.Name}}` provides a Cloud User Team Assignment data source. The data source lets you retrieve a user assigned to a team.

-> **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)
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.
To manage such users with this resource, refer to our [migration guide]<link-to-migration-guide>.

## Example Usages

{{ tffile (printf "examples/%s/main.tf" .Name )}}

{{ .SchemaMarkdown | trimspace }}

For more information see: [MongoDB Atlas API - Cloud Users](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-listteamusers) Documentation.
25 changes: 25 additions & 0 deletions templates/resources/cloud_user_team_assignment.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# {{.Type}}: {{.Name}}

`{{.Name}}` provides a Cloud User Team Assignment resource. The resource lets you import, assign, remove, or update a user to a team.

-> **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)
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.
To manage such users with this resource, refer to our [migration guide]<link-to-migration-guide>.
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The migration guide link is incomplete with placeholder text '' instead of an actual URL.

Suggested change
To manage such users with this resource, refer to our [migration guide]<link-to-migration-guide>.
To manage such users with this resource, refer to our [migration guide](https://www.mongodb.com/docs/atlas/migrate-cloud-user-team-assignment).

Copilot uses AI. Check for mistakes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All placeholders will be addressed as part of this ticket CLOUDP-329711


## Example Usages

{{ tffile (printf "examples/%s/main.tf" .Name )}}

{{ .SchemaMarkdown | trimspace }}

## Import

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`.

```
$ terraform import mongodbatlas_cloud_user_team_assignment.test 63cfbf302333a3011d98592e/9f3c1e7a4d8b2f6051acde47/5f18367ccb7a503a2b481b7a
OR
$ terraform import mongodbatlas_cloud_user_team_assignment.test 63cfbf302333a3011d98592e/9f3c1e7a4d8b2f6051acde47/[email protected]
```

For more information see: [MongoDB Atlas API - Cloud Users](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-addusertoteam) Documentation.