Issues with creating AWS_LB

Hello guys,
I try to create a aws_lb and i get an error that i dont know how to fix it.
Error: creating ELBv2 application Load Balancer (test-lb-web-net-2024): ValidationError: You cannot provide subnets from multiple locales.
│ status code: 400, request id: bbd71767-bf15-4e21-9f1f-b71ab8dcb71a

My code:

resource "aws_lb" "nginx" {
  name               = "test-lb-web-net-2024"
  internal           = false
  load_balancer_type = "application"
  security_groups    = [aws_security_group.alb_sg.id]
  subnets            = [aws_subnet.public_subnet0.id, aws_subnet.public_subnet1.id]
  #subnets            = aws_subnet.public_subnet[*].id
  #depends_on                 = [aws_s3_bucket.public-access]
  enable_deletion_protection = false
  tags                       = local.common_tags
  /*  access_logs {
    bucket  = aws_s3_bucket.public-access.bucket
    prefix  = "alb-logs"
    enabled = true
  } */
}

resource "aws_subnet" "public_subnet0" {
  cidr_block              = var.vpc_public_subnets_cidr_block[0]
  vpc_id                  = aws_vpc.app.id
  map_public_ip_on_launch = var.map_public_ip_on_launch
  availability_zone       = data.aws_availability_zones.available.names[0]

  tags = {
    Name = "public_subnet0"
  }
}

resource "aws_subnet" "public_subnet1" {
  cidr_block              = var.vpc_public_subnets_cidr_block[1]
  vpc_id                  = aws_vpc.app.id
  map_public_ip_on_launch = var.map_public_ip_on_launch
  availability_zone       = data.aws_availability_zones.available.names[1]

  tags = {
    Name = "public_subnet1"
  }
}

my locals are not related subnets, so here it is what i have in my locals file:

locals {
  common_tags = {
    Name         = "${var.company} - ${var.project}"
    company      = var.company
    project      = "${var.company}-${var.project}"
    billing_code = var.billing_code
  }
  #s3_bucket_name = "web-net-app-andreiweb-${random_integer.s3.result}"
  s3_bucket_name = "web-net-app-andreiweb-asdasgjabslkjb123125jasasdjasb}"
}
resource "random_integer" "s3" {
  min = 10000000
  max = 99999999
}

ValidationError: You cannot provide subnets from multiple locales.

I think this implies subnets are being provided from multiple locales (AWS regions). Perhaps local zones are enabled in your region, and the aws_availability_zones data source is returning both local and availability zones in the output?

When Local Zones are enabled in a region, by default the API and this data source include both Local Zones and Availability Zones. To return only Availability Zones, see the example section below.

Ref: Terraform Registry

I haven’t personally encountered this error before so this suggestion is a best guess, but you could trying filtering the data source to only availability zones with the filter argument.

data "aws_availability_zones" "example" {
  filter {
    name   = "opt-in-status"
    values = ["opt-in-not-required"]
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.