Error: creating application Load Balancer: At least two subnets in two different Availability Zones

Hi All,

I would like to ask if anyone encounter this error.

Error: creating application Load Balancer: ValidationError: At least two subnets in two different Availability Zones must be specified

My code is simple only:

resource "aws_lb" "dev-mobile-bff-alb-01" {
  name               = "dev-mobile-bff-alb-01"
  internal           = false
  load_balancer_type = "application"
  security_groups    = ["${aws_security_group.alb_sg.id}"]
  subnets            = ["${aws_subnet.public_subnetB.id}", "${aws_subnet.public_subnetB.id}"]

  enable_deletion_protection = false

  access_logs {
    bucket  = aws_s3_bucket.development-alblogs.bucket
    prefix  = "Development-alb"
    enabled = true
  }

  tags = {
    Environment = "Development"
  }
}

And I am getting this error.

ā”‚ Error: creating application Load Balancer: ValidationError: At least two subnets in two different Availability Zones must be specified
ā”‚       status code: 400, request id: 8a0d7b0e-2077-44f3-bfc8-2dc0f2200ec8
ā”‚
ā”‚   with aws_lb.dev-mobile-bff-alb-01,
ā”‚   on main.tf line 90, in resource "aws_lb" "dev-mobile-bff-alb-01":
ā”‚   90: resource "aws_lb" "dev-mobile-bff-alb-01" {

any advise will be appreciated.

Is this a typo or what you are doing? That is listing the same subnet twice.

Also, the syntax is using an older deprecated form, so Iā€™d recommend something like this instead:

subnets = [aws_subnet.public_subnetA.id, aws_subnet.public_subnetB.id]

1 Like

Thanks Stuart. It was a typo on my end.