Production-ready WordPress deployment on AWS using Terraform modules
This repository provides reusable Terraform modules for deploying scalable WordPress infrastructure on AWS. The modules follow infrastructure-as-code best practices and security standards suitable for production environments.
- High Availability: Auto Scaling Groups with Multi-AZ RDS deployment
- Security: Encrypted storage, IAM roles, restricted network access
- Scalability: Application Load Balancer with auto-scaling EC2 instances
- Monitoring: CloudWatch integration with health checks and alerting
- Modular Design: Reusable components for multiple environments
┌─────────────────────────────────────────────────────────┐
│ VPC │
├─────────────────┬───────────────────┬───────────────────┤
│ Public Subnet │ Public Subnet │ Private Subnet │
│ │ │ │
│ ┌─────────┐ │ ┌─────────────┐ │ ┌─────────────┐ │
│ │ ALB │ │ │ Auto Scaling │ │ │ RDS MySQL │ │
│ │ │ │ │ Group │ │ │ Multi-AZ │ │
│ └─────────┘ │ └─────────────┘ │ └─────────────┘ │
└─────────────────┴───────────────────┴───────────────────┘
Component | Purpose | Features |
---|---|---|
VPC Module | Network isolation | Public/private subnets, NAT Gateway, Internet Gateway |
Security Module | Access control | Security groups, IAM roles, SSH restrictions |
Database Module | Managed MySQL | RDS Multi-AZ, automated backups, encryption |
Compute Module | WordPress hosting | Auto Scaling Groups, health checks, load balancing |
- AWS Account with appropriate IAM permissions
- Terraform >= 1.5.0
- AWS CLI configured (
aws configure
) - SSH key pair for EC2 access
git clone https://github.com/your-org/terraform-wordpress-aws.git
cd terraform-wordpress-aws/environments/dev
cp terraform.tfvars.example terraform.tfvars
Edit terraform.tfvars
with your specific values:
# terraform.tfvars
project_name = "my-wordpress"
environment = "dev"
allowed_ssh_cidrs = ["203.0.113.0/32"] # Replace with your IP
public_key = "ssh-ed25519 AAAAC3..." # Your SSH public key
db_password = "your-secure-password"
wp_admin_password = "your-wordpress-password"
# Optional: Customize instance types and capacity
instance_type = "t3.medium"
min_size = 1
max_size = 3
desired_capacity = 2
terraform init
terraform plan
terraform apply
echo "WordPress URL: $(terraform output -raw load_balancer_url)"
For production environments, use AWS Secrets Manager:
data "aws_secretsmanager_secret_version" "db_credentials" {
secret_id = "prod/wordpress/db_password"
}
locals {
db_password = data.aws_secretsmanager_secret_version.db_credentials.secret_string
}
- Restrict SSH access to specific IP ranges or bastion hosts
- Use private subnets for database and application servers
- Enable VPC Flow Logs for network monitoring
The infrastructure includes CloudWatch alarms for:
- High CPU utilization (>80%)
- Database connection limits (>90%)
- Application Load Balancer health checks
- Auto Scaling Group health status
The project supports multiple environments using separate Terraform workspaces:
environments/
├── dev/
│ ├── main.tf
│ ├── variables.tf
│ └── terraform.tfvars.example
├── staging/
│ ├── main.tf
│ ├── variables.tf
│ └── terraform.tfvars.example
└── prod/
├── main.tf
├── variables.tf
└── terraform.tfvars.example
- Development/Staging: Rapid environment provisioning for testing
- Production Deployments: Scalable WordPress hosting with high availability
- Client Projects: Template for consistent WordPress deployments
- CI/CD Integration: Automated infrastructure deployment in pipelines
- Disaster Recovery: Infrastructure-as-code enables quick rebuilds
- Use
terraform plan
with cost estimation tools for budget planning - Configure Auto Scaling policies based on actual usage patterns
- Consider using Spot Instances for non-production environments
- Implement automated shutdown schedules for development environments
# Update Terraform modules
terraform get -update
# Plan infrastructure changes
terraform plan -out=plan.out
# Apply planned changes
terraform apply plan.out
# Clean up resources
terraform destroy
- Fork the repository
- Create a feature branch (
git checkout -b feature/improvement
) - Commit your changes (
git commit -am 'Add new feature'
) - Push to the branch (
git push origin feature/improvement
) - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For questions or issues:
- Create an issue in the GitHub repository
- Review the Terraform AWS Provider documentation
- Check WordPress deployment best practices