Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

module

Terraform modules for deploying infrastructure with Terraform & Amazon ECS

🛒 AWS E-Commerce Infrastructure Deployment with Terraform & Amazon ECS

A production-ready Infrastructure as Code (IaC) project that deploys a scalable, secure, and highly available eCommerce application on AWS using Terraform Modules and Amazon Elastic Container Service (ECS).

This project demonstrates cloud infrastructure automation, container orchestration, networking, security, load balancing, and CI/CD best practices following AWS Well-Architected Framework principles.


📖 Project Overview

The objective of this project is to provision a complete AWS environment capable of hosting a containerized eCommerce application.

The infrastructure is fully automated using reusable Terraform modules and includes networking, compute, security, load balancing, monitoring, and container deployment.

The architecture is designed to be:

  • Highly Available
  • Scalable
  • Fault Tolerant
  • Modular
  • Production Ready
  • Easy to Maintain

🚀 Features

Infrastructure as Code

  • Modular Terraform Architecture
  • Reusable Terraform Modules
  • Remote State Management
  • Infrastructure Version Control
  • Environment Separation (Dev, Staging, Production)

Networking

  • Custom VPC
  • Public Subnets
  • Private Subnets
  • Internet Gateway
  • NAT Gateway
  • Route Tables
  • Security Groups
  • Network ACLs

Compute

  • Amazon ECS Cluster
  • ECS Services
  • ECS Task Definitions
  • Fargate Launch Type
  • Auto Scaling

Load Balancing

  • Application Load Balancer (ALB)
  • HTTPS Support
  • Health Checks
  • Target Groups
  • Listener Rules

Security

  • IAM Roles
  • IAM Policies
  • Security Groups
  • Private Networking
  • Secrets Management
  • Least Privilege Principle

Containerization

  • Docker Containers
  • ECS Task Deployment
  • Image Versioning
  • Container Health Checks

Monitoring

  • Amazon CloudWatch Logs
  • CloudWatch Metrics
  • ECS Service Monitoring
  • Load Balancer Monitoring

Storage

  • Amazon ECR
  • Amazon S3
  • Amazon RDS (Optional)
  • Amazon ElastiCache (Optional)

🏗️ AWS Architecture

                    Internet
                        │
                Route 53 (Optional)
                        │
             Application Load Balancer
                        │
          ┌─────────────┴─────────────┐
          │                           │
     ECS Service                ECS Service
          │                           │
     ECS Task                  ECS Task
          │                           │
      Docker App               Docker App
          │
     Private Subnets
          │
     Amazon RDS
          │
     Amazon S3

🛠️ Technologies Used

Cloud

  • AWS

Infrastructure

  • Terraform
  • Terraform Modules

Containers

  • Docker
  • Amazon ECS
  • Amazon ECR

Networking

  • VPC
  • Subnets
  • NAT Gateway
  • Internet Gateway
  • Route Tables

Load Balancing

  • Application Load Balancer

Monitoring

  • CloudWatch

Security

  • IAM
  • Security Groups
  • Secrets Manager

Database

  • Amazon RDS (MySQL/PostgreSQL)

Storage

  • Amazon S3

📂 Project Structure

terraform-aws-ecommerce/
│
├── modules/
│   ├── vpc/
│   ├── ecs/
│   ├── alb/
│   ├── security-group/
│   ├── iam/
│   ├── ecr/
│   ├── rds/
│   ├── cloudwatch/
│   └── autoscaling/
│
├── environments/
│   ├── dev/
│   ├── staging/
│   └── production/
│
├── main.tf
├── providers.tf
├── backend.tf
├── variables.tf
├── outputs.tf
├── terraform.tfvars
├── versions.tf
└── README.md

📦 Terraform Modules

VPC Module

Creates:

  • VPC
  • Public Subnets
  • Private Subnets
  • NAT Gateway
  • Internet Gateway
  • Route Tables

ECS Module

Creates:

  • ECS Cluster
  • ECS Service
  • ECS Task Definition
  • Fargate Configuration

ALB Module

Creates:

  • Application Load Balancer
  • Target Groups
  • Listeners
  • Health Checks

ECR Module

Creates:

  • Elastic Container Registry
  • Repository Policies
  • Image Scanning

IAM Module

Creates:

  • ECS Task Role
  • ECS Execution Role
  • IAM Policies

CloudWatch Module

Creates:

  • Log Groups
  • Metrics
  • Alarms

Security Module

Creates:

  • ALB Security Group
  • ECS Security Group
  • Database Security Group

⚙️ Prerequisites

Before deploying ensure you have:

  • AWS Account
  • AWS CLI Configured
  • Terraform v1.6+
  • Docker
  • Git

Verify installation:

terraform -version
aws --version
docker --version

