Terraform for Highly Available WordPress

Terraform for Highly Available WordPress

Someone complained about the lack of technical details hereso I’m going to dig into Terraform a bit.

Network

I’ve been using a basic template for most of my VPC configurations.

This guy just sets up the VPC, route table (very basic here), and subnets.
Terraform VPC

SubnetsTerraform

Just a simple VPC with subnets in zone A and zone B for all resources.

EFS

EFS I configure with a mount in each zone as well.
EFS Terraform code

I manually built the AMI I ended up using and to do that I attached this EFS volume. I then moved wordpress content I needed to be shared and setup the docker instances. Once I did this, I had all the wordpress data I needed on EFS ready to attach to any instance. I configured docker compose to utilize the wordpress image and would sync what was necessary. I later will need to backup this data off of EFS but that’s for another time.

ALB/ELB

Using an ALB to route to both docker hosts (hosts configured as described here).

alb in terraform

I now believe I can setup routing through the ALB using host rules and additional target groups, this will allow me to get rid of HAProxy on the docker host.

Auto-Scale Group

The auto-scale group launches t2.small instances of the custom ami I built and utilizes a user-data file to do some minor configurations and restart servers. I don’t have any scaling policies setup yet and am just using this as a HA instance.

auto-scale group

Killing instances

I’ve killed a few instances and WordPress keeps running. I initially tested with a minimum of 2 instances and experienced no down-time when one instance was killed. Since this is my personal site and I have no uptime requirements I lowered this to a minimum of 1 instance. So it’s not really HA, but close enough for me. If an instance is killed/dies I’ll get about 5 minutes of downtime which I find acceptable.

More to come

I’m going to start tweaking and experimenting more with this instance, visit my site often to stay up to date.

One thought on “Terraform for Highly Available WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *