GithubHelp home page GithubHelp logo

casestudy-terraform-ansible's Introduction

Deploying Wordpress on AWS Infrastructure with Ansible & Terraform

Create an EC2 T2.micro instance
T2.micro instance of CentOS 7 in us-east-2 Availability zone.


Install pre-requisites for the setup.

  • sudo yum install epel-release -y
  • sudo yum install git python python-devel python-pip openssl -y
  • sudo yum install wget nano unzip -y

Perform a Full Update Check.

  • sudo yum update -y

Install Terraform

  • sudo curl -O https://releases.hashicorp.com/terraform/0.13.1/terraform_0.13.1_linux_amd64.zip
  • sudo unzip terraform_0.13.1_linux_amd64.zip -d /usr/local/bin
  • terraform -v

Install Ansible, Also create a backup of Original Hosts file

  • sudo yum install ansible -y
  • ansible --version
  • sudo cp /etc/ansible/hosts /etc/ansible/hosts.bkp

Install Python-pip module & upgrade the same

  • sudo yum install git python-pip
  • sudo pip install --upgrade pip

Install AWS CLI Tool for Auto-Deployment on AWS infra.

  • sudo pip install awscli --upgrade

Go to IAM Service in your AWS Account

IAM Service for us-east-2

  1. Add a User, with a name awsadmin, with an access type of Programmatic access only.
  2. Set permissions via "Attach Existing Policies Directly" Tab, with an Administrator Access
  3. Ignore the Tags & Create the User
  4. Note down the Username, Access Key ID & Secret Access Key
AWS Fields Values
User awsadmin
Access Key ID KeyID
Secret Access Key Secret Key

Configure AWS CLI Tool for Connection

  • aws configure

Enter the Access Key ID & Secret Access key when asked
Enter preferred region & format. - ie. ap-south-1 & json


Uncomment "host_key_checking = false"

  • sudo nano /etc/ansible/ansible.cfg

Install the following roles (use sudo if required)

  • ansible-galaxy install geerlingguy.php-versions geerlingguy.php geerlingguy.php-mysql geerlingguy.repo-remi

SSH Agent Setup

  • ssh-keygen # Accept Defaults
  • ssh-agent bash
  • ssh-add ~/.ssh/id_rsa
  • ssh-add -l # Verify the Status

Let us start with the actual case study
Note down the Git Hub repo for Terraform, & ansible files
GitHub Repo -: https://github.com/ketanvj/casestudy-terraform-ansible.git

Now edit the .tfvars file with aws specific values.

  • cd casestudy-terraform-ansible

dev_ami can be found in any aws instances by the name AMI ID
Change the User in public_key_path depending upon the OS.

	###### Sample terraform.tfvars file

	aws_profile       = "ProfileName"
	aws_region        = "us-east-2"
	db_instance_class = "db.t2.micro"
	dbname		  = "wordpressdb"
            deidentifier      = "wordpressdb"
	dbuser		  = "username"
	dbpassword	  = "username123"
	key_name          = "id_rsa"
	public_key_path   = "/home/centos/.ssh/id_rsa.pub"
	dev_instance_type = "t2.micro"
	dev_ami		  = "ami-0f2b4fc905b0bd1f1"
	cidrs             = {
	  public1	  = "10.1.1.0/24"
	  public2	  = "10.1.2.0/24"
	  private1	  = "10.1.3.0/24"
	  private2	  = "10.1.4.0/24"
	  rds1		  = "10.1.5.0/24"
	  rds2		  = "10.1.6.0/24"
	  rds3		  = "10.1.7.0/24"
	}

Start Initializing Terraform & Plan the setup

  • terraform init

  • terraform plan -out firstsetup

Input var.localip - 0.0.0.0/0

  • terraform apply firstsetup

If you wish to destroy the plan

  • terraform destroy

Write down the output after applying the plan

Outputs:

Wordpress Fields Values
Database_Hostname FQDN:3306
Database_Name wordpressdb
Database_Password username
Database_Username username123
Wordpress_Address http://xx.xx.xx.xx

Visit the Wordpress IP Address
Enter the Output Details in Wordpress Init Screen

casestudy-terraform-ansible's People

Contributors

ketanvj avatar debadutta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.