🔑 Configure AWS Credentials

aws configure

Provide:

AWS Access Key
AWS Secret Key
AWS Region
Output Format

🚀 Deployment Steps

Clone Repository

git clone https://github.com/yourusername/modules.git
cd aws-ecommerce-terraform

Initialize Terraform

terraform init

Validate

terraform validate

Format

terraform fmt

Plan Infrastructure

terraform plan

Deploy Infrastructure

terraform apply

Confirm:

yes

Terraform provisions:

  • VPC
  • ECS Cluster
  • Load Balancer
  • IAM Roles
  • Security Groups
  • CloudWatch
  • ECR
  • ECS Service

🐳 Deploy Application

Build Docker image:

docker build -t ecommerce .

Tag image:

docker tag ecommerce:latest <aws_account_id>.dkr.ecr.<region>.amazonaws.com/ecommerce

Authenticate to ECR:

aws ecr get-login-password \
| docker login \
--username AWS \
--password-stdin \
<aws_account_id>.dkr.ecr.<region>.amazonaws.com

Push image:

docker push <aws_account_id>.dkr.ecr.<region>.amazonaws.com/ecommerce

Update ECS Service:

aws ecs update-service \
--cluster ecommerce-cluster \
--service ecommerce-service \
--force-new-deployment

📈 Auto Scaling

The infrastructure supports:

  • CPU Scaling
  • Memory Scaling
  • Desired Task Count
  • Minimum Capacity
  • Maximum Capacity

Scaling policies automatically adjust the number of running containers based on application demand.


🔒 Security Best Practices

  • Private ECS Tasks
  • Public ALB Only
  • IAM Least Privilege
  • Encrypted ECR Images
  • CloudWatch Logging
  • Secrets Manager Integration
  • HTTPS Support
  • Security Group Isolation

📊 Monitoring

Amazon CloudWatch provides:

  • ECS Logs
  • Container Metrics
  • CPU Utilization
  • Memory Utilization
  • Load Balancer Metrics
  • Target Health
  • Service Events

🌍 CI/CD (Optional)

This project can be integrated with:

  • GitHub Actions
  • AWS CodePipeline
  • AWS CodeBuild
  • Jenkins

Typical deployment workflow:

Git Push
     │
GitHub Actions
     │
Docker Build
     │
Push Image to ECR
     │
Terraform Apply
     │
Update ECS Service
     │
Application Deployed

📸 Screenshots

Recommended screenshots to include:

screenshots/
├── terraform-plan.png
├── ecs-cluster.png
├── ecs-service.png
├── ecs-tasks.png
├── load-balancer.png
├── cloudwatch.png
├── vpc.png
├── ecr.png
└── ecommerce-homepage.png

📚 Learning Outcomes

This project demonstrates experience with:

  • Infrastructure as Code (Terraform)
  • Modular Terraform Design
  • AWS Networking (VPC, Subnets, NAT Gateway)
  • Container Orchestration with Amazon ECS
  • Docker Containerization
  • Load Balancing with ALB
  • IAM Security Best Practices
  • CloudWatch Monitoring
  • Auto Scaling
  • Amazon ECR
  • Infrastructure Automation
  • Cloud Architecture
  • Production-Ready AWS Deployments

🚧 Future Improvements

  • Amazon CloudFront CDN
  • AWS WAF Integration
  • AWS Shield Protection
  • Multi-AZ Database Deployment
  • Blue/Green ECS Deployments
  • Canary Releases
  • Terraform Workspaces
  • AWS Systems Manager Parameter Store
  • ECS Service Connect
  • AWS App Mesh
  • Disaster Recovery Strategy
  • Cost Optimization Dashboard

🤝 Contributing

Contributions are welcome!

  1. Fork the repository.
  2. Create a feature branch:
git checkout -b feature/new-feature
  1. Commit your changes:
git commit -m "Add new feature"
  1. Push your branch:
git push origin feature/new-feature
  1. Open a Pull Request.

📄 License

This project is licensed under the MIT License.


👨‍💻 Author

Nubari

Cloud & DevOps Engineer

Skills

  • AWS
  • Terraform
  • Docker
  • Amazon ECS
  • Amazon ECR
  • IAM
  • CloudWatch
  • VPC Networking
  • GitHub Actions
  • CI/CD

GitHub: https://github.com/pre2jasi

LinkedIn: https://linkedin.com/in/nwigboy


⭐ Acknowledgements

This project was built to demonstrate modern cloud infrastructure automation using AWS and Terraform. It showcases best practices for deploying scalable, secure, and containerized applications in a production-ready environment.

If you found this project helpful, consider giving it a ⭐ on GitHub!

About

Terraform modules for deploying infrastructure

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages