Skip to content

doc: Adds example & documentation for new mongodbatlas_team_project_assignment resource #3581

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 8 commits into
base: CLOUDP-320243-dev-2.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/data-sources/team_project_assignment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Data Source: mongodbatlas_team_project_assignment

`mongodbatlas_team_project_assignment` provides a Team Project Assignment data source. The data source lets you retrieve a team assigned to a project.

## Example Usages

```terraform
resource "mongodbatlas_team_project_assignment" "example" {
project_id = var.project_id
team_id = var.team_id
role_names = ["GROUP_OWNER", "GROUP_DATA_ACCESS_ADMIN"]
}

data "mongodbatlas_team_project_assignment" "example_username" {
project_id = mongodbatlas_team_project_assignment.example.project_id
team_id = mongodbatlas_team_project_assignment.example.team_id
}
```

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

### Required

- `project_id` (String) Unique 24-hexadecimal digit string that identifies your project. Use the [/groups](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-listprojects) endpoint to retrieve all projects to which the authenticated user has access.

**NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.
- `team_id` (String) Unique 24-hexadecimal character string that identifies the team.

### Read-Only

- `role_names` (Set of String) One or more project-level roles assigned to the team.

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

`mongodbatlas_team_project_assignment` provides a Team Project Assignment resource. It lets you manage the association between a team and a project, enabling you to import, assign, remove, or update the team's membership.
## Example Usages

```terraform
resource "mongodbatlas_team_project_assignment" "example" {
project_id = var.project_id
team_id = var.team_id
role_names = ["GROUP_OWNER", "GROUP_DATA_ACCESS_ADMIN"]
}

data "mongodbatlas_team_project_assignment" "example_username" {
project_id = mongodbatlas_team_project_assignment.example.project_id
team_id = mongodbatlas_team_project_assignment.example.team_id
}
```

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

### Required

- `project_id` (String) Unique 24-hexadecimal digit string that identifies your project. Use the [/groups](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-listprojects) endpoint to retrieve all projects to which the authenticated user has access.

**NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.
- `role_names` (Set of String) One or more project-level roles assigned to the team.
- `team_id` (String) Unique 24-hexadecimal character string that identifies the team.

## Import

Team Project Assignment resource can be imported using the Project ID & TeamID, in the format `PROJECT_ID/TEAM_ID`.

```
$ terraform import mongodbatlas_team_project_assignment.test 9f3a7c2e54b8d1a0e6f4b3c2/a4d9f7b18e52c0fa36b7e9cd
```

For more information see: [MongoDB Atlas API - Teams](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-addallteamstoproject) Documentation.
33 changes: 33 additions & 0 deletions examples/mongodbatlas_team_project_assignment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Example: mongodbatlas_team_project_assignment

This example demonstrates how to use the `mongodbatlas_team_project_assignment` resource to assign a team to an existing project with specified roles in MongoDB Atlas.

## Usage

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

resource "mongodbatlas_team_project_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.

[nit] Consider using this instead of example (Applies to all files) https://www.terraform-best-practices.com/naming

project_id = var.project_id
team_id = var.team_id
role_names = ["GROUP_OWNER", "GROUP_DATA_ACCESS_ADMIN"]
}

data "mongodbatlas_team_project_assignment" "example_username" {
project_id = var.project_id
team_id = var.team_id
}
```

You must set the following variables:

- `public_key`: Your MongoDB Atlas API public key.
- `private_key`: Your MongoDB Atlas API private key.
- `project_id`: The ID of the project to assign the team to.
- `team_id`: The ID of the team to assign to the project.

To learn more, see the [MongoDB Atlas API - Cloud Users](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-addallteamstoproject) Documentation.

10 changes: 10 additions & 0 deletions examples/mongodbatlas_team_project_assignment/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "mongodbatlas_team_project_assignment" "example" {
project_id = var.project_id
team_id = var.team_id
role_names = ["GROUP_OWNER", "GROUP_DATA_ACCESS_ADMIN"]
}

data "mongodbatlas_team_project_assignment" "example_username" {
project_id = mongodbatlas_team_project_assignment.example.project_id
team_id = mongodbatlas_team_project_assignment.example.team_id
}
8 changes: 8 additions & 0 deletions examples/mongodbatlas_team_project_assignment/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
output "assigned_team" {
description = "Details of the assigned team"
value = mongodbatlas_team_project_assignment.example
}
output "team_from_team_id" {
description = "Project assignment details for the team retrieved by team_id"
value = data.mongodbatlas_team_project_assignment.example_username
}
4 changes: 4 additions & 0 deletions examples/mongodbatlas_team_project_assignment/provider.tf
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
}
19 changes: 19 additions & 0 deletions examples/mongodbatlas_team_project_assignment/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "project_id" {
description = "The MongoDB Atlas project ID"
type = string
}

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

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

variable "private_key" {
description = "Atlas API private key"
type = string
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add default = "" so the example can be run with env-vars to authenticate

}
9 changes: 9 additions & 0 deletions examples/mongodbatlas_team_project_assignment/versions.tf
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"
}
2 changes: 1 addition & 1 deletion internal/service/teamprojectassignment/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func resourceSchema() schema.Schema {
Attributes: map[string]schema.Attribute{
"project_id": schema.StringAttribute{
Required: true,
MarkdownDescription: "Unique 24-hexadecimal digit string that identifies your project. Use the [/groups](#tag/Projects/operation/listProjects) endpoint to retrieve all projects to which the authenticated user has access.\n\n**NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.",
MarkdownDescription: "Unique 24-hexadecimal digit string that identifies your project. Use the [/groups](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-listprojects) endpoint to retrieve all projects to which the authenticated user has access.\n\n**NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.",
},
"role_names": schema.SetAttribute{
ElementType: types.StringType,
Expand Down
11 changes: 11 additions & 0 deletions templates/data-sources/team_project_assignment.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# {{.Type}}: {{.Name}}

`{{.Name}}` provides a Team Project Assignment data source. The data source lets you retrieve a team assigned to a project.

## Example Usages

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

{{ .SchemaMarkdown | trimspace }}

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

`{{.Name}}` provides a Team Project Assignment resource. It lets you manage the association between a team and a project, enabling you to import, assign, remove, or update the team's membership.
## Example Usages

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

{{ .SchemaMarkdown | trimspace }}

## Import

Team Project Assignment resource can be imported using the Project ID & TeamID, in the format `PROJECT_ID/TEAM_ID`.

```
$ terraform import mongodbatlas_team_project_assignment.test 9f3a7c2e54b8d1a0e6f4b3c2/a4d9f7b18e52c0fa36b7e9cd
```

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