Skip to content

Three-tier AWS architecture for web application and deployment using automation IAC Terraform with S3 Remote backend.

Notifications You must be signed in to change notification settings

CrescentCloud/S3_RemoteBackend-AWS_3tier--Terraform

Repository files navigation

Deploy AWS 3-tier architecture using Terraform with S3 Remote Backend

terraform_aws diagram

Scenario:

Design and create a highly available three-tier AWS architecture for web application and deploy using automation IAC Terraform with S3 Remote backend. User will access the application through the Internet, but the database mustn’t be accessible by the user.

Overview:

Three-tier architecture that includes a presentation tier (user interface), logic tire(application), and data tier(database) is the most implemented in terms of high scalability, security, data integrity, and performance.

Why Terraform?

Terraform is one of the most popular open-source infrastructures as a code automation tool created by HashiCorp. It can manage infrastructure on multiple cloud platforms and supports human-readable configuration language, which helps write infrastructure code quickly and efficiently. Terraform's state allows tracking resource changes throughout your deployments.

RemoteBackends

Remote backends enable storage of TerraForm state in a remote, location to enable secure collaboration.

In this project I use AWS S3 + Dynamo DB for remote Backend

AWS 3 Tire Architecture:

•  VPC
•  EC2 instances
•  Elastic IP
•  Baston Host
•  Nat Gateway
•  Load balancer
•  Auto Scaling
•  RDS instance
•  Route 53 DNS Config

Prerequisites

--> AWS Account
--> AWS Access & Secret Key
--> Terraform installed on IDE (i.e Visual Studio Code)
--> SSH Agent (For Windows), AWS Installed on Terminal (For Mac)
--> MySql Workbech for Database connection testing

Deployment

Steps

01. Run Terraform command

Step 0 used to initialize a working directory containing Terraform configuration files

terraform init

Step 1 used to create an execution plan

terraform plan

Step 2 validates the configuration files in a directory, referring only to the configuration and not accessing any remote services such as remote state, provider APIs, etc

terraform validate

Step 3 used to apply the changes required to reach the desired state of the configuration Steps to initialize backend in AWS and manage it with Terraform:

terraform apply

Screen Shot 2023-04-14 at 12 11 02 AM

02. To use S3 bucket and dynamoDB table to be used as the state backend add this code

backend "s3" {
bucket         = "terraform-bucket"  # s3 bucket name
 key            = "tf/terraform.tfstate"  # state file location
region         = "us-east-1"
dynamodb_table = "terraform-state-locking"
 encrypt        = true
 }

03 . Reinitialize with

terraform init 

Troubleshooting :

if Reinitialize failed
Screen Shot 2023-04-14 at 12 12 11 AM
run bellow code

terraform init -backend-config="access_key=<your_AWS_access_key>" -backend-config="secret_key=<your_AWS_secret_key>" -backend-config="region=us-east-1"

Testing :

On the AWS console, the following item should be available: VPC, subnets, IGW, EC2 instances, load balancers, autoscaling, RDS database, route 53, and S3 bucket with inside terraform state file

S3

Screen Shot 2023-04-14 at 1 05 57 AM

Screen Shot 2023-04-14 at 12 22 30 AM

VPC

Screen Shot 2023-04-14 at 12 19 30 AM

subnet

Screen Shot 2023-04-14 at 12 47 50 AM

loadbalancer

Screen Shot 2023-04-14 at 12 20 40 AM

RDS

Screen Shot 2023-04-14 at 12 25 50 AM

Route 53-> Hosted Zone

Screen Shot 2023-04-14 at 1 30 43 AM

Screen Shot 2023-04-14 at 12 23 39 AM

SSH to Bastion Host

Screen Shot 2023-04-14 at 2 17 35 AM

Connect Application server using private IP

Screen Shot 2023-04-14 at 2 27 20 AM

About

Three-tier AWS architecture for web application and deployment using automation IAC Terraform with S3 Remote backend.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published