-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
155 lines (129 loc) · 3.26 KB
/
main.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
provider "aws" {
region = var.aws_region
}
terraform {
backend "s3" {
bucket = "aws-fastfood-fiap-terraform-tfstate"
key = "fast-food-net/terraform.tfstate"
region = "us-east-1"
}
}
# Criar a VPC
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr
tags = {
Name = "fastfood-vpc"
}
}
# Criar as Subnets
resource "aws_subnet" "subnet_1" {
vpc_id = aws_vpc.main.id
cidr_block = var.subnet_1_cidr
availability_zone = var.availability_zone_1
tags = {
Name = "subnet-1"
}
}
resource "aws_subnet" "subnet_2" {
vpc_id = aws_vpc.main.id
cidr_block = var.subnet_2_cidr
availability_zone = var.availability_zone_2
tags = {
Name = "subnet-2"
}
}
resource "aws_subnet" "subnet_3" {
vpc_id = aws_vpc.main.id
cidr_block = var.subnet_3_cidr
availability_zone = var.availability_zone_3
tags = {
Name = "subnet-3"
}
}
resource "aws_subnet" "subnet_4_public" {
vpc_id = aws_vpc.main.id
cidr_block = var.subnet_4_public_cidr
availability_zone = var.availability_zone_1
map_public_ip_on_launch = true
tags = {
Name = "subnet-4-public"
}
}
resource "aws_security_group" "cluster_security_group" {
name = "cluster-security-group"
description = "Security group for cluster"
vpc_id = aws_vpc.main.id
ingress {
description = "Allow HTTP traffic"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # allow all
}
ingress {
description = "Allow HTTPS traffic"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # allow all
}
egress {
description = "Allow all outbound traffic"
from_port = 0
to_port = 0
protocol = "-1" # all protocols
cidr_blocks = ["0.0.0.0/0"] # allow all
}
}
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.main.id
tags = {
Name = "internet-gateway"
}
}
resource "aws_route_table" "public_route_table" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw.id
}
tags = {
Name = "public-route-table"
}
}
resource "aws_route_table_association" "public_subnet_assoc" {
subnet_id = aws_subnet.subnet_4_public.id
route_table_id = aws_route_table.public_route_table.id
}
resource "aws_eip" "nat" {
vpc = true
}
resource "aws_nat_gateway" "nat" {
allocation_id = aws_eip.nat.id
subnet_id = aws_subnet.subnet_4_public.id
tags = {
Name = "nat-gateway"
}
}
resource "aws_route_table" "private_route_table" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_nat_gateway.nat.id
}
tags = {
Name = "private-route-table"
}
}
resource "aws_route_table_association" "private_subnet_1_assoc" {
subnet_id = aws_subnet.subnet_1.id
route_table_id = aws_route_table.private_route_table.id
}
resource "aws_route_table_association" "private_subnet_2_assoc" {
subnet_id = aws_subnet.subnet_2.id
route_table_id = aws_route_table.private_route_table.id
}
resource "aws_route_table_association" "private_subnet_3_assoc" {
subnet_id = aws_subnet.subnet_3.id
route_table_id = aws_route_table.private_route_table.id
}