Skip to content

Removing a team from terraform causes an error due to attachment to project #662

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

Closed
checkitsam opened this issue Jan 24, 2022 · 3 comments
Closed
Assignees
Labels

Comments

@checkitsam
Copy link

Unable to delete team and remove from project in single operation, perhaps a separate attachment resource would help rather than having to define within the project resource. e.g. mongodbatlas_teams_attachment to allow the team to be attached to a project.

Terraform CLI and Terraform MongoDB Atlas Provider Version

Terraform v1.1.4
on darwin_amd64
+ provider registry.terraform.io/mongodb/mongodbatlas v1.2.0

Terraform Configuration File

locals {
  org_id = "ORG_ID_HERE"
  teams = {
    "Team1" = {
      usernames = ["[email protected]"]
    }
    "Team2" = {
        usernames  = ["[email protected]"]
    }
  }
}

resource "mongodbatlas_teams" "team" {
  for_each  = local.teams
  org_id    = local.org_id
  name      = each.key
  usernames = each.value.usernames
}

resource "mongodbatlas_project" "project" {
  name   = "Test-Project"
  org_id = local.org_id

  dynamic "teams" {
    for_each = mongodbatlas_teams.team
    content {
      role_names = ["GROUP_OWNER"]
      team_id    = teams.value.team_id
    }
  }
}

Steps to Reproduce

  1. terraform init
  2. terraform apply
  3. Remove a team from local.teams
  4. terraform apply

Expected Behavior

Team should be removed from project and then deleted

Actual Behavior

Terraform attempts to delete the team first and errors due to its attachment to the project

Debug Output

Plan: 0 to add, 1 to change, 1 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

mongodbatlas_teams.team["Team1"]: Destroying... [id=]
╷
│ Error: error deleting Team (<team_id>): DELETE https://cloud.mongodb.com/api/atlas/v1.0/orgs/<org_id>/teams/<team_id>: 404 (request "CANNOT_DELETE_TEAM_ASSIGNED_TO_PROJECT") You cannot delete a team that has at least one project assigned to it. Make sure to remove the team from all project before deleting it.
@nikhil-mongo
Copy link
Collaborator

@checkitsam I could repro this and understand what is missing in terms of following the process. I will file the internal ticket to get this fixed.

@nikhil-mongo
Copy link
Collaborator

nikhil-mongo commented Jan 28, 2022

INTMDB-298 filed internally.

@themantissa
Copy link
Collaborator

The fix for this was just released in version 1.3.0. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants