This project deploys a wordpress application and database (RDS) on an Amazon ECS cluster using Terraform. It sets up the necessary infrastructure to run containerized applications on AWS, with separate configurations for VPC and application resources.
Before you begin, ensure you have the following prerequisites:
-
Git: Make sure Git is installed on your local machine. You can download it from here.
-
Terraform: Install Terraform on your local machine by downloading it from here.
-
AWS CLI: Ensure you have AWS CLI installed and configured on your local machine by downloading it from here.
.
├── README.md
├── vpc/
│ ├── vpc.tf
│ ├── variables.tf
│ ├── outputs.tf
│ ├── provider.tf
│ └── main.tfvars
├── app/
│ ├── alb.tf
│ ├── app.tf
│ ├── cw_logs.tf
│ ├── data.tf
│ ├── iam.tf
│ ├── locals.tf
│ ├── outputs.tf
│ ├── provider.tf
│ ├── rds.tf
│ ├── route53.tf
│ ├── sg.tf
│ ├── variables.tf
│ └── main.tfvars
│ └── templates/
│ └── test-cloudinit.tpl
├── global/
└── imgs/
First, we need to deploy the VPC:
-
Navigate to the VPC directory:
cd vpc
-
Initialize Terraform:
terraform init
-
Review and modify
main.tfvars
with your desired VPC configuration. -
Plan the VPC deployment:
terraform plan -var-file=main.tfvars
-
Apply the VPC changes:
terraform apply -var-file=main.tfvars
After the VPC is set up, we can deploy the application:
-
Navigate to the app directory:
cd ../app
-
Initialize Terraform:
terraform init
-
Review and modify
main.tfvars
with your desired application configuration. -
Plan the application deployment:
terraform plan -var-file=main.tfvars
-
Apply the application changes:
terraform apply -var-file=main.tfvars
This project uses separate state files for the VPC and application configurations. State file stored in s3.
- VPC state is stored in
wp_ecs/vpc/terraform.tfstate
- Application state is stored in
wp_ecs/app/terraform.tfstate
The main configuration variables are stored in main.tfvars
files in both the vpc/
and app/
directories. Modify these in line with the sample.tfvars
to customize your deployment.
name = "wp_ecs"
cidr_block = "10.0.0.0/16"
azs = ["us-east-1a", "us-east-1b"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
public_subnets = ["10.0.8.0/24", "10.0.3.0/24"]
The configuration for the app can be found in the sample.tfvars
file.
After successful deployments, Terraform will output:
vpc_id
: The ID of the created VPCpublic_subnet_ids
: List of public subnet IDsprivate_subnet_ids
: List of private subnet IDs
alb_dns_name
: The DNS name of the Application Load Balancerecs_cluster_name
: The name of the ECS clusteralb_arn
: ARN for the ECS cluster
After a successful deployment you can access your application from your domain name, you have a fully functional wordpress application with RDS for your db.
Use as you like 🤷🏽♂️.