/ TERRAFORM

Introduction to Infrastructure as Code (IaC)

The IT industry, including organizations of almost every size, is adopting cloud-based services for maintaining its application workloads. However, there is no denying that there are many operational constraints regarding the underlying infrastructure, which becomes a headache for the development teams. That is where IaC has stepped in and allowed you to operate using cloud-based services with greater independence from the associated constraints.

IaC has become very important for provisioning our infrastructure-as-code efficiently and collaboratively. However, it may not be ideal for every organization, yet the agility IaC provides makes it suitable for companies looking to speed up the pace of infrastructure provisioning and application deployment.

Now let’s talk about some of the features of IaC.

Infrastructure as Code

“Infrastructure as code” (IaC) has become an important buzzword in DevOps processes like infrastructure provisioning. It is a practice of addressing the scale and complexity of today’s IT infrastructures by allowing us to configure the desired state of infrastructure using code.

According to Microsoft, Infrastructure as Code refers to the governance of infrastructure (networks, virtual machines, load balancers, connection topology) in a descriptive model by leveraging the same versioning as the DevOps team uses for source code. It is an integral DevOps practice and is used in combination with Continuous Delivery.

Infrastructure as Code refers to the governance of infrastructure (networks, virtual machines, load balancers, connection topology) in a descriptive model by leveraging the same versioning as DevOps team uses for source code.

Some of the infrastructure management problems solved by IaC are as follows:

  • Inconsistent configuration
  • Out of date documentation
  • Configuration change tracking
  • Configuration drift detection

Configuration drift occurs typically in data centre environments due to inconsistent configuration items, were any modifications to the hardware or software are not recorded and tracked since IaC uses configuration files that maintain the desired state of infrastructure.

In simple words, we can say IaC does the following:

  1. Uses code for provisioning infrastructure: It allows you to manage operations environment and build systems the same way you do applications or other code for general release. Here, UI or CLI is not used to launch a VM or create a VPC. Instead, you describe its desired characteristics in code and tell the tool to do that.
  2. Reusability of tested Infrastructure: It allows you to reuse the already existing tested code for infrastructure management. You don’t need to provision a new infrastructure every time. All this is possible because of the state file generated by the provisioning tool.
  3. Automates operations: It allows you to use an elementary and quick-to-learn configuration syntax provided by the IaC tool. You no longer need to run hectic commands to launch and configure the system. Thus, automating most of the server-side work reduces inefficiency and errors.
  4. Team collaboration, peer reviews, version control: Since your Infrastructure is in code-based configuration, it is very much possible to maintain our code in version control like any other application codebase. It results in a well-structured and tested state file that can be collaborated by the team and, at the same time, reviewed by peers.

What is Terraform?

Terraform or Hashicorp Terraform is one of the most popular IaC tools used in the DevOps chain created by HashiCorp. According to Hashicorp:

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers and custom in-house solutions.

Terraform requires a configuration file describing the components needed to provide the desired infrastructure. Based upon that configuration file, Terraform generates an execution plan outlining the state defined in the configuration. The resultant infrastructure matches the generated plan. Once the configuration is changed, Terraform can detect the changes to the existing infra and show the changes that can apply to the infra.

Features of Terraform

The essential features of terraform are as follows:

  1. infrastructure as code: As discussed, Terraform is an IaC tool. It works on a configuration file. Therefore, the code that defines the infrastructure can be versioned, forked and rolled back, just like any other code.
  2. Execution Plan: Execution plan gets generated in the planning step of Terraform, and the command used for that is terraform plan. The plan command helps the operator check what all Terraform will execute on applying the described configuration. For example, a terraform plan might be run before committing a change to version control to create confidence that it will behave as expected. Once the operator is confident enough, he runs the terraform apply command to make the changes.
  3. Resource Graph: The Resource Graph feature of Terraform plays a vital role in building infrastructure as efficiently as possible. The resource graph allows operators to understand the dependencies among the resources described in their infrastructure. Terraform creates a resource graph of all related resources and parallelizes the creation and modification of non-dependent resources, thus being efficient.
  4. Hybrid cloud as one-tool-one-language: As terraform is not cloud-specific, it supports almost every provider such as IaaS (e.g. AWS, GCP, Microsoft Azure, OpenStack), PaaS (e.g. Heroku), or SaaS services (e.g. Terraform Enterprise, DNSimple, CloudFlare).
  5. Identical Infrastructure: Since Terraform provisions infrastructure using a piece of code, creating different environments like production, QA and staging with identical configurations becomes easy.

I suggest visiting the Terraform vs. Alternatives web page for more info about the features of Terraform and some of the distinguishing features between Terraform and other popularly known IaC tools.

Dive Deeper: Recommended Reads

Expand your knowledge of Infrastructure as Code and Terraform with our insightful collection of articles! Dive into a range of topics that will help you master the art of managing infrastructure:

Embrace the power of Terraform and Infrastructure as Code with this comprehensive collection of articles, and enhance your skills in deploying, managing, and maintaining your infrastructure.

faizan

Faizan Bashir

Principal Engineer | Architecting and building distributed applications in the Cloud | Adventurer

Read More