Terraform Part - 1

Terraform Part - 1

Theory

Introduction to Terraform

Terraform, it is an Infrastructure as Code tool. As a DevOps or Cloud Engineer, we may work with multiple cloud providers, to deploy your applications, manage resources, just create and provide access to the respective team for these resources etc. But why we need to use it?

Tip!

As a DevOps Engineer, you've to learn a lot of tools like

  • Docker

  • Kubernetes

  • Jenkins (any other CI /CD)

  • Cloud

  • Ansible (Configuration Management)

  • Terraform (Infrastructre as Code) and bunch of others. To learn those all, I've a trick. Which is to question yourself as "Why"

  • Why you need to learn this. what features does it provides to improve my DevOps journey?

  • How to implement it? These three questions can really gonna give you a clear picture of that particular tool and helps you to learn it q

Well, here comes the answer for ”Why we need to use Terraform”?

Imagine yourself as a Cloud Engineer at company called Y and your manager comes to you and asks you to create resources for the development team -

`1. Three Virtual Machines (in new environment)

  1. An S3 Bucket

  2. A Database`

Not just that, you should also create few other resources for Operations team, like

  1. EC2 Instance,

  2. Virtual Network

  3. Subnet

  4. Network Gateway and bunch of other resources.

Resource - A service which service provider(GCP, Azure, AWS, etc) provides to a user. just like, S3 Bucket, Instance,etc.( not much relevant definition but, for temporary explanation purpose)

You might go to the the AWS Cloud or whatever Y organization works with and create it. But can't you smell something weird overhere?

  • It takes a lot of time and effort

  • Everything managed by the Cloud Engineer

  • Old School GUI etc.

Here comes the twist, after you have created, your manager asks you to create Ops resources on Azure.

  • We have to delete all the resources we’ve created on AWS

  • and go to Azure console

  • Re create them here.

It may take so much time to do this all the stuff, right?

Here comes the Terraform!

Terraform have most of the cloud provider’s APIs, by which we can describe our infrastructure as how we need in a file (as a code). And when we execute it using Terraform, it reflects it in our Cloud environment.

  • Instead of creating manually and using GUI console, we just define our infrastructure as Code and execute it. We end up with the same resources as we are expecting.

This file is written in HCL Language which stands for Hashicorp Configuration Language

Hashicorp is a parent organization for Terraform.

This language is applicable for all other services provided by the Hashicorp like Vagrant, Vault , Terraform Cloud etc.

What do you mean by APIs?

I’ll try to give you a picture of APIs implementation in simple terms. Let us say, you’ve went to for a Restaurant. You went to the table and order something delicious to the waiter. Waiter goes to the kitchen and gives the order to the chef. Whatever the customer (you) ordered, the chef cooks it and gives it back to the waiter, and he gives it to the person who’ve ordered it.

In the same way, API works. Here, terraform takes the input all the resources that you need to create and it reflects back into the cloud environment. Keeping it simple and precise.

How Terraform works?

So, coming back to the terraform again, we’ve learnt what Infrastructure as Code is, why to use it and how it works, right?

Now, let us learn few basic terminologies of Terraform

Providers:

It is just provides an interface API to manage the services on the Cloud environment. Terraform contains of more than 100 providers APIs and there are categorized into Verified , Private, and others, to not to miss these key relevant information or detailed articles please follow me and comment down if you won’t understand any of these.

Resource:

Just a piece of code by which we define our infrastructure. It can be verified, planned, applied or destroyed.

State File:

If you’ve knowledge about Git, it is simple to understand it. State file represents the infrastructure which you’ve created using the terraform. Basically it is like a git file, used to track the infrastructure. If you’ve committed any changes, it is going to be reflected back to the state file.

Module:

A set of configuration files grouped by together to represent a reusable and sharable set of infrastructure resources.

  • To keep is simple and not to confuse you I’ve just gave you a concise explanation of it.

  • In further articles I’ll explain these clearly and help you out there.

In upcomming article, we are going to execute basic commands of Terraform using AWS and Azure If you've not signed up for them,please finish the work till we meet again. So, thank you and please don't forgot to give feedback via comment section and also to raise a query if you've stuck anywhere else.