11locals {
22 # Th current region
33 region = data. aws_region . current . name
4+ # Indicates if the transit gateway is being proivisioned
5+ enable_transit_gateway = var. transit_gateway_id != null
46 # The id for the transit_gateway_id passed into the module
5- transit_gateway_id = var. enable_transit_gateway ? var. transit_gateway_id : null
6- # Is the routes to propagate down the transit gateway
7- transit_routes = var. enable_transit_gateway && length (var. transit_gateway_routes ) > 0 ? var. transit_gateway_routes : {}
7+ transit_gateway_id = local. enable_transit_gateway ? var. transit_gateway_id : null
8+ # Is the routes to propagate down the transit gateway
9+ transit_routes = local. enable_transit_gateway && length (var. transit_gateway_routes ) > 0 ? var. transit_gateway_routes : {}
10+ # NAT Configuration mode
11+ nat_gateway_mode = var. enable_nat_gateway ? var. nat_gateway_mode : " none"
812 # The configuration for the private subnets
913 private_subnet = var. private_subnet_netmask > 0 ? {
1014 private = {
11- connect_to_public_natgw = var.enable_nat_gateway ? true : false
15+ connect_to_public_natgw = var.enable_nat_gateway
1216 netmask = var.private_subnet_netmask
1317 tags = merge (var. tags , var. private_subnet_tags )
1418 }
1519 } : null
1620 # Public subnets are optional
1721 public_subnet = var. public_subnet_netmask > 0 ? {
1822 public = {
19- nat_gateway_configuration = var .nat_gateway_mode
23+ nat_gateway_configuration = local .nat_gateway_mode
2024 netmask = var.public_subnet_netmask
2125 tags = merge (var. tags , var. public_subnet_tags )
2226 }
2327 } : null
24- # Configuration for the transit subnets
25- transit_subnet = var . enable_transit_gateway ? {
28+ # Configuration for the transit subnets
29+ transit_subnet = local . enable_transit_gateway ? {
2630 transit_gateway = {
2731 connect_to_public_natgw = var.enable_transit_gateway_subnet_natgw
2832 netmask = 28
@@ -39,28 +43,28 @@ locals {
3943 private_subnet_cidrs = [for k , x in module . vpc . private_subnet_attributes_by_az : x . cidr_block if startswith (k, " private/" )]
4044 # A map of private subnet id to cidr block
4145 private_subnet_cidr_by_id = { for k , x in module . vpc . private_subnet_attributes_by_az : x . id => x . cidr_block if startswith (k, " private/" ) }
42- # A map of az to private subnet id
46+ # A map of az to private subnet id
4347 private_subnet_id_by_az = { for k , x in module . vpc . private_subnet_attributes_by_az : trimprefix (k, " private/" ) => x . id if startswith (k, " private/" ) }
44- # A map of az to public subnet id
48+ # A map of az to public subnet id
4549 public_subnet_id_by_az = var. public_subnet_netmask > 0 ? { for k , x in module . vpc . public_subnet_attributes_by_az : k => x . id } : {}
46- # A map of public subnet id to cidr block
50+ # A map of public subnet id to cidr block
4751 public_subnet_cidr_by_id = var. public_subnet_netmask > 0 ? { for k , x in module . vpc . public_subnet_attributes_by_az : x . id => x . cidr_block } : {}
48- # public_subnet ranges
52+ # public_subnet ranges
4953 public_subnet_cidrs = var. public_subnet_netmask > 0 ? [for k , x in module . vpc . public_subnet_attributes_by_az : x . cidr_block ] : []
5054 # The subnet id for the private subnets
5155 private_subnet_ids = [for k , x in module . vpc . private_subnet_attributes_by_az : x . id if startswith (k, " private/" )]
5256 # The subnet id for the public subnets
5357 public_subnet_ids = var. public_subnet_netmask > 0 ? [for k , x in module . vpc . public_subnet_attributes_by_az : x . id ] : []
5458 # The subnet id for the transit subnets
55- transit_subnet_ids = var . enable_transit_gateway ? [for k , x in module . vpc . tgw_subnet_attributes_by_az : x . id ] : []
56- # A list of transit route table ids
57- transit_route_table_ids = var . enable_transit_gateway ? [for k , x in module . vpc . rt_attributes_by_type_by_az . transit_gateway : x . id ] : []
59+ transit_subnet_ids = local . enable_transit_gateway ? [for k , x in module . vpc . tgw_subnet_attributes_by_az : x . id ] : []
60+ # A list of transit route table ids
61+ transit_route_table_ids = local . enable_transit_gateway ? [for k , x in module . vpc . rt_attributes_by_type_by_az . transit_gateway : x . id ] : []
5862 # The routing tables for the private subnets
5963 private_route_table_ids = [for k , x in module . vpc . rt_attributes_by_type_by_az . private : x . id ]
60- # The transgit gateway route table ids
64+ # The transgit gateway route table ids
6165 public_route_table_ids = var. public_subnet_netmask > 0 ? [for k , x in module . vpc . rt_attributes_by_type_by_az . public : x . id ] : []
62- # A map of the route table ids for the transit gateway by az
63- transit_route_table_by_az = var . enable_transit_gateway ? { for k , v in module . vpc . rt_attributes_by_type_by_az . transit_gateway : k => v . id } : {}
66+ # A map of the route table ids for the transit gateway by az
67+ transit_route_table_by_az = local . enable_transit_gateway ? { for k , v in module . vpc . rt_attributes_by_type_by_az . transit_gateway : k => v . id } : {}
6468
6569 subnets = merge (
6670 local. private_subnet ,
@@ -71,8 +75,9 @@ locals {
7175
7276 # A list of the private endpoints to enable ssm
7377 ssm_endpoints = var. enable_ssm ? [" ssmmessages" , " ssm" , " ec2messages" ] : []
74- # enabled_endpotints is a list of all the private endpoints to enable
78+ # enabled_endpotints is a list of all the private endpoints to enable
7579 enabled_endpoints = concat (var. enable_private_endpoints , local. ssm_endpoints )
76- # # Build the list of resolver rules to associate with the vpc
80+ # # Build the list of resolver rules to associate with the vpc
7781 resolver_rules = var. enable_route53_resolver_rules ? [for id in data . aws_route53_resolver_rules . current . resolver_rule_ids : id if ! contains (var. exclude_route53_resolver_rules , id)] : []
78- }
82+ }
83+
0 commit comments