-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpc.tf
97 lines (77 loc) · 1.86 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
# Create a VPC
resource "aws_vpc" "laboratorio_vpc" {
cidr_block = var.vpc_cidr
tags = {
Name = "laboratorio-vpc"
}
}
resource "aws_internet_gateway" "vpc_igw" {
vpc_id = aws_vpc.laboratorio_vpc.id
tags = {
Name = "vpc_igw"
}
}
resource "aws_subnet" "public_subnet_1" {
vpc_id = aws_vpc.laboratorio_vpc.id
cidr_block = var.public_subnet_1_cidr
map_public_ip_on_launch = true
availability_zone = "us-east-2a"
tags = {
Name = "public-subnet-1"
}
}
resource "aws_subnet" "public_subnet_2" {
vpc_id = aws_vpc.laboratorio_vpc.id
cidr_block = var.public_subnet_2_cidr
map_public_ip_on_launch = true
availability_zone = "us-east-2b"
tags = {
Name = "public-subnet-2"
}
}
resource "aws_subnet" "private_subnet" {
vpc_id = aws_vpc.laboratorio_vpc.id
cidr_block = var.private_subnet_cidr
availability_zone = "us-east-2a"
tags = {
Name = "private-subnet"
}
}
resource "aws_eip" "eip" {
vpc = true
}
resource "aws_nat_gateway" "nat_gateway" {
allocation_id = aws_eip.eip.id
subnet_id = aws_subnet.public_subnet_1.id
tags = {
"Name" = "nat_gateway"
}
}
resource "aws_route_table" "private" {
vpc_id = aws_vpc.laboratorio_vpc.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat_gateway.id
}
tags = {
Name = "private"
}
}
resource "aws_route_table" "public" {
vpc_id = aws_vpc.laboratorio_vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.vpc_igw.id
}
tags = {
Name = "public"
}
}
resource "aws_route_table_association" "public_rt_asso" {
subnet_id = aws_subnet.public_subnet_1.id
route_table_id = aws_route_table.public.id
}
resource "aws_route_table_association" "private" {
subnet_id = aws_subnet.private_subnet.id
route_table_id = aws_route_table.private.id
}