### Provider provider "aws" { region = "eu-north-1" version = "~>2.34" } ### Setup test resources locals { tags = {testing = "route tables"} num_of_subnets = 3 } # vpc with subnets resource "aws_vpc" "test_no_sub" { cidr_block = "10.9.0.0/16" tags = local.tags } # vpc without subnets resource "aws_vpc" "test" { cidr_block = "10.10.0.0/16" tags = local.tags } resource "aws_subnet" "test" { count = local.num_of_subnets vpc_id = aws_vpc.test.id cidr_block = "10.10.${count.index}.0/24" tags = local.tags } # Create one custom route table per subnet and associate them resource "aws_route_table" "test" { count = local.num_of_subnets vpc_id = aws_vpc.test.id tags = local.tags } resource "aws_route_table_association" "test" { count = local.num_of_subnets subnet_id = aws_subnet.test[count.index].id route_table_id = aws_route_table.test[count.index].id } module "rts-subnets" { source = "../" vpc_id = aws_vpc.test.id subnets_ids = aws_subnet.test[*].id } module "rts-vpc" { source = "../" vpc_id = aws_vpc.test_no_sub.id } output "subnet" { value = module.rts-subnets[*] } output "vpc" { value = module.rts-vpc[*] }