Skip to content

Commit

Permalink
docs(group): documentation of solution to handle race condition upon …
Browse files Browse the repository at this point in the history
…user group deletion (#2761)
  • Loading branch information
vinay-newrelic authored Oct 28, 2024
1 parent 33aa865 commit fe5b505
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions website/docs/r/group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ In addition to the attributes listed above, the following attribute is also expo

## Additional Examples

### Updating User Group Membership Management in Terraform

### Overview
There is a potential race condition within Terraform when managing user accounts and their respective group memberships. A user might be deleted before Terraform disassociates them from a user group. This can lead to an error during `terraform apply` because the user ID no longer exists when the group resource is being updated.

### Recommended Solution
To address this and ensure proper sequential execution of resource updates, it is recommended to utilize the `create_before_destroy` lifecycle directive within your user group resource definition.

### Implementing Lifecycle Changes
To implement the change, modify the user group resource in your Terraform configuration as follows:

```hcl
resource "newrelic_group" "viewer" {
# Existing configuration ...
lifecycle {
create_before_destroy = true
}
}
```
The `create_before_destroy = true` statement will ensure that Terraform updates the user group (e.g., removes the user) before attempting to destroy the user resource, thus preventing the error.

### Addition of New Users to a New Group

The following example illustrates the creation of a group using the `newrelic_group` resource, to which users created using the `newrelic_user` resource are added.
Expand Down

0 comments on commit fe5b505

Please sign in to comment.