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

Resource newrelic_group: Update is failing when removing a user when the user_id list is build by Terraform #2636

Open
Mallear opened this issue Apr 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Mallear
Copy link

Mallear commented Apr 19, 2024

Hi there,

Terraform Version

Terraform v1.5.0
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v5.39.1
+ provider registry.terraform.io/newrelic/newrelic v3.34.1

Affected Resource(s)

Please list the resources as a list, for example:

  • newrelic_group

Terraform Configuration

data "newrelic_authentication_domain" "this" {
  name = "MyDomain"
}

locals {
  user_name = [
    "John.Doe",
    "Jane.Doe",
    "John.Smith",
    "Jane.Smith"
  ]
}

resource "newrelic_user" "viewer" {
  for_each = toset(local.user_name)
  name                     = each.key
  email_id                 = "${each.key}@domain.com"
  authentication_domain_id = data.newrelic_authentication_domain.this.id
  user_type                = "FULL_USER_TIER"
}

resource "newrelic_group" "viewer" {
  name                     = "Viewer Group Test"
  authentication_domain_id = data.newrelic_authentication_domain.this.id
  user_ids                 = [for user in newrelic_user.viewer : user.id]
}

terraform {
  required_version = ">= 1.5.0"

  required_providers {
    newrelic = {
      source  = "newrelic/newrelic"
      version = ">= 3.14"
    }
  }
}

provider "newrelic" {
}

Actual Behavior

When removing a user from the list, the user is deleted but the group update fails with the following logs:

╷
│ Error: maximum retries reached: The following ids were not found: user_ids: 1005916831
│ 
│   with newrelic_group.viewer,
│   on newrelic_groups.tf line 22, in resource "newrelic_group" "viewer":
│   22: resource "newrelic_group" "viewer" {
│ 
| 

On New Relic, the user is removed from the group.

Expected Behavior

The group succesfully update.

Steps to Reproduce

  1. terraform apply
  2. Comment a user name in local.user_name
  3. terraform apply

Debug Output

╷
│ Error: maximum retries reached: The following ids were not found: user_ids: 1005916831
│ 
│   with newrelic_group.viewer,
│   on newrelic_groups.tf line 22, in resource "newrelic_group" "viewer":
│   22: resource "newrelic_group" "viewer" {
│ 
| 

References

N/A

@pranav-new-relic
Copy link
Member

pranav-new-relic commented Apr 22, 2024

@Mallear thank you for reporting this issue. We shall take a look soon and keep you posted.

My first thoughts suggest this could be happening because the user is first being destroyed/deleted, after which Terraform tries removing the user from the group; however, since the mutation on NerdGraph that removes users from a group validates if the ID of the user given in the input is still valid, the mutation throws an error, hence the issue. However, in the UI, the user is no longer part of the group as the user doesn't even exist anymore.

We might need to fix this by (possibly, if feasible) introducing a dependency that would ensure the user is not deleted until the user is removed from the group, or internally have the user removed from the group, if they have been deleted. The feasibility of the options above aren't clear at this point, so we'll take a look further and keep you posted.

@pranav-new-relic pranav-new-relic added the bug Something isn't working label Jun 3, 2024
@pranav-new-relic pranav-new-relic changed the title newrelic_group update is failing when removing a user when the user_id list is build by Terraform Resource newrelic_group: Update is failing when removing a user when the user_id list is build by Terraform Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants