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

Inconsistent ordering of `member`s within `opsgenie_team`s

Open emmahsax opened this issue 3 years ago • 1 comments

Terraform Version

$ terraform -v
Terraform v1.2.7
on darwin_arm64
+ provider registry.terraform.io/opsgenie/opsgenie v0.6.10

Affected Resource(s)

Please list the resources as a list, for example:

  • opsgenie_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

# Teams variable
teams = {
  team_one = {
    account_one = {
      members = {
        person_one = {
          role = "admin"
        }
        person_two = {
          role = "admin"
        }
      }
    }
  }
}

# Users variable
users = {
  person_one = {
    full_name = "Person One"
    role      = "Owner"
    timezone  = "America/Chicago"
    username  = "[email protected]"
  }
  person_two = {
    full_name = "Person Two"
    role      = "Owner"
    timezone  = "America/Phoenix"
    username  = "[email protected]"
  }
}

resource "opsgenie_user" "users" {
  for_each = var.users

  full_name = each.value.full_name
  role      = each.value.role
  timezone  = each.value.timezone
  username  = each.value.username
}

resource "opsgenie_team" "team-one-account-one" {
  name = "Team_One_Account_One"

  dynamic "member" {
    for_each = var.teams.team_one.account_one.members

    content {
      id   = opsgenie_user.users[member.key].id
      role = member.value.role
    }
  }
}

Debug Output

N/A

Panic Output

N/A

Expected Behavior

Every time we run terraform plan, it should want to make no changes if there are no changes to be made.

Actual Behavior

When we run terraform plan, Terraform oftentimes (but not always) wants to make changes in place, like this:

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # opsgenie_team.team-one-account-one will be updated in-place
  ~ resource "opsgenie_team" "team-one-account-one" {
        id                       = "e917de49-a068-47ef-adaf-[...]"
        name                     = "Team_One_Account_One"
        # (1 unchanged attribute hidden)

      ~ member {
          ~ id   = "acbd3636-b10a-4771-b736-[...]" -> "7505f06c-8936-4e63-82b2-[...]"
            # (1 unchanged attribute hidden)
        }
      ~ member {
          ~ id   = "7505f06c-8936-4e63-82b2-[...]" -> "acbd3636-b10a-4771-b736-[...]"
            # (1 unchanged attribute hidden)
        }
    }

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

Please notice how the only changes it wants to make is rotating around the order in which the members are added to the team. This is basically just clutter, and will only increase in annoyance as we add more members to the teams.

But super importantly: it doesn't always want to make these changes... only sometimes... basically it's intermittent, and that makes it super hard to identify and reproduce

Steps to Reproduce

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

  1. Recreate the resources above as I've shown
  2. terraform apply
  3. Now continue to run terraform plan repeatedly and watch intermittently wanting to adjust things. You may need to take a break and come back to it in another few days. Again, since it's intermittent it's hard to debug and work with.

Important Factoids

N/A

References

There's a lot of other similar issues on this GitHub repository around strange and inconsistent sorting behavior. I think this may just be related to those. Perhaps the API from Opsgenie is returning inconsistent ordering, and the terraform provider just needs to do some ordering by ourselves.

emmahsax avatar Aug 23 '22 19:08 emmahsax

@emmahsax Can you try to upgrade your provider to 0.6.14 and check if you still encounter the issue?

This has been reported before in https://github.com/opsgenie/terraform-provider-opsgenie/issues/288 and should have been fixed (definitely) in 0.6.14 (0.6.11, 0.6.12 & 0.6.13 have other issues, so skip them)

multani avatar Aug 23 '22 20:08 multani

@multani I believe this did fix the issue! I wanted to give some adequate time to make sure, as the issue was intermittent the whole time. But I think it's fine now. I'll reopen if needed.

emmahsax avatar Sep 01 '22 16:09 emmahsax