-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc.tf
145 lines (118 loc) · 2.83 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
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
data "aws_availability_zones" "azs" {
state = "available"
}
locals {
az_names = data.aws_availability_zones.azs.names
public_sub_ids = aws_subnet.subnet_public.id
}
resource "aws_vpc" "vpc" {
cidr_block = var.vpc_cidr_block
tags = {
Name = "${var.project}-vpc"
}
}
resource "aws_subnet" "subnet_public" {
vpc_id = aws_vpc.vpc.id
cidr_block = var.subnet_public_cidr_block
map_public_ip_on_launch = true
tags = {
Name = "${var.project}-public-subnet"
}
}
resource "aws_internet_gateway" internet_gateway {
vpc_id = aws_vpc.vpc.id
tags = {
Name = "${var.project}-internet-gateway"
}
}
resource "aws_route_table" "public_route_table" {
vpc_id = aws_vpc.vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.internet_gateway.id
}
tags = {
Name = "${var.project}-public-route-table"
}
}
resource "aws_route_table_association" "public_route_table_association" {
subnet_id = aws_subnet.subnet_public.id
route_table_id = aws_route_table.public_route_table.id
}
resource "aws_eip" "eip" {
vpc = true
depends_on = [aws_internet_gateway.internet_gateway]
tags = {
Name = "${var.project}-eip"
}
}
resource "aws_nat_gateway" "nat_gateway" {
allocation_id = aws_eip.eip.id
subnet_id = aws_subnet.subnet_public.id
tags = {
Name = "${var.project}-nat-gateway"
}
}
resource "aws_subnet" "subnet_private" {
vpc_id = aws_vpc.vpc.id
cidr_block = var.subnet_private_cidr_block
map_public_ip_on_launch = false
tags = {
Name = "${var.project}-private-subnet"
}
}
resource "aws_route_table" "private_route_table" {
vpc_id = aws_vpc.vpc.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat_gateway.id
}
tags = {
Name = "${var.project}-private-route-table"
}
}
resource "aws_route_table_association" "private_route_table_association" {
subnet_id = aws_subnet.subnet_private.id
route_table_id = aws_route_table.private_route_table.id
}
resource "aws_default_network_acl" "default_network_acl" {
default_network_acl_id = aws_vpc.vpc.default_network_acl_id
subnet_ids = [aws_subnet.subnet_private.id, aws_subnet.subnet_public.id]
ingress {
from_port = 0
to_port = 0
protocol = -1
rule_no = 100
action = "allow"
cidr_block = "0.0.0.0/0"
}
egress {
from_port = 0
to_port = 0
protocol = -1
rule_no = 100
action = "allow"
cidr_block = "0.0.0.0/0"
}
tags = {
Name = "${var.project}-default-default-network-acl"
}
}
resource "aws_default_security_group" "default_security_group" {
vpc_id = aws_vpc.vpc.id
ingress {
from_port = 0
to_port = 0
protocol = -1
self = true
}
egress {
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "${var.project}-default-security-group"
}
}