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

docs(group): Documentation of solution to handle race condition in n… #2761

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading