Terraform modules for deploying infrastructure 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.
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
- Modular Terraform Architecture
- Reusable Terraform Modules
- Remote State Management
- Infrastructure Version Control
- Environment Separation (Dev, Staging, Production)
- Custom VPC
- Public Subnets
- Private Subnets
- Internet Gateway
- NAT Gateway
- Route Tables
- Security Groups
- Network ACLs
- Amazon ECS Cluster
- ECS Services
- ECS Task Definitions
- Fargate Launch Type
- Auto Scaling
- Application Load Balancer (ALB)
- HTTPS Support
- Health Checks
- Target Groups
- Listener Rules
- IAM Roles
- IAM Policies
- Security Groups
- Private Networking
- Secrets Management
- Least Privilege Principle
- Docker Containers
- ECS Task Deployment
- Image Versioning
- Container Health Checks
- Amazon CloudWatch Logs
- CloudWatch Metrics
- ECS Service Monitoring
- Load Balancer Monitoring
- Amazon ECR
- Amazon S3
- Amazon RDS (Optional)
- Amazon ElastiCache (Optional)
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
- AWS
- Terraform
- Terraform Modules
- Docker
- Amazon ECS
- Amazon ECR
- VPC
- Subnets
- NAT Gateway
- Internet Gateway
- Route Tables
- Application Load Balancer
- CloudWatch
- IAM
- Security Groups
- Secrets Manager
- Amazon RDS (MySQL/PostgreSQL)
- Amazon S3
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
Creates:
- VPC
- Public Subnets
- Private Subnets
- NAT Gateway
- Internet Gateway
- Route Tables
Creates:
- ECS Cluster
- ECS Service
- ECS Task Definition
- Fargate Configuration
Creates:
- Application Load Balancer
- Target Groups
- Listeners
- Health Checks
Creates:
- Elastic Container Registry
- Repository Policies
- Image Scanning
Creates:
- ECS Task Role
- ECS Execution Role
- IAM Policies
Creates:
- Log Groups
- Metrics
- Alarms
Creates:
- ALB Security Group
- ECS Security Group
- Database Security Group
Before deploying ensure you have:
- AWS Account
- AWS CLI Configured
- Terraform v1.6+
- Docker
- Git
Verify installation:
terraform -version
aws --version
docker --versionaws configureProvide:
AWS Access Key
AWS Secret Key
AWS Region
Output Format
git clone https://github.com/yourusername/modules.gitcd aws-ecommerce-terraformterraform initterraform validateterraform fmtterraform planterraform applyConfirm:
yes
Terraform provisions:
- VPC
- ECS Cluster
- Load Balancer
- IAM Roles
- Security Groups
- CloudWatch
- ECR
- ECS Service
Build Docker image:
docker build -t ecommerce .Tag image:
docker tag ecommerce:latest <aws_account_id>.dkr.ecr.<region>.amazonaws.com/ecommerceAuthenticate to ECR:
aws ecr get-login-password \
| docker login \
--username AWS \
--password-stdin \
<aws_account_id>.dkr.ecr.<region>.amazonaws.comPush image:
docker push <aws_account_id>.dkr.ecr.<region>.amazonaws.com/ecommerceUpdate ECS Service:
aws ecs update-service \
--cluster ecommerce-cluster \
--service ecommerce-service \
--force-new-deploymentThe 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.
- Private ECS Tasks
- Public ALB Only
- IAM Least Privilege
- Encrypted ECR Images
- CloudWatch Logging
- Secrets Manager Integration
- HTTPS Support
- Security Group Isolation
Amazon CloudWatch provides:
- ECS Logs
- Container Metrics
- CPU Utilization
- Memory Utilization
- Load Balancer Metrics
- Target Health
- Service Events
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
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
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
- 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
Contributions are welcome!
- Fork the repository.
- Create a feature branch:
git checkout -b feature/new-feature- Commit your changes:
git commit -m "Add new feature"- Push your branch:
git push origin feature/new-feature- Open a Pull Request.
This project is licensed under the MIT License.
Nubari
Cloud & DevOps Engineer
- 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
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!