-
Notifications
You must be signed in to change notification settings - Fork 2
/
route.tf
51 lines (44 loc) · 1.9 KB
/
route.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# CREATE PRVIATE ROUTE
resource "aws_route" "private_route" {
count = "${length(var.private_subnets)}"
destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = "${element(aws_nat_gateway.nat_gateway.*.id, count.index)}"
route_table_id = "${element(aws_route_table.private_route_table.*.id, count.index)}"
}
# CREATE PRIVATE ROUTE TABLE
resource "aws_route_table" "private_route_table" {
vpc_id = "${aws_vpc.vpc.id}"
propagating_vgws = ["${var.public_propagating_vgws}"]
count = "${length(var.private_subnets)}"
tags {
Name = "${var.vpc_name}-private-rt-${element(var.availability_zones, count.index)}"
environment_name = "${var.environment_name}"
}
}
# ASSOCIATE PRIVATE SUBNET WITH PRIVATE ROUTE TABLE
resource "aws_route_table_association" "private_route_table_association" {
count = "${length(var.private_subnets)}"
subnet_id = "${element(aws_subnet.private_subnet.*.id, count.index)}"
route_table_id = "${element(aws_route_table.private_route_table.*.id, count.index)}"
}
# CREATE PUBLIC AWS ROUTE
resource "aws_route" "public_aws_route" {
route_table_id = "${aws_route_table.public_route_table.id}"
destination_cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.internet_gateway.id}"
}
# CREATE PUBLIC ROUTE TABLE
resource "aws_route_table" "public_route_table" {
vpc_id = "${aws_vpc.vpc.id}"
propagating_vgws = ["${var.public_propagating_vgws}"]
tags {
Name = "${var.vpc_name}-public-rt"
environment_name = "${var.environment_name}"
}
}
# ASSOCIATE PUBLIC SUBNET WITH PUBLIC ROUTE TABLE
resource "aws_route_table_association" "public_route_table_association" {
count = "${length(var.public_subnets)}"
subnet_id = "${element(aws_subnet.public_subnet.*.id, count.index)}"
route_table_id = "${element(aws_route_table.public_route_table.*.id, count.index)}"
}