Hello,
I’m trying to put the list of destination_cidr_block for transit gateway route in route table. But it only picks the first cidr_block from the list. And also if there are more than one route table in a vpc, the route is created in only one route table in first availability for eg. ap-south-1a.
here is my modules/main.tf for transit gateway route of module
resource "aws_route" "transit_gateway" {
count = var.create_vpc && var.create_tgw && length(var.private_subnets) > 0 ? 1 : 0
route_table_id = element(aws_route_table.private.*.id, count.index)
destination_cidr_block = var.tgw_cidr[count.index]
transit_gateway_id = var.transit_gateway_id
provider = aws.dst
timeouts {
create = "5m"
}
}
Here is modules/variable.tf for transit gateway route
variable "create_vpc" {
description = "Controls if VPC should be created (it affects almost all resources)"
type = bool
default = true
}
variable "create_tgw" {
description = "Controls if an Transit Gateway is created for public subnets and the related routes that connect them."
type = bool
default = true
}
variable "private_subnets" {
description = "A list of private subnets inside the VPC"
type = list(string)
default = []
}
variable "tgw_cidr" {
type = list(string)
default = []
}
variable "transit_gateway_id" {}
VPC module in main.tf
module "vpc3" {
source = "./modules"
name = "vpc3"
cidr = "10.2.0.0/16"
azs = ["ap-south-1a", "ap-south-1b", "ap-south-1c"]
private_subnets = ["10.2.1.0/24", "10.2.2.0/24", "10.2.3.0/24"]
enable_ipv6 = true
private_subnet_assign_ipv6_address_on_creation = true
private_subnet_ipv6_prefixes = [0, 1, 2]
tgw_cidr = ["10.1.0.0/16", "10.10.0.0/16"]
transit_gateway_id = module.tgw.ec2_transit_gateway_id
providers = {
aws.dst = aws.chris
}
}