Introduction to Terraform

What is IaC

IaC stands for Infrastructure as code. It is an approach to manage and provision resources through code instead of a manual process. For example, to create an EC2 machine, you will go to AWS UI and manually provide configuration to deploy the EC2 machine. However, you can do the same through code. The next question that comes to our mind is why I use Infrastructure as code if I can do things manually. If you already don’t know the answers, I will answer them. Before we start, assume you have to deploy 10 Virtual machines for your Dev environment, and below are the reasons you want to use IaC.

1. Reduce Human Error: When you manually create resources, there are chances of human error where some configurations may be selected wrong for some resources. However, this can avoid using code.

2. Save Time: Automating the infrastructure deployment will allow engineers to spend less time manually performing this deployment, and Engineers can spend time on other urgent things.

3. Increase Speed of deployment: Think about 10 machines being deployed by the Engineer one by one or 10 machines being deployed by code at the same time.

4. Repeatability and Consistency: Let’s say you need to deploy the Virtual machines with the same configuration in your QA environment. You can use the same code to deploy the Virtual machine in a QA environment to provide consistency between these two environments. This will save time and from errors like “Application performance is fine on Dev Virtual machines but not on your QA environment.”

Different tools are available for IaC, such as Terraform, Ansible, and AWS CloudFormation.

Why do you want to use Terraform?

We understand Infrastructure as code, but why do you want to use Terraform for it. I love to use Terraform because it allows me to deploy and manage resources to multiple Cloud Providers such as AWS, GCP, and Azure. It can also be used for the on-prem data center. 

Terraform is HashiCorp’s open-source Infrastructure as a code tool that allows us to create, manage and version your infrastructure. You can write your resources using HashiCorp Configuration Language (HCL). Need more details on language? Please review this Github page for more information. 

Terraform Work Flow

There are three main steps in Terraform Core workflow. We will discuss them more in future posts:

Write: You will write your code for infrastructure as you do in any programming language.

Plan: Review the changes that will happen in your infrastructure before applying.

Deploy: Deploy the infrastructure.

Let’s Install Terraform

Let’s install the terraform in our system to do some hand on. I use a mac book, so I will use Homebrew to install Terraform. Please find the steps that I have used:

brew tap hashicorp/tap

brew install hashicorp/tap/terraform

If you are installing on a different OS or need more details, please review HashiCorp Website.

Leave a Reply

Your email address will not be published. Required fields are marked *