-
Notifications
You must be signed in to change notification settings - Fork 9
/
vpc.tf
111 lines (94 loc) · 2.64 KB
/
vpc.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
resource "aws_vpc" "vpc" {
cidr_block = "${lookup(var.vpc_cidr_block, var.tier)}"
instance_tenancy = "default"
enable_dns_hostnames = "true"
tags = {
Name = "${var.tier}-vpc"
}
}
resource "aws_subnet" "pub_subnet1" {
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "${lookup(var.pub_sub1, var.tier)}"
availability_zone = "${var.region}a"
map_public_ip_on_launch = "true"
tags = {
Name = "${var.tier}-pub-sub1"
}
}
resource "aws_subnet" "pub_subnet2" {
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "${lookup(var.pub_sub2, var.tier)}"
availability_zone = "${var.region}b"
map_public_ip_on_launch = "true"
tags = {
Name = "${var.tier}-pub-sub2"
}
}
resource "aws_subnet" "private_subnet1" {
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "${lookup(var.private_sub1, var.tier)}"
availability_zone = "${var.region}a"
tags = {
Name = "${var.tier}-private-sub1"
}
}
resource "aws_subnet" "private_subnet2" {
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "${lookup(var.private_sub2, var.tier)}"
availability_zone = "${var.region}b"
tags = {
Name = "${var.tier}-private-sub2"
}
}
resource "aws_internet_gateway" "gw" {
vpc_id = "${aws_vpc.vpc.id}"
tags = {
Name = "${var.tier}-ng"
}
}
resource "aws_eip" "nat" {
vpc = true
}
resource "aws_nat_gateway" "nat_gw" {
allocation_id = "${aws_eip.nat.id}"
subnet_id = "${aws_subnet.pub_subnet1.id}"
tags = {
Name = "${var.tier}-ng"
}
}
resource "aws_route_table" "pub_Subnet_rtb" {
vpc_id = "${aws_vpc.vpc.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.gw.id}"
}
tags = {
Name = "Public-route"
}
}
resource "aws_route_table" "private_Subnet_rtb" {
vpc_id = "${aws_vpc.vpc.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_nat_gateway.nat_gw.id}"
}
tags = {
Name = "Private-route"
}
}
resource "aws_route_table_association" "public-route" {
subnet_id = "${aws_subnet.pub_subnet1.id}"
route_table_id = "${aws_route_table.pub_Subnet_rtb.id}"
}
resource "aws_route_table_association" "public-route2" {
subnet_id = "${aws_subnet.pub_subnet2.id}"
route_table_id = "${aws_route_table.pub_Subnet_rtb.id}"
}
resource "aws_route_table_association" "private-route" {
subnet_id = "${aws_subnet.private_subnet1.id}"
route_table_id = "${aws_route_table.private_Subnet_rtb.id}"
}
resource "aws_route_table_association" "private-route2" {
subnet_id = "${aws_subnet.private_subnet2.id}"
route_table_id = "${aws_route_table.private_Subnet_rtb.id}"
}