Terraform Introduction: What is Terraform? - Part 1

Terraform Introduction: What is Terraform? - Part 1

What is Terraform? you may ask, what is it used for? Why is it so popular? Is it just some buzzword? Well as you read on, those questions would get answered accordingly.

Before we are able to understand what Terraform is, we need to first clarify some concepts. First of all let’s define what Infrastructure-as-Code is as this is closely tied to Terraform.

"Infrastructure-as-Code (IaC) is simply the managing and provisioning of infrastructure through code instead of through manual processes."

What is this “infrastructure” as mentioned above? Well it involves: hardware, software, Operating Systems and data storage. This “infrastructure” mostly involves cloud infrastructure and a bit of on-prem infrastructure. Now we have defined IaC and Infrastructure, let’s now define Terraform.

“Terraform written in Go, is an open-source Infrastructure-as-Code tool created by Hashicorp. With Terraform one can build, change, and version infrastructure safely and efficiently.”

“Terraform is an open source tool that uses declarative language meaning, with Terraform you can specify what you want and also specify the final results, Terraform will simply do the rest.”

Terraform is mostly used to provision cloud infrastructure as it supports a lot of providers such as AWS, Azure, GCP, Alibaba Cloud, Oracle Cloud. Terraform does support on-prem infrastructure but not stand-alone infrastructure, the on-prem infrastructure must either be operating with OpenStack or VMWare as these are supported by Terraform.

With Terraform, one can perform Multi-cloud functionalities such as using the Azure Data Factory which is only available on Azure, using the Google BigQuery which can only be found at Google Cloud Platform, or using Amazon Lambda which is only available in Amazon Web Services. All the aforementioned infrastructure can be created and managed in the same way with Terraform.

Terraform Use cases

  • Terraform is cloud-agnostic and allows a single configuration to be used to manage multiple providers, and to even handle cross-cloud dependencies. This simplifies management and orchestration, helping operators build large-scale multi-cloud infrastructures.
  • Services provided by PaaS providers such as Heroku can be used in Terraform. The setup needed to host a web application on Heroku can written in just a few lines of code. Other configurations such as setting up a custom CNAME can also be done with Terraform in very little time.
  • With Terraform, one can spin up environments to test software in and once done, this environment can be disposed of. Also if the operations are satisfied with the operation of an application in the staging environment, that staging environment can be easily replicated and used as the production environment.

There are numerous use cases for Terraform and of course all cannot be discussed in the scope of this article.

Let’s take a look at some of the benefits of using Terraform:

Benefits of Using Terraform

  • With Terraform, teams can review and comment on the infrastructure. Terraform allows to have state management (storage, viewing, history, and locking), a web UI for viewing and approving Terraform runs.
  • If your desired Terraform plugin or provider so called is not available on the Terraform Registry you can simply write your own provider and integrate it with Terraform to build your infrastructure with ease.
  • With Terraform one can commit their Infrastructure-as-Code to VCS in order to promote collaboration.
  • The human readable configuration language helps you to write Infrastructure-as-Code relatively quickly.

There are numerous benefits to using Terraform and obviously all cannot be mentioned here. Now we know some of the use cases of Terraform, and the benefits of using Terraform, let’s simply take a look at how Terraform works.

The Terraform Architecture has 2 main components:

Blank diagram (2).png

  • Core: This requires two input sources in order to work, These sources include the Terraform config file and Terraform state file. The Terraform config file is analysed by the core and compared with Terraform state file which holds the current state of the infrastructure in order to decide on the point of action which is either to create, update or destroy infrastructure. The Terraform config file contains the desired state of the infrastructure.
  • Providers: Terraform relies on plugins called "providers" to interact with cloud providers, SaaS providers, and other APIs. Once the state of the infrastructure has been determined via the Terraform config file, the Core then interacts with the desired cloud provider via Terraform plugin to create, update or destroy the desired infrastructure.

Now you know how Terraform works, the benefits of using it and some of the real world use cases. For the next article, let’s use Terraform first hand, to provision an EC2 instance on AWS.