Query on dynamic Reiteration cidr Subnets

I need to create dynamic subnet space and it was following an example, so in a give scenario creating 15 subnets across 3 az’s with a 27 suffix. I started here eg >> base_cidr_block = “10.178.0.0/16”
networks = [
{
name = “eu-west-2a”
new_bits = var.Subnet_Bits
},
{
name = “eu-west-2b”
new_bits = var.Subnet_Bits
},
{
name = “eu-west-2c”
new_bits = var.Subnet_Bits
},
{
]
}

resource “aws_vpc” “example” {
cidr_block = module.subnet_addrs.base_cidr_block
}

resource “aws_subnet” “example” {
for_each = module.subnet_addrs.network_cidr_blocks

vpc_id = aws_vpc.example.id
availability_zone = each.key
cidr_block = each.value

But this fails once I add the next in sequence as the key is repeated , is there a better way or am I doing something wrong . I was using the following source >>module “subnet_addrs” {
source = “hashicorp/subnets/cidr”

I tried this , and it seems to work , any feedback or advice would be greatesource “aws_subnet” “private_infrastructure” {
for_each = var.subnet_map
vpc_id = aws_vpc.main.id
cidr_block = cidrsubnet(var.vpc_cidr,11, each.key)
availability_zone = length(regexall("^[a-z]{2}-[a-z]±[0-9][a-z]", element(var.availability_zone_list, each.key))) > 0 ? element(var.availability_zone_list, each.key) : null
tags = merge(var.tags, map(“Name”, format("%s-subnet-private_infrastructure-%s", aws_vpc.main.id, element(var.availability_zone_list, each.key))))
}
Using this variable “subnet_map” {
description = “subnet”
type = map(list(string))
default = {
“0” = [“eu-west-2a”]
“1” = [“eu-west-2b”]