Lang
Blog

Beginner’s Short Guide to Terraform

A shift to multi-cloud infrastructure!

ByPayal Mittal
July 23rd . 5 min read
Beginner's short guide to Terraform

As a developer, you know that the deployment of code is a tedious and unpleasant job. You would give it days to deploy in a perfect manner only to turn out that you messed up again. But then, we’re humans not computers and we make mistakes.

So why not use automation, instead, for faster and safer code deployment?

Infrastructure as Code (IAC) is one such approach that makes it possible to automate the deployment process. The idea behind this concept is to define, manage, and provision your infrastructure by writing it in script form.

It lets the computers do the automation and the developers do the coding, each one doing what they are best at and making the deployment process faster, easier, and more productive.

There are many tools for IaC available out there like Ansible, CloudFormation, Puppet, and TerraForm.

Each one of them is open-source, manages the infrastructure, and works with various cloud providers (except for CloudFormation). All are well documented and equally feature-rich.

However, we’re going to learn basics about Terraform like what it is, how it works, and why you should choose it over the other IaC tools-

Overview About Terraform

Created by HashiCrop, Terraform is an open-source, third-party IAC (Infrastructure as Code) automation tool for building and managing infrastructure in files in a safe and efficient manner.

It uses HashiCrop Configuration Language (HCL) to define the infrastructure in high-level configuration syntax. Also, it renders an execution plan which lets you see the changes before you apply them.

“Terraform does not abstract the underlying providers, instead allowing users to leverage the differentiating features with a consistent workflow.”

With multi-cloud automated provisioning and enhanced workflow, it secures the infrastructure with encrypted variables thus, reducing risks and increasing productivity.

terraform_1.jpg

While all the IAC tools do the same job, the slight differences between their properties make it even more difficult to choose any one of them. However, considering several points in favor of Terraform, we can help you make this choice easy for you.

Lets’ check out some of the key features of Terraform -

  • IaC (Infrastructure as Code) for productive results
  • Built-in functions and string interpolations
  • Single workflow over multiple providers
  • Execution plan to see changes before applying
  • Declarative configuration files
  • Reuse configurations
  • Platform agonistic (liberty to use any Cloud provider services)
  • Resource graph
  • Workspaces for organizing infrastructure
  • In-built state management
  • 160+ providers

How Terraform Works?

Let’s see how Terraform works -

terraform_2.jpg

  • Write Infrastructure in Code: Users define the infrastructure in code (configuration files) in a simple, human-readable HashiCrop Configuration Language (HCL). Either they write them or borrow from the public module registry.
  • Managing Configuration Files: Then, the user stores these configuration files in the version control system (VCS) repository and connect it to the Terraform workspaces.
  • Reading infrastructure configuration files: Terraform CLI reads these files and determines an execution plan for changes which is later applied and provisioned.
  • Automatic Provisioning: While making any changes in the VCS, the Terraform Cloud will execute the plan in the workspace connected to it.
  • Plan Review: The Terraform UI reviews the plan for final accuracy and then it is applied to provision the infrastructure.

Terraform Cloud

“Terraform Cloud is a free to use SaaS application that provides the best workflow for writing and building infrastructure as code with Terraform. It performs Terraform runs to provision infrastructure, either on-demand or in response to various events.”

It offers the best workflow that is responsible for remote terraform execution, version control integration, cross-workspace data sharing, remote-state management, and command-line integration.

With Terraform Cloud you can collaborate and work together as a team, which means if you make any changes your team will be able to see them. It has been designed to work with your VCS (Version Control System) provider directly.

Further features of the Terraform cloud are -

  • Easy access to shared state and secret data
  • Access controls for approving changes to infrastructure
  • Private registry for sharing Terraform modules
  • Policy controls for governing the contents of Terraform configurations
  • Share infrastructure code

In order to get started with Terraform and connect with your team, you would need to create a Terraform cloud account.

Terraform or CloudFormation?

There are a few reasons (and good ones!) developers prefer to Terraform over CloudFormation. Top of them is the specific limitation of CloudFormation to work only over AWS which rules out the options of using any other Cloud providers.

As AWS itself developed CloudFormation, it explains this limitation. But it also limits the developer to the solutions and bug fixes offered by AWS only. Also, CloudFormation code is generally redundant which makes it more vulnerable to errors and difficult to manage large-scale infrastructure.

On the other hand, Terraform is the right tool to manage infrastructure at a grand-scale. It gives you flexibility over structuring your projects at your ease. The inbuilt state management feature enables the developers to keep track of the infrastructure.

Though CloudFormation supports nested stack arrangement, it takes a lot of effort to store the whole code in a giant-sized file in a repository, whereas with Terraform you can split and save them as you want.

You don’t have to presume that Terraform is all good and wonderful, it has its own limitations like limited reusability & module support, but overall, it is worth learning and making a move with it.

For further details about Terraform, refer here.

This blog was a small effort to give brief insights about Terraform and how would it be a good choice of tool for your project requirements. I hope you find it satisfactory.

See you the next week with something new, till then- Happy Reading!!

Share:
0
+0