From 1f8af064cbc36f10cabb4bb89c913ab965ba2675 Mon Sep 17 00:00:00 2001 From: mayowales Date: Fri, 6 Feb 2026 01:44:05 +0100 Subject: [PATCH 1/4] Dokerized app and update compose file --- docker-compose.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f2e4b91b..0aa483fa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ services: vote: - image: pokfinner/vote:latest + image: mayowales/voting-app:latest # build: ./vote depends_on: redis: @@ -14,7 +14,7 @@ services: - back-tier result: - image: pokfinner/result:latest + image: mayowales/result-app:latest # build: ./result depends_on: db: @@ -26,7 +26,7 @@ services: worker: # build: ./worker - image: pokfinner/worker:latest + image: mayowales/worker-app:latest depends_on: redis: condition: service_healthy From 199ad7ce31f3aca2c6ae1ce1ae3c237deec89ce6 Mon Sep 17 00:00:00 2001 From: mayowales Date: Fri, 6 Feb 2026 11:44:26 +0100 Subject: [PATCH 2/4] terraform-skeleton --- terraform/main.tf | 0 terraform/module/compute/main.tf | 0 terraform/module/compute/outputs.tf | 0 terraform/module/compute/variables.tf | 0 terraform/module/networking/main.tf | 0 terraform/module/networking/outputs.tf | 0 terraform/module/networking/variables.tf | 0 terraform/outputs.tf | 0 terraform/provider.tf | 0 terraform/terraform.tfvars | 0 terraform/variables.tf | 0 11 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 terraform/main.tf create mode 100644 terraform/module/compute/main.tf create mode 100644 terraform/module/compute/outputs.tf create mode 100644 terraform/module/compute/variables.tf create mode 100644 terraform/module/networking/main.tf create mode 100644 terraform/module/networking/outputs.tf create mode 100644 terraform/module/networking/variables.tf create mode 100644 terraform/outputs.tf create mode 100644 terraform/provider.tf create mode 100644 terraform/terraform.tfvars create mode 100644 terraform/variables.tf diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 00000000..e69de29b diff --git a/terraform/module/compute/main.tf b/terraform/module/compute/main.tf new file mode 100644 index 00000000..e69de29b diff --git a/terraform/module/compute/outputs.tf b/terraform/module/compute/outputs.tf new file mode 100644 index 00000000..e69de29b diff --git a/terraform/module/compute/variables.tf b/terraform/module/compute/variables.tf new file mode 100644 index 00000000..e69de29b diff --git a/terraform/module/networking/main.tf b/terraform/module/networking/main.tf new file mode 100644 index 00000000..e69de29b diff --git a/terraform/module/networking/outputs.tf b/terraform/module/networking/outputs.tf new file mode 100644 index 00000000..e69de29b diff --git a/terraform/module/networking/variables.tf b/terraform/module/networking/variables.tf new file mode 100644 index 00000000..e69de29b diff --git a/terraform/outputs.tf b/terraform/outputs.tf new file mode 100644 index 00000000..e69de29b diff --git a/terraform/provider.tf b/terraform/provider.tf new file mode 100644 index 00000000..e69de29b diff --git a/terraform/terraform.tfvars b/terraform/terraform.tfvars new file mode 100644 index 00000000..e69de29b diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 00000000..e69de29b From 0dff82b031170569e56bda9988c5333f4cb09a0d Mon Sep 17 00:00:00 2001 From: mayowales Date: Fri, 6 Feb 2026 15:37:06 +0100 Subject: [PATCH 3/4] create network wodules and .tfvar --- terraform/module/networking/main.tf | 92 ++++++++++++++++++++++++ terraform/module/networking/outputs.tf | 11 +++ terraform/module/networking/variables.tf | 20 ++++++ terraform/terraform.tfvars | 3 + 4 files changed, 126 insertions(+) diff --git a/terraform/module/networking/main.tf b/terraform/module/networking/main.tf index e69de29b..d3eaf989 100644 --- a/terraform/module/networking/main.tf +++ b/terraform/module/networking/main.tf @@ -0,0 +1,92 @@ +# Creating VPC +resources "aws_vpc" "main" { + cidr_block = var.vpc_cidr + enable_dns_hostnames = true + enable_dns_support = true + + tags = { + Name = "wale-project-vpc" + } +} + +# creating Subnets +resources "aws_subnet" "public-sn" { + count = length(var.public_subnet_cidrs) + vpc_id = aws_vpc.main.vpc_id + cidr_block = var.public_subnet_cidrs[count.index] + map_public_ip_lunch = true + + tags = { + Name = "Public-subnet-${count.index + 1}" + } +} + + +resources "aws_subnet" "public-sn" { + count = length(var.private_subnet_cidrs) + vpc_id = aws_vpc.main.vpc_id + cidr_block = var.private_subnet_cidrs[count.index] + map_public_ip_lunch = false + + tags = { + Name = "Private-subnet-${count.index + 1}" + } +} + +# Internet Gateway +resources "aws_internet_gateway" "igw" { + vpc_id = aws_vpc.main.id + + tags = { + Name = "wales-igw" + } +} + +# NAT Gateway +resources "aws_nat_gateway" "nat" { + subnet_id = aws_subnet.public-sn.id + + tags = { + Name = "wales-nat-gw" + } +} + +# Route Tables +resources "aws_route_table" "public-rt" { + vpc_id = aws_vpc.main.id + + route { + cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.igw.id + } + + tags = { + Name = "wale-public-rt" + } +} + +resources "aws_route_table" "private-rt" { + vpc_id = aws_vpc.main.id + + route { + cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.igw.id + } + + tags = { + Name = "wale-private-rt" + } +} + +# Associations +resources ""aws_rout_table_association" "wale-public" { + count = length(var.public_subnet_cidr) + subnet_id = aws_subnet.public-sn[count.index].id + route_table_id = aws_route_table.public-rt.id +} + +resources ""aws_rout_table_association" "wale-private" { + count = length(var.private_subnet_cidr) + subnet_id = aws_subnet.private-sn[count.index].id + route_table_id = aws_route_table.private-rt.id +} diff --git a/terraform/module/networking/outputs.tf b/terraform/module/networking/outputs.tf index e69de29b..6ce0f61b 100644 --- a/terraform/module/networking/outputs.tf +++ b/terraform/module/networking/outputs.tf @@ -0,0 +1,11 @@ +ouput "vpc_id { + value = aws_vpc.main.id +} + +ouput "public_subnet_ids" { + value = aws_subnet.public-sn[*].id +} + +ouput "private_subnet_ids" { + value = aws_subnet.private-sn[*].id +} diff --git a/terraform/module/networking/variables.tf b/terraform/module/networking/variables.tf index e69de29b..6a5d5073 100644 --- a/terraform/module/networking/variables.tf +++ b/terraform/module/networking/variables.tf @@ -0,0 +1,20 @@ + +variable "vpc_cidr" { + type = string + description = "The cidr block for the VPC" +} + +variable "vpc_name" { + type = string + description = "The cidr block for the VPC" +} + +variable "public_subnet_cidrs" { + type = list(string) + description = "Public subnet IP range" +} + +variable "private_subnet_cidrs" { + type = list(string) + description = "Private subnet ip range" +} diff --git a/terraform/terraform.tfvars b/terraform/terraform.tfvars index e69de29b..4ebbf86b 100644 --- a/terraform/terraform.tfvars +++ b/terraform/terraform.tfvars @@ -0,0 +1,3 @@ +vpc_cidr = "10.0.0.0/16" +public_subnet_cidrs = ["10.0.1.0/24"] +private_subnet_cidrs = ["10.0.2.0/24"] From 0983860677b82a68f8d74be3dc3c72ff628f66fe Mon Sep 17 00:00:00 2001 From: mayowales Date: Fri, 6 Feb 2026 16:17:21 +0100 Subject: [PATCH 4/4] updated compute module --- terraform/module/compute/main.tf | 59 +++++++++++++++++++++++++++ terraform/module/compute/outputs.tf | 9 ++++ terraform/module/compute/variables.tf | 34 +++++++++++++++ terraform/terraform.tfvars | 7 ++++ 4 files changed, 109 insertions(+) diff --git a/terraform/module/compute/main.tf b/terraform/module/compute/main.tf index e69de29b..8fb72067 100644 --- a/terraform/module/compute/main.tf +++ b/terraform/module/compute/main.tf @@ -0,0 +1,59 @@ +# Security Groups +resource "aws_security_group" "public_sg" { + name = "frontend-sg" + vpc_id = var.vpc_id + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } +} + +resource "aws_security_group" "private_sg" { + name = "backend-sg" + vpc_id = var.vpc_id + ingress { + from_port = 0 + to_port = 0 + protocol = "-1" + security_groups = [aws_security_group.public_sg.id] + } + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } +} + +# EC2 Instances +resource "aws_instance" "app_nodes" { + for_each = var.instance_map + + ami = var.ami_id + instance_type = var.instance_type + key_name = var.key_name + + # Logic: If the map says "public", use the public subnet, else private + subnet_id = each.value.is_public ? var.public_subnet_id : var.private_subnet_id + + # Logic: If public, use public SG, else private SG + vpc_security_group_ids = [each.value.is_public ? aws_security_group.public_sg.id : aws_security_group.private_sg.id] + + tags = { + Name = "${each.key}-server" + } +} diff --git a/terraform/module/compute/outputs.tf b/terraform/module/compute/outputs.tf index e69de29b..6c91fdfc 100644 --- a/terraform/module/compute/outputs.tf +++ b/terraform/module/compute/outputs.tf @@ -0,0 +1,9 @@ + +output "instance_ips" { + value = { + for name, instance in aws_instance.app_nodes : name => { + public_ip = instance.public_ip + private_ip = instance.private_ip + } + } +} diff --git a/terraform/module/compute/variables.tf b/terraform/module/compute/variables.tf index e69de29b..f3cd3d0e 100644 --- a/terraform/module/compute/variables.tf +++ b/terraform/module/compute/variables.tf @@ -0,0 +1,34 @@ +variable "vpc_id" { + type = string +} + +variable "vpc_cidr" { + type = string +} + +variable "public_subnet_id" { + type = string +} + +variable "private_subnet_id" { + type = string +} + +variable "ami_id" { + type = string +} + +variable "instance_type" { + type = string +} + +variable "key_name" { + type = string +} + +variable "instance_map" { + type = map(object({ + is_public = bool + })) + description = "A simple map of instance names and whether they are public or private" +} diff --git a/terraform/terraform.tfvars b/terraform/terraform.tfvars index 4ebbf86b..89d01221 100644 --- a/terraform/terraform.tfvars +++ b/terraform/terraform.tfvars @@ -1,3 +1,10 @@ vpc_cidr = "10.0.0.0/16" public_subnet_cidrs = ["10.0.1.0/24"] private_subnet_cidrs = ["10.0.2.0/24"] + + +instance_map = { + "vote-app" = { is_public = true } + "worker" = { is_public = false } + "db" = { is_public = false } +}