Skip to content
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

grafana_team members ordering causes terraform changes #384

Closed
andyli opened this issue Feb 9, 2022 · 0 comments · Fixed by #385
Closed

grafana_team members ordering causes terraform changes #384

andyli opened this issue Feb 9, 2022 · 0 comments · Fixed by #385
Labels

Comments

@andyli
Copy link

andyli commented Feb 9, 2022

Terraform Version

  • Terraform: 1.1.5
  • Terraform Grafana Provider: 1.19.0
  • Grafana: v8.3.3 (30bb7a93ca)

Affected Resource(s)

  • grafana_team

Terraform Configuration Files

locals {
  testers = {
    "A"  = "a@example.com"
    "B" = "b@example.com"
    "C"  = "c@example.com"
  }
}

resource "grafana_user" "testers" {
  for_each = local.testers

  name     = each.key
  email    = each.value
  login    = each.value
  password = "PASSWORD"
  is_admin = false
}

resource "grafana_team" "testers" {
  name = "Testing team"

  # Re-ordering the members here would cause a terraform change that is not persisted.
  # i.e. The initial order will be kept even if we `terraform apply` a different order.
  members = [
    local.testers["A"],
    local.testers["B"],
    local.testers["C"],
  ]

  depends_on = [grafana_user.testers]
}

Expected Behavior

If we reorder members, e.g.

  members = [
    local.testers["C"],
    local.testers["A"],
    local.testers["B"],
  ]

terraform apply should apply and save the new ordering. Subsequent terraform apply should show no changes.

Actual Behavior

There is always a change as follows,

  # grafana_team.testers will be updated in-place
  ~ resource "grafana_team" "testers" {
        id      = "3"
      ~ members = [
          + "c@example.com",
            "a@example.com",
            "b@example.com",
          - "c@example.com",
        ]
        name    = "Testing team"
        # (1 unchanged attribute hidden)
    }
@andyli andyli added the bug label Feb 9, 2022
julienduchesne added a commit that referenced this issue Feb 10, 2022
It's managed as a set by the Grafana API (and client) but we have it as a list in the resource
This means that whenever the ordering change, it's not being pushed to the API and we have a drift (see issue for more info)

This makes the members attribute a set. Migration is not an issue since both lists and sets are represented as JSON lists in the state (I tested it)

Closes #384
julienduchesne added a commit that referenced this issue Feb 10, 2022
* Fix `grafana_team` members reordering
It's managed as a set by the Grafana API (and client) but we have it as a list in the resource
This means that whenever the ordering change, it's not being pushed to the API and we have a drift (see issue for more info)

This makes the members attribute a set. Migration is not an issue since both lists and sets are represented as JSON lists in the state (I tested it)

Closes #384

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

Successfully merging a pull request may close this issue.

1 participant