Page cover

(AWS) Highly available Design deployment

Task Requirement

Architecture

File Structure

Terraform Resources + Code Steps

Configure AWS Provider

used HCP as Statefile saver (for security and team work things).

Setup Variables

will use these variables in code later.

Set Variables

VPCs Resource Deployment

Created Three VPCs, with enabled DNS hostname and support for flexible communicate.

Subnets Resource Deployment

Created 4 private subnets for VPC 1, Two private subnets in different AZ's for the app and auto-scaling group, and other subnets for RDS and Standby RDS.

Created 1 private subnets for VPC 2, private subnet to hold EC2 Server.

And finally created 4 Subnets for VPC 3, Two subnet is Public and the other two is Private, Note: If you have NAT GW in your public subnet you should have the same AZ because of Low latency and Cost .

Gateway Resource Deployment

Created Internet Gateway to connect to the internet in VPC 3 as required, Created Elastic IP for NAT GW so it can have IP to connect to the internet, and finally Created NAT GW to connect private Servers to Internet without expose servers IPs.

Transit Gateway and Attachment Resource Deployment

Created Transit to connect the three VPCs together through it like a (Hub).

Created Attachments for every VPC, it's like making a gate in both VPCs and Transit GW.

Created Association for every attachment, it's like to connect the gates together like making a road to travel through.

Transit Route table and subnets route tables Resource Deployment

Created One Route table for VPC 1, routes accept any traffic from/to transit GW, then associate every subnet in VPC 1 to this one route table.

Created One Route table for VPC 2, routes accept any traffic from/to transit GW, then associate every subnet in VPC 2 to this one route table.

Created Two Route Table for VPC 3, first one Public RTB that routes for 3 things

  1. Routes to Internet GW

  2. Routes to VPC 1 through Transit GW

  3. Routes to VPC 2 through Transit GW

circle-check

then associate public subnet to the public RTB, second one Private RTB that routes only for NAT GW, then associate private subnet to the private RTB.

circle-check

Created Transit GW Route table.

Then created route to VPC 1, by adding VPC 1 CIDER block and transit GW Table ID and the expected gate of VPC 1 ID.

created route to VPC 2, by adding VPC 1 CIDER block and transit GW Table ID and the expected gate of VPC 2 ID.

created route to VPC 1, by adding VPC 3 CIDER block and transit GW Table ID and the expected gate of VPC 3 ID.

created route_to_vpc_3_pub_sub and adding CIDR "0.0.0.0/0" and the expected gate of VPC 3 ID.

triangle-exclamation

Security Group Resource Deployment

Created Security group for VPC 1,

  • Ingress rules: Allowed HTTP so i can see the app in port 80, Allowed SSH so i can securely check the app logs, Allowed ICMP to check connections, Allowed RDS postgress port the app can connect to Database.

  • egress rule: Allowed all traffic to go out.

Created Security group for VPC 2,

  • Ingress rules:Allowed SSH so i can securely check ec2 logs, Allowed ICMP to check connection.

  • egress rule: Allowed all traffic to go out.

Created Security group for VPC 3,

  • Ingress rules: Allowed HTTP so i can see the app in port 80, Allowed SSH so i can securely check the app logs.

  • egress rule: Allowed all traffic to go our.

circle-info

SSH allowed so i can connect to any EC2 in every VPC.

EC2 Resource Deployment

Created Key pair and make it download in bastion host so i can have SSH Connection to other EC2s easily. (in both VPC 3 & 2)

RDS Resource Deployment

Created RDS with specific Requirment as the task and password managed by Secret Manager Service

Created Subnet group for db so i can include the primary AZ and the standby AZ

Load Balancer Resource Deployment

Created Two load balancer, One Internal Load balancer for the application in VPC 1, and one Public Load balancer for the user.

Auto-Scaling Group Resource Deployment

Created templat to nginx server to be proxy for Public ALB

Created ASG Service and attach it to VPC 3.

Created template so i can use it in multiple EC2 that the ASG Service will create in high load.

Created ASG Service and attach it to VPC 1 as Required.

triangle-exclamation

Check Code

Connected to Bastion host and pinged one server from VPC 1

Connected to one server in VPC 1 from Bastion host

and Finally internal Load Balancer can be accessed through nginx proxy and Public Application Load balancer.

You can Check whole Task in here (githubarrow-up-right)

That's it, quick and simple! 🚀 I hope this guide has sparked some ideas, and I’d love to hear your thoughts. Thanks!

Last updated