STAY HOME! STAY SaVE

Techies Net
  • Home
  • Software
    • Dotiny
  • Web & App Development
    • Website Builder
    • App Development
  • Request Review
  • Advertise
  • Mobile App
  • Contact Us

How to Integrate Terraform with Chef (WordPress Installation)

11/1/2019

4 Comments

 
You might be thinking is there is need for Terraform and Chef integration together? I say Yes, for the usecase where you want to develop an IAAC (Infrastructure as a Code) with power of Chef Orchestration in one go. i.e. you want Terraform to launch your EC2 instance with some AMI and later Chef do the installation of your custom application, configures it and sent you an email at the end stating "Hurray! your application is ready to use"
Terraform + Chef
For persons who are new to these DevOps tools, let me brief them with slight introduction.
What is Terraform?
Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions. Terraform is one of the tools you should be using in your DevOps toolchain. Configuration files describe to Terraform the components needed to run a single application or your entire datacenter. It maintains a state file to know the current status of infrastructure resources created by it. (Via: Terraform.io)

What is Chef?
Chef is an automation tool that provides a way to define infrastructure as code. Infrastructure as code (IAC) simply means that managing infrastructure by writing code (Automating infrastructure) rather than using manual processes. It can also be termed as programmable infrastructure. Chef uses a pure-Ruby, domain-specific language (DSL) for writing system configurations. Chef is closely competing with Puppet in terms of Configuration Management DevOps tools. (Via: Edureka.co)

Steps to integrate Terraform with Chef and Run Together

Let us take an example of hosting a WordPress website on AWS EC2. To do so,  we will using Terraform for building and managing the infrastructure and Chef for installation of WordPress application, PHP, MySQL, etc.

Terraform Instructions

  1. First begin with download of Terraform as per your Workstation OS. Will download Mac OS version of Terraform. Download it from here - https://www.terraform.io/downloads.html
  2. Download a popular IDE. I prefer VSCODE and ATOM
  3. After installation create a directory / folder on your desktop and inside it, create three files with .tf as extension for Terraform
    1. Main.tf
    2. Variables.tf
    3. Output.tf
Terraform files (Main.tf, Output.tf, Variables.tf)
File 1: ​Main.tf (Desktop/Terraform/main.tf)

In main.tf, we have initiated provider AWS with its Access credentials, declared EC2 resource with Chef provisioner and declared security group.
You need to replace the following items inside this file:
​1. Access Credentials
2. Chef Server Organisation Pem file
3. Ec2 machine keypair pem file
​File 2: ​variables.tf (Desktop/Terraform/variables.tf)

In variables.tf, mostly variables will be declared which we call inside main.tf. You can add your own custom variables as well. 
Syntax is:
variable "variable_name" {
     description = ""
     default= ""
}
​File 3: ​output.tf (Desktop/Terraform/output.tf)

In output.tf, generally we want to output values on successful Terraform execution. Usually IP of server, DNS, SG, etc.

Chef Instructions

To begin with Chef, there are some pre-requistics that you need to furnish before execution of Chef. They are:
1. Create account in Self-Hosted or Managed Chef Server - ​https://manage.chef.io/login
2. Create organisation in Chef Server
3. Download Starter Kit
4. Download ChefDK - 
https://downloads.chef.io/chefdk/ and install it on your machine

1. Create account in Chef Server & Create Organisation

  • ​Signup for the account and login inside Chef server
  • Create organisation in Chef Server (Administration > Organisation > Create Organisation)
Create organization in Chef Server

2. Download Starter Kit & Install Chef DK

  • To download starter kit, go to Administration -> Organisation -> Click on your recently created Organisation -> Setting icon -> Download Starter kit.
Picture
  • Extract starter.zip and copy contents inside /Downloads/starter/chef-repo/ to your folder /Desktop/Terraform/Chef
  • Now your directory should be like below screenshot.
  • Later download ChefDK - downloads.chef.io/chefdk/ and install it on your computer
