-
Notifications
You must be signed in to change notification settings - Fork 0
/
02-network.tf
192 lines (172 loc) · 5.18 KB
/
02-network.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
resource "aws_vpc" "vpn-vpc" {
cidr_block = var.vpc_cidr
enable_dns_support = true
enable_dns_hostnames = true
tags = merge(
{ Name = "vpn-vpc" },
local.common_tags
)
}
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.vpn-vpc.id
tags = merge({ Name = "vpn-igw" }, local.common_tags)
}
resource "aws_subnet" "vpn-subnets" {
count = length(data.aws_availability_zones.available.names)
cidr_block = element(var.aws_subnets, count.index)
availability_zone = data.aws_availability_zones.available.names[count.index]
vpc_id = aws_vpc.vpn-vpc.id
map_public_ip_on_launch = true
tags = merge({ Name = "vpn-subnet-${count.index}" }, local.common_tags)
}
resource "aws_route_table" "vpn-rt" {
vpc_id = aws_vpc.vpn-vpc.id
tags = merge({ Name = "vpn-route-table" }, local.common_tags)
}
resource "aws_route_table_association" "vpn-rt-assoc" {
count = length(aws_subnet.vpn-subnets)
route_table_id = aws_route_table.vpn-rt.id
subnet_id = element(aws_subnet.vpn-subnets.*.id, count.index)
}
resource "aws_route" "vpn-rt" {
count = length(aws_subnet.vpn-subnets)
destination_cidr_block = "0.0.0.0/0"
route_table_id = aws_route_table.vpn-rt.id
gateway_id = aws_internet_gateway.igw.id
}
resource "aws_network_acl" "vpn-acl" {
vpc_id = aws_vpc.vpn-vpc.id
subnet_ids = aws_subnet.vpn-subnets.*.id
tags = merge({ Name = "vpn-acl" }, local.common_tags)
}
resource "aws_network_acl_rule" "ssh-ingress" {
network_acl_id = aws_network_acl.vpn-acl.id
protocol = "tcp"
rule_action = "allow"
rule_number = 1000
from_port = 22
to_port = 22
cidr_block = var.my_ip
}
resource "aws_network_acl_rule" "ssh-egress" {
network_acl_id = aws_network_acl.vpn-acl.id
protocol = "tcp"
egress = true
rule_action = "allow"
rule_number = 1000
from_port = 22
to_port = 22
cidr_block = var.my_ip
}
resource "aws_network_acl_rule" "ephemeral-ingress-tcp" {
network_acl_id = aws_network_acl.vpn-acl.id
egress = false
protocol = "tcp"
rule_action = "allow"
rule_number = 1001
cidr_block = "0.0.0.0/0"
from_port = 1024
to_port = 65535
}
resource "aws_network_acl_rule" "ephemeral-ingress-udp" {
network_acl_id = aws_network_acl.vpn-acl.id
protocol = "udp"
egress = false
rule_action = "allow"
rule_number = 1002
cidr_block = "0.0.0.0/0"
from_port = 1024
to_port = 65535
}
resource "aws_network_acl_rule" "ephermal-outbound-tcp" {
network_acl_id = aws_network_acl.vpn-acl.id
protocol = "tcp"
egress = true
rule_action = "allow"
rule_number = 1001
cidr_block = "0.0.0.0/0"
from_port = 1024
to_port = 65535
}
resource "aws_network_acl_rule" "ephermal-outbound-udp" {
network_acl_id = aws_network_acl.vpn-acl.id
protocol = "udp"
rule_action = "allow"
egress = true
rule_number = 1002
cidr_block = "0.0.0.0/0"
from_port = 1024
to_port = 65535
}
resource "aws_network_acl_rule" "openvpn-admin-ingress" {
network_acl_id = aws_network_acl.vpn-acl.id
protocol = "tcp"
rule_action = "allow"
rule_number = 1003
from_port = 943
to_port = 943
cidr_block = var.my_ip
}
resource "aws_network_acl_rule" "openvpn-admin-egress" {
network_acl_id = aws_network_acl.vpn-acl.id
protocol = "tcp"
egress = true
rule_action = "allow"
rule_number = 1003
from_port = 943
to_port = 943
cidr_block = var.my_ip
}
resource "aws_network_acl_rule" "openvpn-https-ingress" {
network_acl_id = aws_network_acl.vpn-acl.id
protocol = "tcp"
rule_action = "allow"
rule_number = 1004
from_port = 443
to_port = 443
cidr_block = var.my_ip
}
resource "aws_network_acl_rule" "openvpn-https-egress" {
network_acl_id = aws_network_acl.vpn-acl.id
protocol = "tcp"
egress = true
rule_action = "allow"
rule_number = 1004
from_port = 443
to_port = 443
cidr_block = var.my_ip
}
resource "aws_network_acl_rule" "vpn-outbound-udp" {
network_acl_id = aws_network_acl.vpn-acl.id
protocol = "udp"
rule_action = "allow"
egress = true
rule_number = 1005
cidr_block = "0.0.0.0/0"
from_port = 1194
to_port = 1194
}
resource "aws_network_acl_rule" "vpn-inbound-udp" {
network_acl_id = aws_network_acl.vpn-acl.id
protocol = "udp"
rule_action = "allow"
egress = false
rule_number = 1005
cidr_block = "0.0.0.0/0"
from_port = 1194
to_port = 1194
}
resource "aws_network_acl_rule" "vpn-outbound-all" {
network_acl_id = aws_network_acl.vpn-acl.id
protocol = "-1"
rule_action = "allow"
egress = true
rule_number = 1006
cidr_block = "0.0.0.0/0"
}
resource "aws_eip" "vpn-instance-eip" {
vpc = true
depends_on = [aws_internet_gateway.igw]
instance = aws_instance.vpn-instance.id
tags = merge({ Name = "vpn-eip" }, local.common_tags)
}