Modern web applications demand scalable, secure, and maintainable infrastructure. This project demonstrates how to deploy a complete three-tier architecture on AWS using Terraform with professional CI/CD workflows.
What You'll Build
A production-ready architecture featuring:
- Web Tier: Application Load Balancer with SSL termination and Auto Scaling Groups
- Application Tier: EC2 instances running PHP web application in private subnets
- Database Tier: RDS MySQL with Multi-AZ support and encrypted storage
Key Features
π Security First
- Private subnets for application and database tiers
- AWS Secrets Manager integration for database credentials
- OIDC authentication (no long-term AWS keys)
- Security groups with least-privilege access
π GitOps Workflow
- Environment-specific branches (
env/dev
,env/staging
,env/prod
) - Automated Terraform validation and planning on PRs
- Manual approval gates for production deployments
- Safe destroy workflows with confirmation requirements
π Infrastructure as Code
- Modular Terraform design for reusability
- Remote state management with S3 and DynamoDB
- Environment-specific configurations
- Comprehensive output values
Project Structure
aws-three-tier-terraform-cicd/ βββ .github/workflows/ β βββ terraform.yaml # CI/CD pipeline βββ docs/ β βββ MANUAL_WORKFLOWS.md # Manual workflow documentation βββ infra/envs/ β βββ dev/ # Development environment config β β βββ terraform.tfvars # Dev-specific variables β βββ staging/ # Staging environment config β β βββ terraform.tfvars # Staging-specific variables β βββ prod/ # Production environment config β β βββ terraform.tfvars # Production-specific variables β βββ main.tf # Main infrastructure configuration β βββ variables.tf # Input variables β βββ locals.tf # Local values β βββ versions.tf # Terraform and provider versions βββ modules/ β βββ application/ # Application tier module β β βββ main.tf # Application module implementation β β βββ variables.tf # Application module variables β β βββ outputs.tf # Application module outputs β βββ network/ # Network tier module β βββ main.tf # Network module implementation β βββ variables.tf # Network module variables β βββ outputs.tf # Network module outputs βββ scripts/ # Helper scripts
Quick Start
- Fork the repository and configure GitHub secrets:
DB_PASSWORD # Database password AWS_ROLE_ARN # OIDC role ARN
For detailed instructions on setting up OIDC authentication and configuring the Terraform backend, see: one-click-aws-terraform-backend-gitops-oidc
- Set GitHub variables:
AWS_REGION # Target AWS region TF_BACKEND_* # Terraform backend config
- Configure environment by copying
terraform.tfvars.example
:
region = "us-west-2" env_name = "dev" certificate_arn = "arn:aws:acm:..." domain_name = "yourdomain.com"
- Deploy using GitOps:
- Create PR to environment branches β Terraform format check, validation, and plan
- Merge to
env/dev
β Deploy to development - Merge to
env/staging
β Deploy to staging - Merge to
env/prod
β Deploy to production (with manual approval)
CI/CD Pipeline Highlights
The GitHub Actions workflow provides:
- Automated Planning: Terraform plans run on every PR with results commented
- Environment Isolation: Separate workspaces for dev/staging/prod
- Security Gates: Manual approval required for production changes
- Safe Destruction: Multi-step confirmation for infrastructure teardown
Database Security
Credentials are handled through multiple security layers:
- GitHub Secrets store the master password
- AWS Secrets Manager receives the password via CI/CD
- IAM Roles allow EC2 instances to retrieve credentials
- No Hardcoding - passwords never appear in code or state
Production Considerations
- Configure DNS manually (project doesn't create Route53 records)
- Enable VPC Flow Logs for network monitoring
- Use remote state backend for team collaboration
Why This Approach Works
This architecture pattern provides:
- Scalability: Auto Scaling Groups handle traffic spikes
- Security: Multi-layered security with private networking
- Reliability: Multi-AZ deployment with load balancing
- Maintainability: Modular Terraform with GitOps workflows
- Cost Efficiency: Environment-specific scaling configurations
Ready to deploy enterprise-grade infrastructure? Check out the full repository for complete implementation details.
Top comments (0)