A complete Terraform configuration for deploying MediaWiki on AWS using ECS Fargate, RDS MySQL, and Application Load Balancer.
This deployment creates:
- VPC with public/private subnets across multiple AZs
- ECS Fargate cluster running MediaWiki containers
- RDS MySQL database in private subnets
- Application Load Balancer for high availability
- EFS for persistent file storage
- S3 for configuration and media storage
- CloudWatch logging and monitoring
- GuardDuty security monitoring (optional)
- AWS CLI configured with appropriate credentials
- Terraform
- Docker Hub account (if using custom MediaWiki image)
-
Clone and navigate to the project:
git clone <your-repo-url> cd mediawiki-aws/mediawiki-aws
-
Create your configuration file:
cp terraform.tfvars.example terraform.tfvars
-
Edit
terraform.tfvarswith your values:db_username = "admin" db_password = "your-secure-password" db_name = "mediawiki"
-
Deploy the infrastructure:
terraform init terraform plan terraform apply
-
Get the MediaWiki URL:
terraform output mediawiki_url
-
Complete MediaWiki setup:
- Visit the URL from step 5
- Follow the MediaWiki installation wizard
- Download the
LocalSettings.phpfile when prompted
-
Upload configuration to S3:
aws s3 cp LocalSettings.php s3://$(terraform output -raw s3_bucket_name)/LocalSettings.php -
Restart the ECS service:
aws ecs update-service --cluster $(terraform output -raw ecs_cluster_name) \ --service $(terraform output -raw ecs_service_name) --force-new-deployment
| Variable | Description | Default | Required |
|---|---|---|---|
aws_region |
AWS region for deployment | us-west-1 |
No |
project_name |
Name prefix for all resources | mediawiki |
No |
environment |
Environment name (dev/staging/prod) | dev |
No |
db_username |
Database admin username | - | Yes |
db_password |
Database admin password | - | Yes |
db_name |
Database name | mediawiki |
No |
mediawiki_image |
Docker image for MediaWiki | thejolman/mediawiki-aws:latest |
No |
config_file |
MediaWiki config file name | LocalSettings.php |
No |
logo_file |
MediaWiki logo file name | wiki.png |
No |
availability_zone_count |
Number of AZs to use | 2 |
No |
enable_deletion_protection |
Enable RDS deletion protection | false |
No |
skip_final_snapshot |
Skip snapshot creation when deleting DB | true |
No |
enable_guardduty |
Enable GuardDuty monitoring | false |
No |
# Required variables
db_username = "wikiuser"
db_password = "MySecurePassword123!"
# Optional customizations
project_name = "my-wiki"
environment = "production"
aws_region = "us-east-1"
availability_zone_count = 3
enable_deletion_protection = true
skip_final_snapshot = false
enable_guardduty = trueaws s3 cp your-logo.png s3://$(terraform output -raw s3_bucket_name)/wiki.pngaws logs describe-log-groups --log-group-name-prefix "/ecs/mediawiki"The RDS instance is in private subnets. To access:
- Use AWS Systems Manager Session Manager
- Create a bastion host in public subnet
- Use RDS Proxy (not included in this configuration)
- VPC with private subnets for database
- Security groups with minimal required access
- ECS tasks run in private subnets
- ALB provides public access point
- Optional GuardDuty threat detection
- IAM roles with least privilege access
- CloudWatch logs for ECS tasks
- RDS performance insights
- ALB access logs
- Optional GuardDuty findings
To destroy all resources:
terraform destroyWarning: This will permanently delete all data including the database and S3 bucket contents.
# View ECS service status
aws ecs describe-services --cluster $(terraform output -raw ecs_cluster_name) \
--services $(terraform output -raw ecs_service_name)
# Check ALB target health
aws elbv2 describe-target-health --target-group-arn $(terraform output -raw target_group_arn)
# View recent logs
aws logs tail /ecs/mediawiki-app --since 1h