This project demonstrates enterprise-grade Infrastructure as Code (IaC) for deploying a production-ready Ruby application on AWS. It showcases a well-architected, modular Terraform configuration that provisions a complete cloud infrastructure with high availability, security, and scalability as core design principles.
The infrastructure is designed to support a containerized Ruby application running behind a load balancer, with a managed PostgreSQL database, all within an isolated VPC environment. The configuration follows AWS Well-Architected Framework principles and Terraform best practices to ensure maintainability, reusability, and operational excellence.
This project provisions a complete AWS infrastructure including:
- Custom VPC with public subnets and Internet Gateway
- RDS PostgreSQL database with multi-AZ support
- Auto Scaling Group with EC2 instances for the Ruby application
- Application Load Balancer for traffic distribution
- IAM roles for EC2 with ECR and S3 access
- Security Groups for network isolation
Internet → ALB → EC2 Auto Scaling Group (Ruby App) → RDS PostgreSQL
modules/vpc- VPC, subnets, security groups, and routingmodules/ec2- Launch template, ASG, ALB, and target groups
- Infrastructure split into reusable modules (
vpc,ec2) for better organization and maintainability - Each module has clear inputs/outputs and handles specific infrastructure concerns
- Promotes code reusability across different environments
- IAM Least Privilege: EC2 instances use IAM roles with read-only access to ECR and S3
- Network Isolation: Resources deployed in custom VPC with security groups controlling traffic
- Defense in Depth: Multiple security layers (VPC, Security Groups, IAM)
- Database deployed in private subnets with restricted security group rules
- Multi-AZ RDS: Database configured with Multi-AZ for automatic failover
- Auto Scaling Group: Application scales horizontally based on demand
- Load Balancing: ALB distributes traffic across multiple availability zones
- EC2 instances deployed across multiple subnets for fault tolerance
- Parameterization: All configurations externalized via variables in
terraform.tfvars - DRY Principle: Use of
for_eachloops to avoid code duplication - Data Sources: Leverages data blocks for dynamic policy generation
- Explicit Dependencies: Clear
depends_ondeclarations for proper resource ordering
- User data scripts automate EC2 configuration (Docker installation)
- Launch templates ensure consistent instance configuration
- Infrastructure provisioning is fully automated and repeatable
- RDS skip_final_snapshot is enabled for development purposes
- EC2 instances are configured with Docker via user data script