Picture
  • Now delete the starter cookbook and download wordpress from Chef Supermarket - https://supermarket.chef.io/cookbooks/wordpress
  • Use the following commands to download wordpress and its dependencies cookbooks and upload them to Chef Server.
  • Open Visual Studio -> File -> Open -> Navigate to Desktop/ Terraform -> Click Open
  • Then open terminal inside (Menu -> Terminal or CTRL + `)
Terminal Commands to Setup Chef

Visual Studio Code - Running Chef
  • If uploading to chef server is successful,  you should be able to see Cookbooks inside Managed Chef Server. Go to Manage.chef.io -> Login -> Policy -> Cookbooks
Chef Server with Cookbooks

Running Terraform and Executing Cookbook WordPress Inside It

  • Move your directory back to main root folder /Desktop/Terraform
  • Before that, Go to Main.tf -> Chef Provisioner and change details of your Chef server 
    • EC2 Keypair pem file
    • Chef Server URL
    • Chef Server .pem key -> Available in your Desktop/Terraform/Chef/.chef/yourfile.pem
  • Now run the following commands to run Terraform and later Chef Provisioner will install chef
​Terraform Commands to run inside VSCode

Wordpress Hello World
I hope, you like the tutorial. We tried our level best to put things together with screenshots.
​Kindly use comment section below if you face any issues in executing and understanding these instructions or for any questions regarding Terraform and Chef.

Author : Shoeb Ahmad Fareed

Shoeb Ahmad Fareed
Designation: Founder & CEO
Bio: A Technology Leninist who believes that success can only be achieved if one has a practical implementation knowledge. He is a Computer Science Engineer, a professional blogger and a debugger.

Techies Net - Technology Blog
Share This Post




4 Comments
Baju Anak Branded link
18/1/2019 02:58:19 pm

Thank you so much you already give this information for our. I'm so happy and enjoyed for this.

Reply
Hill climb racing link
9/8/2019 11:55:34 am

The most thrilling landscape, wildlife, and grayscale photography at very affordable prices at Shannonspointofview. Checkout a glimpse of the best work we have done so far.

Reply
dumami link
16/6/2022 12:23:36 pm

Thank you for taking the time to talk about it; I have strong feelings about it and want to learn more about it. Would you mind adding information to your blog post? It will really benefit all of us, <a href="https://bubbleshootergame.online/">bubble shooter</a>

Reply
Bigcommerce SEO Services link
9/12/2022 03:22:06 pm

Thank for this guidance..

Reply



Leave a Reply.

    Get Updates Via Email

    Enter Email Address

    7:00 AM - 9:00 AM IST

    Blog Sponsors


    Category

    All
    Apps
    Camera
    Cars Bikes
    Cloud
    Computers
    Earn Easy Money
    Education
    Entertainment
    Fun
    Games
    How To
    Innovation
    Mobile
    News Internet
    News Internet47f3cea023
    News Internet769585a1ca
    News Of Internet
    News Of Internet
    SmartBand
    Smartwatch
    Software
    Technology

    Archives

    January 2019
    July 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    December 2017
    August 2017
    July 2017
    June 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015
    September 2015
    August 2015
    July 2015
    June 2015
    May 2015
    April 2015
    March 2015
    February 2015
    January 2015
    December 2014
    November 2014
    October 2014
    September 2014
    August 2014
    July 2014
    June 2014
    May 2014
    April 2014
    March 2014
    February 2014
    January 2014
    December 2013
    November 2013
    October 2013
    September 2013
    August 2013
    July 2013
    June 2013
    May 2013
    April 2013
    March 2013
    February 2013
    January 2013
    December 2012
    November 2012
    October 2012
    September 2012
    August 2012
    July 2012
    June 2012
    May 2012
    April 2012
    March 2012
    February 2012
    January 2012
    December 2011
    November 2011
    October 2011
    September 2011
    August 2011
    July 2011
    June 2011
    May 2011
    April 2011
    March 2011
    February 2011

Contact Us

Email: [email protected]

Stay Connected

Download Our Mobile App 

Techies Net Mobile App
Copyright © 2011-2019 Techies Net | Our Logo | Advertise | Careers | Donate Us | All Right Reserved.
All the trademarks are sole property of their respective owners.

Powered By HostChef.In

  • Home
  • Software
    • Dotiny
  • Web & App Development
    • Website Builder
    • App Development
  • Request Review
  • Advertise
  • Mobile App
  • Contact Us