I want to create a module that can accept inputs for environments(dev,test,prod) and create the number of subnets ("app" and "db" subnet for each environment) with proper tags. e.g Name=dev-app The module should be flexible to add/delete subnets as input variables are updated. My template looks like below
variable "environments" {
type = map(object({
app_subnet_cidr = string
db_subnet_cidr = string
}))
default = {
dev = {
app_subnet_cidr = "192.168.219.0/24"
db_subnet_cidr = "192.168.218.0/24"
}
test = {
app_subnet_cidr = "192.168.118.0/24"
db_subnet_cidr = "192.168.119.0/24"
}
}
}
resource "aws_subnet" "this" {
for_each = var.environments
vpc_id = var.vpc_id
cidr_block = {Don't know what to use here}
tags {
Name = {Don't know what to use here}
}
}
I was referring to the below articles. https://www.hashicorp.com/blog/terraform-0-12-rich-value-types/ Question-2: How "networks" variable could be defined for below module
module "subnets" {
source = "./subnets"
parent_vpc_id = "vpc-abcd1234"
networks = {
production_a = {
network_number = 1
availability_zone = "us-east-1a"
}
production_b = {
network_number = 2
availability_zone = "us-east-1b"
}
staging_a = {
network_number = 1
availability_zone = "us-east-1a"
}
}
}
https://www.hashicorp.com/blog/hashicorp-terraform-0-12-preview-for-and-for-each/