Skip to content

GitHub repo for deploying AWS architecture using Terraform. Build, manage, and scale your infrastructure efficiently.

Notifications You must be signed in to change notification settings

Ayush2948/Terraform-Architecture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 

Repository files navigation

This repository provides the code and documentation for modernizing the deployment and scaling of a web application using Terraform on Amazon Web Services (AWS) infrastructure. The primary objective is to implement a three-tier architecture using Infrastructure-as-Code (IaC) principles with Terraform.

Table of Contents

What is Terraform?

Terraform is an open-source Infrastructure-as-Code (IaC) tool developed by HashiCorp. It allows you to define and manage infrastructure through code, automatically creating, updating, or deleting resources to match your desired state. This approach brings predictability, version control, and automation to infrastructure management.

What is Infrastructure as Code (IaC)?

IaC automates infrastructure provisioning and management with code. Instead of manual configurations, tools like Terraform enable you to define infrastructure using code that's versioned, testable, and ensures consistent and repeatable deployments.

How Terraform Works

Terraform follows a simple three-step process:

  1. Write: Define your infrastructure in Terraform configuration files.
  2. Plan: Terraform generates an execution plan that shows what will change in your infrastructure.
  3. Apply: Execute the plan to create, update, or delete resources accordingly.


                aws-terraform-2.png

Basic Terraform Commands

  • terraform init: Initializes your Terraform environment.
  • terraform plan: Generates an execution plan to show what changes will be applied.
  • terraform apply: Executes the plan to create or modify resources.
  • terraform destroy: Destroys the created infrastructure.

Basic Terraform Terms

  • Variables in Terraform: Placeholders for dynamic values in your configurations, making them flexible and reusable.
  • Resources in Terraform: Infrastructure components you manage, such as EC2 instances, VPCs, and databases.

Understanding the Architecture

A three-tier architecture divides an application into three interconnected layers: the presentation tier, application tier, and data tier. In our case, this architecture consists of a custom Virtual Private Cloud (VPC), Internet Gateway, subnets, EC2 instances, route tables, NAT Gateway, and an RDS database.

Terraform Flow Diagram

Environment Setup Prerequisites

To get started, you'll need the following:

  • AWS Account Access Keys: You must have an AWS account and access credentials. Create keys in the AWS IAM section.
  • AWS CLI Installation: Install the AWS Command Line Interface (CLI) to interact with AWS services.
  • Terraform Installation: Install Terraform, an infrastructure-as-code tool by HashiCorp.
  • AWS Profile Configuration: Use the AWS CLI to set up a profile with your access keys and preferred region for deployment.
  • VS Code Installation: Install Visual Studio Code (VS Code) for code editing.

Steps to Create the Architecture

Follow these steps to create the architecture using Terraform, as outlined in the code provided:

  1. Define the provider and region.
  2. Create a custom VPC.
  3. Create subnets.
  4. Set up security groups for EC2 instances and RDS.
  5. Create EC2 instances.
  6. Set up an Internet Gateway.
  7. Create a route table for the public subnet.
  8. Define a route for the public subnet.
  9. Associate the custom route table with the public subnet.
  10. Set up a NAT Gateway.
  11. Create an RDS database.
  12. Create an Elastic IP.

How to Run this Code

  1. Save the provided code in a .tf file.
  2. Open a terminal.
  3. Run terraform init.
  4. Run terraform plan.
  5. Run terraform apply to create the infrastructure.
  6. To destroy the infrastructure, run terraform destroy.

Troubleshooting

If you encounter issues:

  1. Ensure Terraform is installed and environment variables are set correctly.
  2. Check the security group rules and network ACLs.
  3. Verify route table settings for the public subnet.
  4. Ensure instances have public IPs or Elastic IPs.
  5. Double-check route table associations and instance statuses.

blog-1-Traced-1.png    linkedin-1.png

About

GitHub repo for deploying AWS architecture using Terraform. Build, manage, and scale your infrastructure efficiently.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages