-2

When I am trying to use multiple subnets it gives me the following error: enter image description here

And these are the tf related blocks: enter image description here

enter image description here

Please help

Shay Pinchasi
  • 131
  • 1
  • 1
  • 6

1 Answers1

1

I think you misunderstood the conceppt of element function. Here,

element(var.subnet_public1_cidr_block, 3)

selects cidr of index-3(fourth element) but there is just 0, 1 and 2 ... So, to choose first index of subnet_public1_cidr_block = ["10.0.128.0/20", "10.0.128.0/20", "10.0.128.0/20"] use this instead:

element(var.subnet_public1_cidr_block, 0)

This will use first cidr value. OR,

you can dynamically use count variable as:

resource "aws_subnet" "subnet_public1" {
    ...
    count = 3
    cidr_block = element(var.subnet_public1_cidr_block, count.index)
    map_public_ip_on_launch = "true"
    availability_zone = data.aws_availability_zones.available.names[count.index]
    ...
}