Deploy a WordPress Blog in AWS with Terraform (DevOps/Cloud Automation — Part I)

Iyana Garry
4 min readMar 25, 2019

As I promised in my previous tutorial, I will do a tutorial series on how to deploy live websites in AWS without using the dashboard.

I’m starting off with a software program called Terraform. Terraform performs what is called “infrastructure as code”. Terraform makes it very easy to deploy a live website, once you have everything configured correctly.

1. Install PIP for Python.
If you’re using RHEL 7 like I am, then Python 2.7 is pre-installed. However, installing PIP in RHEL 7 is not as straightforward as it is in other Linux distros. You have to install “EPEL” first, then install PIP.

Since the output for the PIP installation is quite lengthy, I only posted a snippet of its installation output.

2. Install the PIP package for AWS CLI.

After installing the package, log into the AWS dashboard, click on your name and click on “My Security Credentials”.
If you’ve used AWS before, listed below should be your credentials, the access key and secret key. If you do not have credentials, you can create them on this page.

After downloading your credentials from AWS, insert them in the file above.

3. Create an SSH key for the EC2 instance.
Terraform needs to access an SSH key, so there will be a way to access the instance once Terraform configures it.

To simplify the “ssh-keygen” command, “-t rsa” makes the algorithm used to create the key RSA, “-b 4096” the command makes the key 4096 (the largest size of an SSH key), “-N ‘’” uses no passphrase for the key (this is optional) and “-f ‘’/……/.ssh/aws_key” stores the key with the “aws_key” name and the “/……/.ssh/” file path. The directory of where you want to store the key needs to be fully typed instead of a shortcut like “~/.ssh”.

4. Download and install Terraform.

Here is where you will download Terraform. If you’re not sure if you need the 32-bit or 64-bit version, then enter “uname -m” in the shell terminal to find out which bit-version of Linux you have installed. Right-click the link to the installation file and select “Copy Link”.

Use the “wget -P” command to download the file into a specific directory and the “unzip” command to extract the file.

5. Create a Terraform file.

Use the “cat” command to view the RSA algorithm of your SSH key. You will need to copy and paste this when you create your Terraform file.

Create a file in your preferred text editor that has the extension “.tf”.
Above contains the contents of what the Terraform file should contain (the AMI, ami-0dccf86d354af8ce3, is the image that installs WordPress in the EC2 instance.)

6. Run Terraform.

After you create the Terraform file, you change the directory to where you saved the file and enter the following 3 commands:
terraform init
terraform plan
terraform apply
If you configured everything correctly, you should not see any errors.

You should see a confirmation that the EC2 instance was created.

Go back to your browser, go to the EC2 dashboard and you should see an EC2 instance that is initializing.
On the bottom right corner of my screenshot is the public IP address of my EC2 instance. On your dashboard, copy your public IP address, open a new tab and paste the public IP address in the URL bar.

View Part II of this tutorial series on WordPress blog deployment with Chef.

View Part III of this tutorial series on WordPress blog deployment with Ansible.

View Part IV of this tutorial series on WordPress blog deployment with Docker.

--

--