Looping over a variable/data lookup


I am creating subnets using the AWS provider and am hoping to create 6 but I would like to assign a different availability zone to this. In my region there is only 3 AZs so I would like the list to be iterated over twice and therefor the second 3 subnets would then have AZ1, AZ2 and AZ3.

I apologise in advance if this is a simple issue but I have not found the solution so am coming to the community for help :smiley:

Our current is as below but if we want more than 3 subnets then this does not work as we would like

resource "aws_subnet" "subnet-tier-private" {
  count                   = 3
  vpc_id                  = aws_vpc.vpc.id
  cidr_block              = element(var.vpc-tier-private-cidr, count.index)
  availability_zone       = element(data.aws_availability_zones.available.names, count.index)