jzarzycki / WordpressTerraformAnsible

A project for the purposes of learning Terraform and Ansible with deploying a Wordpress website on DigitalOcean

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Purpose

A project for the purposes of learning Terraform and Ansible with deploying a Wordpress website on DigitalOcean.
Long ago I've created a CV/Blog website using Wordpress as a project in order to better understand the Linux OS in the process.
Now that I've learned Terraform and Ansible It only made sense to revisit this old project of mine and adapt it to use the Infrastructure as Code approach.

Usage

Create the infrastructure

Before trying to create the resources specify the required variables inside terraform/terraform.tfvars (example file provided at terraform/terraform.tfvars.example) and login to terraform cloud (remember to update values in terraform/providers.tf).
When you completed setting up you can finally run:

cd terraform
terraform init
terraform plan -no-color -out plan.txt
terraform apply plan.txt

Provision the infrastrucutre

The playbook ansible/main.yml needs to be executed in order to provision the infrastructure created by terraform.
Terraform creates the ansible inventory file ansible/inventory as part of its configuration. In order to be able to execute this playbook you need to provide values for the ansible/roles/webserver/files/.env file, example configuration can be found inside .env.example.

cd ../ansible
ansible-playbook -i inventory main.yml

The login user for ssh can be specified as such:

ansible-playbook -i inventory main.yml --extra-vars "login_user=username"

Project structure

WordpressTerraformAnsible # The project repository
├── ansible # This is where all of the Ansible code resides
│‎ ‎ ‎ └── roles
│‎ ‎ ‎ ‎ ‎ ‎ ‎ ├── common # Configuration common for all servers, like ssh config, basic securing of the server, etc
│‎ ‎ ‎ ‎ ‎ ‎ ‎ ├── docker # Configuration regarding installing and configuring docker
│‎ ‎ ‎ ‎ ‎ ‎ ‎ └── webserver # Configuration needed to provision the wordpress site on a prepared docker host
└── terraform # This is where all of the Terraform code resides
‎ ‎ ‎ ‎ └── modules
‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ └── infrastructure # Module containing implementation of infrastructure for my website.
‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ └── networking # Module containing networking related configuration for my website.

About

A project for the purposes of learning Terraform and Ansible with deploying a Wordpress website on DigitalOcean


Languages

Language:HCL 64.3%Language:Jinja 24.6%Language:Dockerfile 10.4%Language:Smarty 0.8%