Terraform to the Rescue

Osusara Kammalawatta
3 min readJul 1, 2020

Think we are going to deploy an application on AWS. Maybe we need EC2 instances, VPCs, database services such as RDS. Also, services such as Cognito, CloudsWatch. Handling all these manually is time-consuming. If we require a large set of infrastructure, for a complex distributed application, for instance, we find it difficult to configure, bring up and down of resources. Special during the development/testing phases. Also, this manual and repetitive procedure also opens us up to human error.

Source: https://www.terraform.io/intro/index.html

Here comes Terraform

So what is Terraform? According to HashiCorp’s definition,

Terraform is the infrastructure as code offering from HashiCorp. It is a tool for building, changing and managing infrastructure in a safe, repeatable way.

We can use Terraform to describe the infrastructure using a high-level configuration syntax in a configuration language called the HashiCorp Configuration Language (HCL). It allows us to define the desired resources on almost any provider (AWS, GCP, Azure, Docker, etc) and automates the creation of those resources at the time of apply. This is called “Infrastructure as Code”.

So how the hell Infrastructure as Code works? There are two ways, ‘Push’ and ‘Pull’. The Push method is based on controlling the server. We push the configurations to the server. The Pull method involves the IaaS pulling it’s configuration from another server. Terraform uses the Push approach.

Advantages of using Terraform

  • we can manage heterogeneous services, provided by different providers in the same workflow by creating a configuration file to fit our needs.
  • Terraform has the ability to manage states. It creates a state file when a project initialization and uses this local state to create plans and make changes to the infrastructure.
  • Operators can ensure that the environment is operating correctly. High reliability. Also, prevent human errors.
  • Uses best practices.

Steps for deployment

A simple workflow for deployment is similar to these steps,

Source: https://www.terraform.io/
  • Create the configuration file including the necessary resources and authorization credentials.
  • Run terraform init command to download the provider plugins according to the configuration file.
  • Run terraform plan to verify the creation process and then terraform apply to create real resources as well as state file that compares future changes in your configuration files to what actually exists in your deployment environment.

Here’s how to install and quick start.

Hope you got something from my article. Feel free to response.

Happy Coding Folks 👽

--

--