From 3fe30671d9a8afcc4647d7bd6bee32054bd80ede Mon Sep 17 00:00:00 2001 From: Matheus Jacques Date: Thu, 24 Aug 2023 17:06:23 +0200 Subject: [PATCH] fix(terraform): update subnet_id in docker-swarm module to use swarm-public-subnet instead of swarm-subnet for improved clarity feat(terraform): add aws_subnet resource for swarm-public-subnet to create a public subnet for the swarm cluster feat(terraform): add aws_internet_gateway resource to create an internet gateway for the swarm VPC feat(terraform): add aws_route_table resource to create a route table for the swarm VPC feat(terraform): add aws_route_table_association resource to associate the swarm-public-subnet with the public route table --- deploy/scripts/terraform/main.tf | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/deploy/scripts/terraform/main.tf b/deploy/scripts/terraform/main.tf index 2b84a4678..3bbd08fc1 100644 --- a/deploy/scripts/terraform/main.tf +++ b/deploy/scripts/terraform/main.tf @@ -6,7 +6,7 @@ module "docker-swarm" { source = "./modules/docker-swarm" key_name = aws_key_pair.swarm-key.key_name vpc_id = aws_vpc.swarm-vpc.id - subnet_id = aws_subnet.swarm-subnet.id + subnet_id = aws_subnet.swarm-public-subnet.id security_group = aws_security_group.swarm-sg.id instance_type = "t2.micro" # Choose the instance type as needed manager_count = 1 @@ -24,11 +24,34 @@ resource "aws_vpc" "swarm-vpc" { enable_dns_hostnames = true } -resource "aws_subnet" "swarm-subnet" { +resource "aws_subnet" "swarm-private-subnet" { vpc_id = aws_vpc.swarm-vpc.id cidr_block = "10.0.1.0/24" } +resource "aws_subnet" "swarm-public-subnet" { + vpc_id = aws_vpc.swarm-vpc.id + cidr_block = "10.0.2.0/24" +} + +resource "aws_internet_gateway" "igw" { + vpc_id = aws_vpc.swarm-vpc.id +} + +resource "aws_route_table" "public_rt" { + vpc_id = aws_vpc.swarm-vpc.id + + route { + cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.igw.id + } +} + +resource "aws_route_table_association" "public_subnet_asso" { + subnet_id = aws_subnet.swarm-public-subnet.id + route_table_id = aws_route_table.public_rt.id +} + resource "aws_security_group" "swarm-sg" { vpc_id = aws_vpc.swarm-vpc.id