Review the Auto Scaling group load-balancer association

Associate a load balancer with an Auto Scaling group when its workload needs traffic distribution.

Description

An Auto Scaling group serving requests through a load balancer needs an association with that load balancer or its target group. Workloads such as queue workers may not need a load balancer; choose according to the service design.

Potential impact

If an association required by the service is missing, newly launched instances may not receive requests.

Remediation

Use load_balancers for a Classic ELB or target_group_arns for an ALB/NLB. To replace instances based on load-balancer health checks, also enable ELB health checks in Auto Scaling.

Examples

The revised example associates the group with an existing Classic ELB named elb-1. The launch template and load balancer are defined separately.

Before

hcl
resource "aws_autoscaling_group" "example" {
  availability_zones = ["us-east-1a"]
  desired_capacity   = 1
  max_size           = 1
  min_size           = 1

  launch_template {
    id      = aws_launch_template.foobar.id
    version = "$Latest"
  }
}

After

hcl
resource "aws_autoscaling_group" "example" {
  availability_zones = ["us-east-1a"]
  desired_capacity   = 1
  max_size           = 1
  min_size           = 1

  launch_template {
    id      = aws_launch_template.foobar.id
    version = "$Latest"
  }

  load_balancers = ["elb-1"]
}

References