DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Implement Amazon S3 Cross-Region Replication With Terraform
  • Container Checkpointing in Kubernetes With a Custom API
  • Streamlining HashiCorp Cloud Platform (HCP) Deployments With Terraform
  • Automating AWS Infrastructure Testing With Terratest

Trending

  • The Smart Way to Talk to Your Database: Why Hybrid API + NL2SQL Wins
  • How to Use AWS Aurora Database for a Retail Point of Sale (POS) Transaction System
  • Operational Principles, Architecture, Benefits, and Limitations of Artificial Intelligence Large Language Models
  • How GitHub Copilot Helps You Write More Secure Code
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. How to Deploy a Full Environment for a Wordpress Site via Docker by Using Terraform

How to Deploy a Full Environment for a Wordpress Site via Docker by Using Terraform

This tutorial will get you started with developing your first infrastructure in minutes!

By 
Mohamed Latfalla user avatar
Mohamed Latfalla
·
Dec. 29, 20 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
13.9K Views

Join the DZone community and get the full member experience.

Join For Free

For many users, preparing an environment in AWS to host their website/system can be tough, especially if they’re new to cloud and what that actually means.

Also, after the preparation is done, the creation of resources might take a while, too! But what if you could do all of the following in just twenty minutes?

  • Create a VPC and all essentials for public and private subnets.
  • Create an EFS and prepare an access point to this storage option.
  • Create a launch template to replicate your configuration into multiple EC2s in different subnets.
  • Prepare your website as a Docker image to have a consistent replica of your website and its DB.

It feels impossible, right? It’s actually not — this is the beauty of IAC and Terraform. Why don’t we go deeper? 

Note: This is a POC script and it did get tested. Yes, it could be better but for the purposes of this article, it’s a good starting point.

What Will You Get?

Check the image below:

After you run the code as it is, you will get a load balancer placed in one of the public subnets, one EC2 machine that got deployed by the auto scaling launch template, and EFS.

These things are enough to run your website, at least for this use case. 

But what actually happened when I run the script is the following:

  • For VPC, the script will make a VPC, subnets (public and private), routing tables, and internet gateway.
  • For auto scaling, the script will make a launching template with what is needed to replicate the configuration into multiple instances as is required and will make sure that the minimum required instances are always meet the configuration.
  • For the load balancer, the script will prepare an endpoint associated with health check metrics.
  • For EC2, the script will launch an instance from the configuration script that got attached to the auto scaling launching template. This will install and set up Docker inside the machine and will pull the project from GitHub.
  • For EFS, the script will create all needed resources like security group, access point and access point attachment for this storage.

Is that too much? I guess not; some other systems needs a lot more. But let’s agree on one thing: Doing all of these things in 20 minutes manually is exhausting.

The Steps of Deployment

It is really easy and requires just a few clicks. Let’s get started!

Before we start, clone this link.

1. Do You Have Terraform Installed?

First things first: Check whether you have Terraform installed on your machine.


2. Do You Have Your AWS Credentials?

Because we are going to deploy these instructions to AWS, make sure one of these two options are available:

  • AWS CLI is configured, so you should only know which profile you will use if multiple configurations are placed.
  • AWS access and secret keys, because of course we need credentials to access.

Note: Check provider.tf once you decide which connection to use.

3. Some Necessary Commands

Open a terminal window and navigate into the project.

Because we are going to make a new instance, we might need to access the instance, so run these commands.

Shell
 




x


 
1
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f $PWD/id_rsa


Note: Do not change the key name unless you go to vars.ft and change it there also.

Then, run this command to get all needed modules:

Shell
 




xxxxxxxxxx
1


 
1
terraform init


4. Trigger the Script

There is only one step left, maybe two if you want to check what will happen.

To check what resources will be created, run this command:

Shell
 




xxxxxxxxxx
1


 
1
terraform plan


To bring all these planned resources to the life, run this command:

Shell
 




xxxxxxxxxx
1


 
1
terraform apply


fter all resources are alligned in the correct order, a message will ask you to approve these changes. Type yes.

And now, you can relax until the whole process is finished.

Note: After the Terraform script is done, please wait 5-10 minutes before checking the website. The infrastructure is done but the instance script is in progress. EFS mounting needs some time to be done.

To clean everything, run this command:

Shell
 




xxxxxxxxxx
1


 
1
terraform destroy


Important Points

Why EFS in this simple use case? Because I am using Docker to host the website and DB all together, and you have the auto scaling launch template, EFS should insure the consistency of your DB because the DB has a volume pointed into EFS. Any new instance will use EFS as volume.

At the end of the script execution, Terraform will return an ELB link and this will not work directly. Why? Because the initial Wordpress page is going to be /admin to finish all needed configuration. So, go to aws console -> EC2 -> your created instance and visit its public IP to finish the setup. Then all is going to be good.

Summary

I have no idea if this precess would be helpful for anyone, but since I know how to make it, so why not share it?

Creating a full basic environment in AWS has many funny turns, especially for newcomers to this platform. This script will provide a few important points to think about for now. Using Docker is really good option, using Terraform is not hard, and finally, IAC is something they need to work on.

Terraform (software) Docker (software) WordPress AWS

Opinions expressed by DZone contributors are their own.

Related

  • Implement Amazon S3 Cross-Region Replication With Terraform
  • Container Checkpointing in Kubernetes With a Custom API
  • Streamlining HashiCorp Cloud Platform (HCP) Deployments With Terraform
  • Automating AWS Infrastructure Testing With Terratest

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!