- Multi-AZ deployment across us-east-1a and us-east-1b
- Public subnets for load balancers and NAT gateways
- Private subnets for secure application and database hosting
- Internet Gateway and NAT Gateways for controlled internet access
- Proper routing tables and security groups
Network Details:
- VPC CIDR:
10.0.0.0/16 - Public Subnets:
10.0.0.0/24,10.0.1.0/24 - Private Subnets:
10.0.2.0/24,10.0.3.0/24
- PostgreSQL 16 (latest version)
- Cost-optimized configuration (db.t3.micro, single AZ for dev)
- Encrypted storage with automatic backups
- AWS Secrets Manager integration for secure credentials
- Performance Insights enabled (7-day free retention)
- CloudWatch logs integration
- VPC security groups for network isolation
Database Features:
- Engine: PostgreSQL 16
- Instance: db.t3.micro (Free Tier eligible)
- Storage: 20GB GP2 with auto-scaling up to 100GB
- Backups: 7-day retention
- Monitoring: Performance Insights + CloudWatch
- ECS Fargate Cluster: Serverless container orchestration platform
- Application Load Balancer: Public internet access with multi-AZ distribution
- Auto-scaling: CPU (70%) and Memory (80%) based scaling (1-3 tasks)
- Container Platform: Currently running nginx:latest for testing
- Security Integration: Secure database connectivity via Secrets Manager
- Monitoring: CloudWatch Container Insights and detailed logging
- Health Checks: Multi-AZ health monitoring and traffic distribution
Container Platform Features:
- Cluster:
backend-infrastructure-dev-cluster - Service:
backend-apiwith Fargate deployment - Resources: 0.25 vCPU, 512MB RAM per container (cost-optimized)
- Public URL: Live and serving traffic
- Auto-scaling: Active monitoring with CloudWatch alarms
- Logs: Streaming to
/ecs/backend-infrastructure-dev-backend-api
- Jenkins Module: CI/CD automation and container deployment pipeline
- Monitoring Module: Prometheus + Grafana observability stack
- SSL/HTTPS: Certificate management and secure endpoints# Backend Infrastructure Terraform
Infrastructure as Code for backend services using Terraform on AWS.
Modern, scalable backend infrastructure built with Terraform modules for maximum reusability across environments.
- Infrastructure: Terraform
- Containerization: Docker + ECS
- Database: PostgreSQL (RDS)
- CI/CD: Jenkins
- Monitoring: Prometheus + Grafana
- Security: AWS Secrets Manager, VPC isolation
terraform/
βββ environments/
β βββ dev/ # Development environment
β βββ staging/ # Staging environment (planned)
β βββ prod/ # Production environment (planned)
βββ modules/
βββ vpc/ # β
Network foundation
βββ rds/ # β
PostgreSQL database
βββ ecs/ # π Container platform (next)
βββ monitoring/ # π Prometheus + Grafana (planned)
βββ jenkins/ # π CI/CD pipeline (planned)
- Multi-AZ deployment across us-east-1a and us-east-1b
- Public subnets for load balancers and NAT gateways
- Private subnets for secure application and database hosting
- Internet Gateway and NAT Gateways for controlled internet access
- Proper routing tables and security groups
Network Details:
- VPC CIDR:
10.0.0.0/16 - Public Subnets:
10.0.0.0/24,10.0.1.0/24 - Private Subnets:
10.0.2.0/24,10.0.3.0/24
- PostgreSQL 16 (latest version)
- Cost-optimized configuration (db.t3.micro, single AZ for dev)
- Encrypted storage with automatic backups
- AWS Secrets Manager integration for secure credentials
- Performance Insights enabled (7-day free retention)
- CloudWatch logs integration
- VPC security groups for network isolation
Database Features:
- Engine: PostgreSQL 16
- Instance: db.t3.micro (Free Tier eligible)
- Storage: 20GB GP2 with auto-scaling up to 100GB
- Backups: 7-day retention
- Monitoring: Performance Insights + CloudWatch
- Jenkins Module: CI/CD automation and container deployment pipeline
- Monitoring Module: Prometheus + Grafana observability stack
- SSL/HTTPS: Certificate management and secure endpoints
- AWS CLI configured with appropriate permissions
- Terraform >= 1.0 installed
- Git for version control
-
Clone the repository
git clone <repository-url> cd backend-infrastructure-terraform
-
Deploy Development Environment
cd terraform/environments/dev terraform init terraform plan terraform apply -
Verify Deployment
- Check AWS Console for VPC and RDS resources
- Verify database connectivity from private subnets
- Review Secrets Manager for database credentials
Each environment (dev, staging, prod) has its own:
- Terraform state file (isolated deployments)
- Variable configurations
- Resource sizing and settings
Development Environment:
- Cost-optimized settings
- Single AZ deployment
- Minimal resource allocation
- Enhanced logging for debugging
- Network Isolation: Private subnets for sensitive resources
- Encrypted Storage: All RDS volumes encrypted at rest
- Secrets Management: Database credentials in AWS Secrets Manager
- Security Groups: Restrictive ingress/egress rules
- IAM: Least privilege access patterns
Currently Enabled:
- RDS Performance Insights (7-day retention)
- PostgreSQL query logs in CloudWatch
- Infrastructure metrics and alarms
- VPC Flow Logs for network analysis
Planned:
- Prometheus metrics collection
- Grafana dashboards
- Application-level monitoring
- Log aggregation and analysis
Development Environment:
- Free Tier eligible resources where possible
- Single AZ deployment for non-critical workloads
- Right-sized instances (t3.micro for RDS)
- Efficient storage allocation with auto-scaling
Estimated Monthly Cost (Dev):
- RDS db.t3.micro: ~$12-15
- NAT Gateways: ~$32-45
- EBS Storage: ~$2-4
- Total: ~$50-65/month
-
Deploy Your Own Application
- Replace nginx with your custom Docker image
- Configure application-specific environment variables
- Set up proper health check endpoints
-
Add SSL/HTTPS Support
- Certificate Manager integration
- HTTPS listener configuration
- Security headers and best practices
-
CI/CD Pipeline (Jenkins Module)
- Automated container builds and deployments
- Integration with container registry
- Blue/green deployment strategies
- Create feature branches for new modules
- Test in development environment first
- Document all variables and outputs
- Follow Terraform best practices
- Update README with changes
- Location:
terraform/modules/vpc/ - Purpose: Network foundation with public/private subnet architecture
- Outputs: VPC ID, subnet IDs, gateway IDs for other modules
- Location:
terraform/modules/rds/ - Purpose: Managed PostgreSQL database with security best practices
- Outputs: Database endpoint, credentials ARN, security group ID
-
State Lock Errors
terraform force-unlock <lock-id>
-
Module Not Found
terraform init
-
RDS Version Issues
- Check AWS documentation for supported PostgreSQL versions
- Update
engine_versionvariable accordingly
- Check AWS CloudWatch logs for detailed error messages
- Review Terraform state for resource dependencies
- Use
terraform planto preview changes before applying
Infrastructure Status: Production-Ready Container Platform β
Public URL: Live and serving traffic π
Next Milestone: CI/CD Pipeline (Jenkins) π―
Last Updated: July 2025