Skip to content

πŸš€ Terraws automates AWS infrastructure with Terraform! Create a VPC, deploy EC2s, load balance traffic, manage state in S3/DynamoDB, and future IAM integration for secure S3 access. πŸ—οΈπŸŒ.❌❌ Due To credit limitation the below URL resources may not be available ❌❌

Notifications You must be signed in to change notification settings

moshdev2213/Terraws

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌍 Terraws - AWS Infrastructure with Terraform πŸ› οΈ

19 (1)

🎯 Project Overview

The Terraws project automates the deployment of a scalable and secure AWS infrastructure. It is designed to demonstrate key AWS services and features, including EC2, VPC, S3, and Load Balancers. The infrastructure is organized into reusable modules, making it easier to maintain and extend.

πŸ‘Ύ Features of the Project:

  1. VPC Setup 🏠

    • Creates a custom VPC to isolate resources securely.
    • Two public subnets are created within this VPC to host EC2 instances. Each instance has internet access via a public route table and internet gateway.
    • Enables flexibility for adding more resources in the future, such as private subnets or NAT gateways.
  2. EC2 Instances πŸ–₯️

    • Two EC2 instances, each deployed in separate public subnets for high availability.
    • EC2 instances are pre-configured to connect to the internet and access other AWS services like S3 (future integration via IAM Roles planned).
    • Easy scaling to accommodate more EC2 instances as needed.
  3. S3 Bucket for Storage πŸ“¦

    • An S3 bucket is created to serve as a scalable storage solution.
    • Future plans include setting up fine-grained IAM roles to allow EC2 instances to interact securely with the S3 bucket.
    • Can be used for storing logs, backups, or any other project files that need to be accessed from the EC2 instances.
  4. Load Balancer πŸ–§

    • A highly available Application Load Balancer (ALB) distributes traffic across the EC2 instances.
    • The load balancer ensures that traffic is evenly distributed, and it automatically adjusts as more instances are added.
    • With health checks enabled, the load balancer ensures that traffic only goes to healthy EC2 instances.
  5. State Management πŸ—„οΈ

    • Terraform state is stored in a remote S3 bucket for centralized and persistent state management. This ensures that all team members work with the same state file.
    • A DynamoDB table is used to enable state locking, preventing race conditions when multiple users attempt to run Terraform commands concurrently.

πŸ—οΈ Infrastructure Architecture

Here's a quick look at the AWS architecture deployed by this Terraform project:

  • VPC with two public subnets, each hosting an EC2 instance.
  • Application Load Balancer to distribute traffic across EC2 instances.
  • S3 Bucket for storage, accessible by EC2 instances.
  • Terraform state stored in S3, with locking in DynamoDB to ensure safe, concurrent operations.

πŸš€ Deployed Ec2 Images

ec1


ec2

πŸš€ Getting Started with Terraform

1. Install Terraform πŸ§‘β€πŸ’»

Make sure you have Terraform installed on your machine. You can download it from the official site:

# For macOS (via brew)
brew install terraform

# For Linux (via apt)
sudo apt-get install terraform

# For Windows
choco install terraform

Check the installation:

terraform --version

2. Configure AWS CLI πŸ”‘

Terraform interacts with AWS using your AWS credentials. Set up the AWS CLI and configure your access keys.

# Install AWS CLI
brew install awscli # For macOS
sudo apt install awscli # For Linux

# Configure the AWS CLI
aws configure

You'll be prompted to enter your:

  • AWS Access Key ID
  • AWS Secret Access Key
  • Default region name (e.g., us-east-1)
  • Default output format (e.g., json)

3. Clone the Repository 🧩

git clone https://github.com/yourusername/terraws.git
cd terraws

4. Structure πŸ“‚

The project is modularized to maintain a clean and reusable structure:

/terraws
β”‚
β”œβ”€β”€ /modules
β”‚   β”œβ”€β”€ /vpc
β”‚   β”œβ”€β”€ /ec2
β”‚   β”œβ”€β”€ /loadbalancer
β”‚   └── /s3
β”‚
β”œβ”€β”€ /assets
β”‚   β”œβ”€β”€ ec2_01.png
β”‚   β”œβ”€β”€ ec2_02.png
|
β”œβ”€β”€ /scripts
β”‚   β”œβ”€β”€ startup_script_ec2_01.sh
β”‚   β”œβ”€β”€ startup_script_ec2_02.sh
|
β”œβ”€β”€ main.tf       # Main entry point for Terraform
β”œβ”€β”€ variables.tf  # Variables definition
β”œβ”€β”€ outputs.tf    # Outputs definition
└── terraform.tfstate # State file stored remotely
└── backend.tf # file about remote state and locker

5. Configure S3 Backend & DynamoDB for State Management πŸ—„οΈ

Before you start, ensure the state is stored securely by configuring S3 and DynamoDB. This project already includes the backend configuration in main.tf:

terraform {
  backend "s3" {
    bucket         = "your-s3-bucket-name"
    key            = "path/to/terraform.tfstate"
    region         = "us-east-1"
    dynamodb_table = "terraform-lock-table"
  }
}

6. Initialize Terraform βš™οΈ

Run the following to initialize the Terraform environment and download the necessary providers:

terraform init

If using a config file for the backend then use below command

terraform init -backend-config=backend.conf

7. Plan the Infrastructure πŸ“

To check what changes will be applied without actually making any changes:

terraform plan

8. Apply the Configuration πŸš€

To provision your AWS infrastructure:

terraform apply

You’ll be prompted to type yes to confirm and apply the changes.

9. Access Your Infrastructure 🌐

Once the infrastructure is set up, you'll get outputs like:

  • EC2 instance public IPs 🌐
  • Load Balancer DNS name πŸ–§
  • VPC ID 🏠

10. Tear Down the Environment πŸ’£

When you're done and want to clean up, run:

terraform destroy

This will remove all the resources created by Terraform.


πŸ“œ Detailed Features and Setup:

VPC Module 🏠

  • Configures a custom VPC with two public subnets.
  • Attaches an Internet Gateway for outgoing traffic to the internet.
  • Routes internet-bound traffic through a public route table.

EC2 Module πŸ–₯️

  • Launches EC2 instances in each of the public subnets.
  • Includes key-pair setup for SSH access to the instances.
  • Configures security groups to allow SSH (port 22) and HTTP (port 80) traffic.

Load Balancer Module πŸ–§

  • Deploys an Application Load Balancer to distribute traffic across EC2 instances.
  • Configures listeners and target groups for the EC2 instances.
  • Includes health checks to ensure the load balancer only sends traffic to healthy instances.

S3 Module πŸ“¦

  • Creates an S3 bucket for storage needs (e.g., logs, backups, etc.).
  • Planned IAM roles to securely manage access to the S3 bucket from EC2 instances.

πŸ“œ Future Improvements

  • IAM Roles: Adding fine-grained access control to S3 for EC2 instances.
  • Auto Scaling: Configuring auto-scaling for EC2 instances behind the load balancer.
  • Monitoring & Logging: Set up AWS CloudWatch for monitoring and alarms.
  • Database Integration: Plan to include an RDS instance or DynamoDB for data storage.

🌟 Let's build the cloud infrastructure, with code 🌟

About

πŸš€ Terraws automates AWS infrastructure with Terraform! Create a VPC, deploy EC2s, load balance traffic, manage state in S3/DynamoDB, and future IAM integration for secure S3 access. πŸ—οΈπŸŒ.❌❌ Due To credit limitation the below URL resources may not be available ❌❌

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published