Review unused security groups

Check actual usage and remove groups that are no longer needed.

Description

Check which resources use the security group and which other rules reference it.

Potential impact

An unattached group can look like active protection even though its rules apply to no workload.

Remediation

Attach a required group to the intended resource. Remove an obsolete group after confirming that no attachments or rule references remain.

Examples

The example group has no traffic rules. Before attaching it to the Application Load Balancer with security_groups, allow inbound traffic on the listener port and outbound traffic to the targets on the service and health-check ports. Then verify client access and target health.

Before

hcl
resource "aws_security_group" "web" {
  name        = "web-sg"
  description = "Web server security group"
  vpc_id      = aws_vpc.main.id
}

resource "aws_lb" "app" {
  name               = "app-lb"
  load_balancer_type = "application"
  subnets            = [aws_subnet.a.id, aws_subnet.b.id]
}

After

hcl
resource "aws_security_group" "web" {
  name        = "web-sg"
  description = "Web server security group"
  vpc_id      = aws_vpc.main.id
}

resource "aws_lb" "app" {
  name               = "app-lb"
  load_balancer_type = "application"
  subnets            = [aws_subnet.a.id, aws_subnet.b.id]
  security_groups    = [aws_security_group.web.id]
}

References