Skip to content

A demonstration of Terraform to setup 3-Tier app infrastructure in AWS

Notifications You must be signed in to change notification settings

naeemark/tf-aws-three-tier-infra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform Three Tier Infrasture on AWS

Terraform Validate and Plan

Demonstration of requirements understanding, proposing a solution and implementation of Infrastructure as a Code by using the latest tools and techniques.



What is this repository for

  • A terraform project to solve the task for tecAlliance
  • Demonstrates infrastructure architecture for AWS Cloud
  • CI/CD implementation using Github Actions in repo
  • The live environment will be established on AWS.

Problem Statement:

Problem Statement

Proposed Solution:

  • As per the provided instructions, I would like to use terraform for the infrastructure provisioning.
  • A custom VPC along with public and private subnests will be created.
  • As demanded, a MySQL RDS Instance will be prepared for persistence.
  • Backend EC2 will be hosted in one of the private subnets.
  • The Frontend required multiple instances, so an Auto Scalling Group with the provided configs might be a good solution.
  • For testing, a bastion host will be provisioned, which will have necessary access to lookup inside the private resources.
  • Frontends will be connected to an Application Load Balancer.
  • Frontend and Backend instances should include some script for bootstraping / initial configurations.
  • Terraform should use necessary features for security and reusability of code.
  • A ci/cd pipeline should be inplaced for mocking the whole flow in repository.
  • Resources should be used as modules. (Will keep in same repo)
  • The project should be prepared in a way to easily scale for a multi environment deployments with minimal changes.
  • ALB endpoint should be shown as an output.

Deployment Flow

Deployment flow

Infrastructure

Infrastructure

Assumptions

  • Frontends and Backend wont have any applications to serve the requests.
  • Some health check servers will started i.e nginx,
  • This task is to demonstrate the infrastructure best practices.
  • There won't be a requirements to keep this system up for a long time, instead, some screenshot can be provided for validation.
  • Provision of resources to setup a Bastion host will be conditional.
  • Due to unavailability of SSL/TLS Certificate, ALB could not be tested on https port:443, but the code will be provided

Deliverable Content

Directory Structure

├── .github
│   └── workflows
│       └── terraform.yml
├── .gitignore
├── README.md
├── blueprint
│   ├── backend.tf
│   ├── main.tf
│   ├── modules
│   │   ├── backend
│   │   │   ├── main.tf
│   │   │   ├── outputs.tf
│   │   │   └── variables.tf
│   │   ├── bastion
│   │   │   ├── main.tf
│   │   │   ├── outputs.tf
│   │   │   └── variables.tf
│   │   ├── database
│   │   │   ├── main.tf
│   │   │   ├── outputs.tf
│   │   │   └── variables.tf
│   │   ├── frontend
│   │   │   ├── main.tf
│   │   │   └── variables.tf
│   │   ├── load_balancer
│   │   │   ├── main.tf
│   │   │   ├── outputs.tf
│   │   │   └── variables.tf
│   │   ├── network
│   │   │   ├── main.tf
│   │   │   ├── outputs.tf
│   │   │   └── variables.tf
│   │   └── security_groups
│   │       ├── main.tf
│   │       ├── outputs.tf
│   │       └── variables.tf
│   ├── outputs.tf
│   └── variables.tf
├── envs
│   └── dev
│       ├── main.tf
│       ├── outputs.tf
│       └── variables.tf
└── scripts
    ├── init_backend_server.sh
    ├── init_bastion_host.sh
    └── init_frontend_server.sh

Development Cycle

Developer Setup

To setup the project locally you need to clone this repo, from main branch or some latest TAG

cd to envs/dev

# cd to `envs/dev` and initialize the project
$ terraform init

#  to Validate
$ terraform validate

# to plan
$ terraform plan

# Apply the changes to aws cloud
$ terraform apply

# Cleanup
$ terraform destroy

Configuration

  • Terraform should be installed
  • ⚠️ AWS Credentials should be setup as defualt profile of local machine

Pre-reqs

  • terrafom (used Terraform v1.4.3-dev)
  • aws credentials
  • VS Code

Deployment

  • When a pull request is merged in main, Github Action starts and following steps are done by automated CI/CD:
    • Makes a deployment to AWS (Mock)

Contribution guidelines

  • Forks are always appreciated

Screenshots

  • Browser Output
  • 2
  • 3
  • 4
  • 5
  • 5a
  • 6
  • 6a
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

About

A demonstration of Terraform to setup 3-Tier app infrastructure in AWS

Resources

Stars

Watchers

Forks

Packages

No packages published