I’m testing out TF 13, and am just getting my head around what is possible or not. The idea here is to create a subnet (in 3 AZ’s) PER module that is being created. Is that technically possible to do from just one subnet resource ? FYI the code I have the the aws_subnet resource is just pseudocode somewhat . If using for_each is easier to achieve that, then of course that’s possible as well.
locals {
vpc_cidrs = {
egress = cidrsubnet(local.root_cidr, 8, 0)
shared = cidrsubnet(local.root_cidr, 8, 1)
# starting from the last cidr to keep special cidrs and team account cidrs grouped
datascience = cidrsubnet(local.root_cidr, 8, 255)
}
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
for_each = local.vpc_cidrs
name = each.key
cidr = each.value
azs = local.azs
enable_flow_log = true
tags = {
Name = each.key
}
}
resource "aws_subnet" "private" {
count = length(module.vpc)
cidr_block = cidrsubnet(module.vpc.*.vpc_cidr_block[count.index) ,3 , count.index )
availability_zone = element(local.azs, count.index)
vpc_id = element(module.vpc.*.vpc_id[count.index], count.index)
tags = {
Name = "${module.vpc.*.name[count.index)}-private"
}
}