IAM group has no users

Review the purpose and need for an IAM group with no users.

Description

aws_iam_group_membership manages the full user list for a group. Check current members and the group’s purpose before applying an empty list.

Potential impact

An omitted member may lose access granted by the group. An unnecessary new member may gain its permissions.

Remediation

Review the owner and group policies, declare only the required members and check the plan for removals. Retire an unused group after checking dependencies.

Examples

The user list for test-group changes from empty to test-user and test-user-two. Neither excerpt defines a group policy.

Before

hcl
resource "aws_iam_group_membership" "example" {
  name = "tf-testing-group-membership"

  users = [
  ]

  group = aws_iam_group.example.name
}

resource "aws_iam_group" "example" {
  name = "test-group"
}

After

hcl
resource "aws_iam_group_membership" "example" {
  name = "tf-testing-group-membership"

  users = [
    aws_iam_user.user_one.name,
    aws_iam_user.user_two.name,
  ]

  group = aws_iam_group.example.name
}

resource "aws_iam_group" "example" {
  name = "test-group"
}

resource "aws_iam_user" "user_one" {
  name = "test-user"
}

resource "aws_iam_user" "user_two" {
  name = "test-user-two"
}

References