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
Terraform Instructions
- 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
- Download a popular IDE. I prefer VSCODE and ATOM
- After installation create a directory / folder on your desktop and inside it, create three files with .tf as extension for Terraform
- Main.tf
- Variables.tf
- Output.tf
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
Syntax is:
variable "variable_name" {
description = ""
default= ""
}
Chef Instructions
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)
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.
- 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
- 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 + `)
- 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
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
Kindly use comment section below if you face any issues in executing and understanding these instructions or for any questions regarding Terraform and Chef.