terraform-provider-grafana icon indicating copy to clipboard operation
terraform-provider-grafana copied to clipboard

removing users from teams fails when user was removed

Open hargut opened this issue 3 years ago • 0 comments

Terraform Version

  • Terraform: 1.1.9
  • Terraform Grafana Provider: 1.22.0
  • Grafana: 8.3.4

Affected Resource(s)

Please list the resources as a list, for example:

  • grafana_team

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

resource "random_password" "password" {
  for_each         = local.users
  length           = 32
  special          = true
  override_special = "_%@"
  min_lower        = 1
  min_numeric      = 1
  min_special      = 1
  min_upper        = 1
}

resource "grafana_user" "common-user" {
  for_each = local.users
  login    = lower(each.value["email"])
  email    = lower(each.value["email"])
  name     = each.value["name"]
  password = random_password.password[each.key].result
  is_admin = false
}

resource "grafana_team" "common-groups" {
  for_each = local.groups
  name  = each.value["display-name"]
  members = each.value["members"]

  depends_on = [grafana_user.common-user]
}

Expected Behavior

User should be removed from team without terraform failing.

Actual Behavior

Provider fails with an error, even with correct plan.

Terraform will perform the following actions:

  # grafana_team.common-groups["some-team"] will be updated in-place
  ~ resource "grafana_team" "common-groups" {
        id      = "15"
      ~ members = [
          - "[email protected]",
        ]
        name    = "Some Name"
        # (1 unchanged attribute hidden)
    }

  # grafana_user.common-user["random-user-id"] will be destroyed
  - resource "grafana_user" "common-user" {
      - email    = "[email protected]" -> null
      - id       = "56" -> null
      - is_admin = false -> null
      - login    = "[email protected]" -> null
      - name     = "Maximilian Mustermann" -> null
      - password = (sensitive value)
      - user_id  = 56 -> null
    }

  # random_password.password["random-user-id"] will be destroyed
  - resource "random_password" "password" {
      - id               = "none" -> null
      - length           = 32 -> null
      - lower            = true -> null
      - min_lower        = 1 -> null
      - min_numeric      = 1 -> null
      - min_special      = 1 -> null
      - min_upper        = 1 -> null
      - number           = true -> null
      - override_special = "_%@" -> null
      - result           = (sensitive value)
      - special          = true -> null
      - upper            = true -> null
    }

Plan: 0 to add, 1 to change, 2 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

grafana_user.common-user["random-user-id"]: Destroying... [id=56]
grafana_user.common-user["random-user-id"]: Destruction complete after 0s
random_password.password["random-user-id"]: Destroying... [id=none]
random_password.password["random-user-id"]: Destruction complete after 0s
grafana_team.common-groups["some-team"]: Modifying... [id=15]
╷
│ Error: error adding user [email protected]. User does not exist in Grafana
│ 
│   with grafana_team.common-groups["some-team"],
│   on teams.tf line 1, in resource "grafana_team" "common-groups":
│    1: resource "grafana_team" "common-groups" {
│ 
╵
ERRO[0013] 1 error occurred:
        * exit status 1

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. The depends_on is required as otherwise the team might be created too early resulting in a similar error.
  2. terraform apply after removing a user which also belongs to a team
  3. The same issue appears when the team contains multiple members and a single user should be removed from the system.

hargut avatar May 05 '22 16:05 hargut