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”