diff --git a/main.tf b/main.tf index ea0070a..0f737ea 100644 --- a/main.tf +++ b/main.tf @@ -44,4 +44,82 @@ resource "aws_subnet" "subnet_3" { tags = { Name = "subnet-3" } -} \ No newline at end of file +} + +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_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 +} diff --git a/variables.tf b/variables.tf index 5458109..8f294c4 100644 --- a/variables.tf +++ b/variables.tf @@ -5,19 +5,19 @@ variable "aws_region" { } variable "availability_zone_1" { - description = "Zona de disponibilidade para a primeira Subnet" + description = "Zona de disponibilidade 1a" type = string default = "us-east-1a" } variable "availability_zone_2" { - description = "Zona de disponibilidade para a segunda Subnet" + description = "Zona de disponibilidade 1b" type = string default = "us-east-1b" } variable "availability_zone_3" { - description = "Zona de disponibilidade para a terceira Subnet" + description = "Zona de disponibilidade 1c" type = string default = "us-east-1c" } @@ -44,4 +44,10 @@ variable "subnet_3_cidr" { description = "CIDR block da terceira Subnet" type = string default = "10.0.3.0/24" +} + +variable "subnet_4_public_cidr" { + description = "CIDR block da quarta Subnet (publica)" + type = string + default = "10.0.4.0/24" } \ No newline at end of file