Why Terraform & What really it is?

Why Terraform & What really it is?

One of the best IAC Provision Tool

Β·

5 min read

By reading the title, you may have so many questions like what is this tool really about? What is "IAC"? Everything will be cleared in this section, I would also suggest for the beginners to practice the tool in their own systems as well, but first lets understand why it is needed at the first place?

Traditional IT Deployment

Let us take a real life traditional infrastructure IT example where an organization has to build a new application for any particular service. Refer the following flowchart as you read the steps which many current business still uses:

Business.png

1) The business comes up with their application and set the goals and objectives for a particular service the application has to meet the goals to complete for the same.

2)The Business analyst analyses it and converts it into high level technical requirements.

3) These requirements are then passed to a solution architect who designs the infrastructure for the deployment of this app like the type and number of servers needed for the app data bases or load balances etc.

4) Following the traditional practices this now has to be transferred to on-premise environment aiming to use the assets of the data centers. If any extra hardware is needed, then it has to be ordered via procurement team which will put in new hardware request with the vendors. This process usually takes few months for purchasing and delivering hardware to data centers.

5) Then comes the on-field infra team in which field engineers rack and stack the equipment, system admins perform initial configuration, storage admins assigns storage servers and backup admins configure the backup spaces. Once the systems has been setup, the application team can now deploy the application worldwide.

This deployment model is commonly used by many organizations, however it has many disadvantages like:

  • High turnover time
  • slow deployment
  • high costs
  • higher chance of human errors
  • cant scale up efficiently

Rise of 'Infrastructure as Code' Tools

Therefore many organizations uses cloud platforms to take advantages of services provided by AWS,GCP or Azure which reduces the turnover and deployment time by months of timeframe, because with cloud you don't have to manage the actual infrastructure. They also provide APIs that opens whole new world of opportunity of automation and finally built in auto scaling and elastic functions which reduces the resource wastage.

While this approach is better way than traditional deployment method, using this is not always the ideal solution in the cases of large environment infrastructure. It still may have to go to different teams with lots of process overhead which increases delivery time and human error chances are still high.

To solve this issue, different organizations by developing their own scripts and tools. Everyone was trying to automate the infrastructure provisioning to deploy environment faster by leveraging API's of various cloud platforms. These evolved to be set of tools which came out to be known as 'Infrastructure as Code' (IAC).

IAC's

The idea of these tools is that a better way to provision cloud infrastructure is to codify the entire provision process via which by just writing codes, we can provision, modify and even destroy infrastructure recourses.

The code which is used to perform and control the infra is called shell script, which is not easy to manage and requires deployment and programming skills to maintain the same. That's where tools like terraform ,ansible help with code that are easy to execute, human readable and maintained . A large shell script can be simply converted into a simple terraform config file like this:

Business (1).png

With IAC's ,we can define infrastructure resources using simple human readable high level language. There are many IAC tools which are categorized as follows.

Business (3).png

For the time being, we will discuss about Terraform as a provision tool, you can check the other types and research about them yourself as well.

Terraform - Provision Tool

Terraform allows you to automate and manage infrastructure. It can be deployed in multiple platform which monitors databases & servers, supports all the providers, and uses HCL language (Hashicorp Configuration Language). HCLis a simple declarative which is used to define infrastructure as block of human readable codes.

The main objective of Terraform is to convert the current state of infrastructure to a desired structured using required resources.

State: the deployment state of structure deployed in the terraform.

Resource: objects that terraform manage to get to desired state

Terraform Workflow:

Terraform works in these phases to convert current state into desired state. The flow is illustrated as follows:

Business (4).png

1) Writing Config File: We first write the configuration file in HCL in which we declare the infrastructure platform resources. Like in this example:

resource "local_file" "pet"{
byte1=value1
byte2=value2
}

Here, we define the resource by writing at first, then the resource name is written which is pet here. The "local_file" is name of provider of the resource which is must to define.

2) INIT:

Then, terraform initializes the project and identifies providers to be used. It will detect the resource name, type and the provider name from the config file we wrote.

3) PLAN:

Them, it drafts a plan to get to the desired state. It allocates resources and providers to be used as required and makes a plan for the execution of the program. We use this command to review the changes we make to the config file.

4) APPLY:

The changes, when made and reviewed are then applied and executes the actions proposed in a terraform plan . It is used to deploy your infrastructure.

After following these steps, your first Terraform Resource is ready !!

=========================================================

References:

kodekloud.com/courses/terraform-for-beginners

youtube.com/watch?v=YcJ9IeukJL8&t=1042s

youtube.com/watch?v=l5k1ai_GBDE&t=46s

Thank you for reading the blog.πŸ™ŒπŸ»πŸ“ƒ

πŸ”° Keep Learning !! Keep Sharing !! πŸ”°

πŸš€ Feel free to connect with me :

Β