-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnat.tf
67 lines (58 loc) · 1.7 KB
/
nat.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
#---------------------------------------------------------------------------------------------------
# NAT Gateway
#---------------------------------------------------------------------------------------------------
resource "aws_subnet" "nat" {
count = length(var.availability_zones)
vpc_id = aws_vpc.this.id
cidr_block = var.nat_subnet_cidr_blocks[count.index]
availability_zone = var.availability_zones[count.index]
tags = var.tags
}
resource "aws_route_table_association" "dmz" {
count = length(var.availability_zones)
subnet_id = aws_subnet.nat[count.index].id
route_table_id = aws_route_table.public.id
}
resource "aws_network_acl" "nat" {
vpc_id = aws_vpc.this.id
subnet_ids = [aws_subnet.nat[0].id]
# allow all traffic from instances inside the VPC.
ingress {
protocol = "all"
rule_no = 100
action = "allow"
cidr_block = var.cidr_block
from_port = 0
to_port = 0
}
# allow all returning traffic from the internet.
ingress {
protocol = "tcp"
rule_no = 110
action = "allow"
cidr_block = "0.0.0.0/0"
from_port = 1024
to_port = 65535
}
# allow all traffic to the internet.
egress {
protocol = "all"
rule_no = 100
action = "allow"
cidr_block = "0.0.0.0/0"
from_port = 0
to_port = 0
}
tags = var.tags
}
resource "aws_eip" "nat" {
count = length(var.availability_zones)
vpc = true
tags = var.tags
}
resource "aws_nat_gateway" "gw" {
count = length(var.availability_zones)
allocation_id = aws_eip.nat[count.index].id
subnet_id = aws_subnet.nat[count.index].id
tags = var.tags
}