@@ -3,102 +3,85 @@ resource "aws_route_table" "public" {
33
44 tags = merge (
55 {
6- Name = " PublicRouteTable" ,
7- Project = var.project,
8- Environment = var.environment
6+ Name = " ${ var . environment } -${ var . application } -public-route-table" ,
7+ Environment = var.environment,
8+ Owner = var.owner,
9+ CostCenter = var.cost_center,
10+ Application = var.application
911 },
1012 var. tags
1113 )
1214}
1315
1416resource "aws_route" "public" {
1517 route_table_id = aws_route_table. public . id
16- destination_cidr_block = " 0.0.0.0/0 "
18+ destination_cidr_block = var . destination_cidr_block
1719 gateway_id = aws_internet_gateway. main . id
1820}
1921
20-
21- resource "aws_route_table_association" "public" {
22- count = length (var. public_subnet_cidr_blocks )
23- subnet_id = aws_subnet. public [count . index ]. id
24- route_table_id = aws_route_table. public . id
25- }
26-
2722resource "aws_route_table" "app" {
2823 vpc_id = aws_vpc. main . id
2924
3025 tags = merge (
3126 {
32- Name = " AppRouteTable" ,
33- Project = var.project,
34- Environment = var.environment
27+ Name = " ${ var . environment } -${ var . application } -app-route-table" ,
28+ Environment = var.environment,
29+ Owner = var.owner,
30+ CostCenter = var.cost_center,
31+ Application = var.application
3532 },
3633 var. tags
3734 )
3835}
3936
4037resource "aws_route" "app" {
41- count = length (aws_nat_gateway . main )
42- route_table_id = aws_route_table. app . id
43- destination_cidr_block = " 0.0.0.0/0 "
44- gateway_id = aws_nat_gateway. main [count . index ]. id
38+ count = var . create_nat_gateway ? 1 : 0
39+ route_table_id = aws_route_table. app . id
40+ destination_cidr_block = var . destination_cidr_block
41+ nat_gateway_id = aws_nat_gateway. main [count . index ]. id
4542}
4643
47- resource "aws_route_table_association" "app" {
48- count = length (var. app_subnet_cidr_blocks )
49- subnet_id = aws_subnet. app [count . index ]. id
50- route_table_id = aws_route_table. app . id
51- }
5244
53- #
5445resource "aws_route_table" "db" {
5546 vpc_id = aws_vpc. main . id
5647
5748 tags = merge (
5849 {
59- Name = " DbRouteTable" ,
60- Project = var.project,
61- Environment = var.environment
50+ Name = " ${ var . environment } -${ var . application } -db-route-table" ,
51+ Environment = var.environment,
52+ Owner = var.owner,
53+ CostCenter = var.cost_center,
54+ Application = var.application
6255 },
6356 var. tags
6457 )
6558}
6659
6760resource "aws_route" "db" {
68- count = length (aws_nat_gateway. main )
69- route_table_id = aws_route_table. db . id
70- destination_cidr_block = " 0.0.0.0/0"
71- gateway_id = aws_nat_gateway. main [count . index ]. id
72- }
73-
74- resource "aws_route_table_association" "db" {
75- count = length (var. db_subnet_cidr_blocks )
76- subnet_id = aws_subnet. db [count . index ]. id
77- route_table_id = aws_route_table. db . id
61+ count = var. create_nat_gateway ? 1 : 0
62+ route_table_id = aws_route_table. db . id
63+ destination_cidr_block = var. destination_cidr_block
64+ nat_gateway_id = aws_nat_gateway. main [count . index ]. id
7865}
7966
8067resource "aws_route_table" "management" {
8168 vpc_id = aws_vpc. main . id
8269
8370 tags = merge (
8471 {
85- Name = " ManagementRouteTable" ,
86- Project = var.project,
87- Environment = var.environment
72+ Name = " ${ var . environment } -${ var . application } -management-route-table" ,
73+ Environment = var.environment,
74+ Owner = var.owner,
75+ CostCenter = var.cost_center,
76+ Application = var.application
8877 },
8978 var. tags
9079 )
9180}
9281
9382resource "aws_route" "management" {
94- count = length (aws_nat_gateway. main )
95- route_table_id = aws_route_table. management . id
96- destination_cidr_block = " 0.0.0.0/0"
97- gateway_id = aws_nat_gateway. main [count . index ]. id
98- }
99-
100- resource "aws_route_table_association" "management" {
101- count = length (var. management_subnet_cidr_blocks )
102- subnet_id = aws_subnet. management [count . index ]. id
103- route_table_id = aws_route_table. management . id
83+ count = var. create_nat_gateway ? 1 : 0
84+ route_table_id = aws_route_table. management . id
85+ destination_cidr_block = var. destination_cidr_block
86+ nat_gateway_id = aws_nat_gateway. main [count . index ]. id
10487}
0 commit comments