3 Tier Architecture AWS best practices: WordPress application
Wordpress on AWS - Terraform for multiple teams Project

In this project, we aimed to build a three-tier WordPress application using Terraform in a real-world environment where the DevOps team is distributed worldwide and independent contributors or groups provide each block. To make it possible we use a "remote" backend for Terraform on an S3 bucket (versioning enabled) and DynamoDB to keep the state locked for only one transaction at a time.
Steps:
Git clone the repo
Go to repo directory:
cd united-wordpress-aws
Check if aws s3 is available:
aws s3 ls
Copy content from the "template.txt" file or edit and save it as "envs/prod/prod.tfvars" file:
vim envs/prod/prod.tfvars
public_key = "~/.ssh/id_rsa.pub"
region = "your-region" # change if needed
key_name = "your_key_name" # change
domain = "yourdomainname.com" # change
zone_id = "copy-from-route53-region-ID" # change
rds_username = "admin" # change the username
rds_password = "admin123" # change the password
tags = {
Name = "Wordpress-VPC"
Team = "AWS"
}
Run script to install Terraform environment and version:
bash scripts/installation.sh
Backend Setup (DynamoDB +S3)
Run Makefile:
$ make backend
Script also will create the "backend.tf" file into VPC,ASG,RDS folders
Optionally, if your VM does not have administrator priviliages, run below commands to add your AWS credentials as environment variables.
$ export AWS_ACCESS_KEY_ID={Your AWS_ACCESS_KEY_ID}
$ export AWS_SECRET_ACCESS_KEY={Your AWS_SECRET_ACCESS_KEY}
Finaly, run
$ make build
And wait for about 20 mins
For Deleting Resources and delete the Application:
$ make destroy
TROUBLESHOOTING:
In case of error when deleteing S3 bucket use AWS console and manually empty and delete the bucket
│ Error: deleting Amazon S3 (Simple Storage) Bucket (terraform-tfstate-prod-1999999999999): BucketNotEmpty: The bucket you tried to delete is not empty. You must delete all versions in the bucket.
│ status code: 409, request id: HAMSEY42N6MG45QR, host id: h8kkpMo03yqa5U+esfQJZwgeaenEg63dqUexPPYV4b4j63JNfQjiJO8WlwyifBF5qK5OeE7ZXlU=
│
Test Database accessibility:
From EC2 instance of Web in your VPC!!! DB endpoints should be available from the final outputs
[ec2-user@ip-10-0-1-157 ~]$ mysql -h aurora-cluster-demo.cluster-ctxxweudrhd8.us-west-1.rds.amazonaws.com -u admin -p mydb
>
Enter password: ******
You should see:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 219
Server version: 8.0.23 Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Last updated