|
| 1 | +--- |
| 2 | +page_title: "Migration Guide: Project Teams Attribute to Team Project Assignment Resource" |
| 3 | +--- |
| 4 | + |
| 5 | +# Migration Guide: Project Teams Attribute to Team Project Assignment Resource |
| 6 | + |
| 7 | +**Objective:** Migrate from the deprecated `teams` attribute on the `mongodbatlas_project` resource to the new `mongodbatlas_team_project_assignment` resource. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Before you begin |
| 12 | + |
| 13 | +- **Backup** your [Terraform state file](https://developer.hashicorp.com/terraform/cli/commands/state). |
| 14 | +- Ensure you are using the MongoDB Atlas Terraform Provider `2.0.0` or later (version that includes `mongodbatlas_team_project_assignment` resource). |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## Why should I migrate? |
| 19 | + |
| 20 | +- **Future compatibility:** The `teams` attribute inside `mongodbatlas_project` is deprecated and will be removed in a future provider release. |
| 21 | +- **Separation of concerns:** Manage projects and team-to-project role assignments independently. |
| 22 | +- **Clearer diffs:** Role or team modifications won't require re‑applying the entire project resource. |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## What's changing? |
| 27 | + |
| 28 | +- Historically, `mongodbatlas_project` accepted an inline `teams` block to assign one or more teams to a project with specific roles. |
| 29 | +- Now, each project-team role mapping must be managed with `mongodbatlas_team_project_assignment`. |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +## From `mongodbatlas_project.teams` to `mongodbatlas_team_project_assignment` |
| 34 | + |
| 35 | +### Original configuration |
| 36 | + |
| 37 | +```hcl |
| 38 | +locals { |
| 39 | + project_id = <PROJECT_ID> |
| 40 | + team_map = { # team_id => set(role_names) |
| 41 | + <TEAM_ID_1> = ["GROUP_OWNER"] |
| 42 | + <TEAM_ID_2> = ["GROUP_READ_ONLY", "GROUP_DATA_ACCESS_READ_WRITE"] |
| 43 | + } |
| 44 | +} |
| 45 | +
|
| 46 | +resource "mongodbatlas_project" "this" { |
| 47 | + name = "<PROJECT_NAME>" |
| 48 | + org_id = "<ORG_ID>" |
| 49 | + project_owner_id = "<OWNER_ID>" |
| 50 | +
|
| 51 | + dynamic "teams" { |
| 52 | + for_each = local.team_map |
| 53 | + content { |
| 54 | + team_id = teams.key |
| 55 | + role_names = teams.value |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +### Step 1: Ignore `teams` and remove from configuration |
| 64 | + |
| 65 | +-> **Note:** The `teams` attribute is a `SetNestedBlock` and cannot be marked `Optional`/`Computed` for a smooth migration. For now, `ignore_changes` is required during Step 1. Support for removing `teams` entirely will come in a future Atlas Provider release. |
| 66 | + |
| 67 | +Replace the `mongodbatlas_project.teams` block with: |
| 68 | + |
| 69 | +```hcl |
| 70 | +resource "mongodbatlas_project" "this" { |
| 71 | + name = "<PROJECT_NAME>" |
| 72 | + org_id = "<ORG_ID>" |
| 73 | + project_owner_id = "<OWNER_ID>" |
| 74 | + |
| 75 | + lifecycle { |
| 76 | + ignore_changes = ["teams"] |
| 77 | + } |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +Then run: |
| 82 | + |
| 83 | +```shell |
| 84 | +terraform plan |
| 85 | +terraform apply |
| 86 | +``` |
| 87 | + |
| 88 | +This removes the `teams` block from the config but keeps the assignments in Atlas unchanged until we explicitly manage them in new resources. |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +### Step 2: Add the new `mongodbatlas_team_project_assignment` resources |
| 93 | + |
| 94 | +```hcl |
| 95 | +resource "mongodbatlas_project" "this" { |
| 96 | + name = "<PROJECT_NAME>" |
| 97 | + org_id = "<ORG_ID>" |
| 98 | + project_owner_id = "<OWNER_ID>" |
| 99 | + |
| 100 | + lifecycle { |
| 101 | + ignore_changes = ["teams"] |
| 102 | + } |
| 103 | +} |
| 104 | +
|
| 105 | +resource "mongodbatlas_team_project_assignment" "this" { |
| 106 | + for_each = local.team_map |
| 107 | + |
| 108 | + project_id = mongodbatlas_project.this.id |
| 109 | + team_id = each.key |
| 110 | + role_names = each.value |
| 111 | +} |
| 112 | + |
| 113 | +import { |
| 114 | + for_each = local.team_map |
| 115 | +
|
| 116 | + to = mongodbatlas_team_project_assignment.this[each.key] |
| 117 | + id = "${mongodbatlas_project.this.id}/${each.key}" |
| 118 | +} |
| 119 | +``` |
| 120 | + |
| 121 | +Run `terraform plan` (you should see **import** operations), then `terraform apply`. |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +### Step 4: Verify and clean up |
| 126 | + |
| 127 | +- After successful import and apply, `terraform plan` should show **no changes**. |
| 128 | +- Keep the `ignore_changes = ["teams"]` lifecycle rule until the provider releases a version without the `teams` argument in `mongodbatlas_project`. |
| 129 | + |
| 130 | +--- |
| 131 | + |
| 132 | +## Examples |
| 133 | + |
| 134 | +For complete, working configurations that demonstrate the migration process, see the examples in the provider repository: [migrate_team_project_assignment](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v2.0.0/examples/migrate_team_project_assignment). |
| 135 | + |
| 136 | +The examples include: |
| 137 | +- **v1**: Original configuration using deprecated `teams` attribute in `mongodbatlas_project` resource. |
| 138 | +- **v2**: Final configuration using `mongodbatlas_team_project_assignment` resource for team-to-project assignments. |
| 139 | + |
| 140 | +## Notes and tips |
| 141 | + |
| 142 | +- **Import format** for `mongodbatlas_team_project_assignment`: |
| 143 | +``` |
| 144 | +PROJECT_ID/TEAM_ID |
| 145 | +``` |
| 146 | +- **Modules:** Terraform import blocks cannot live inside modules ([Terraform issue](https://github.com/hashicorp/terraform/issues/33474)). |
| 147 | +- If you manage team assignments in modules, import each at the root level using the correct resource address (e.g. `module.<name>.mongodbatlas_team_project_assignment.<name>`). |
| 148 | +- You can use `terraform plan` to confirm imports before applying. |
| 149 | + |
| 150 | +--- |
| 151 | + |
| 152 | +## FAQ |
| 153 | + |
| 154 | +**Q: Do I need to delete the old `teams` from state?** |
| 155 | +A: No — using `ignore_changes` ensures they remain in Atlas until the provider removes the field. Then you can drop the lifecycle rule. |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +## Further resources |
| 160 | +- [`mongodbatlas_team_project_assignment` docs](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/team_project_assignment) |
0 commit comments