Terraform: what are the possibilities and why is Infrastructure-as-code so popular? 

December 23, 2021

 A popular Infrastructure as Code (IaC) tool is Terraform. Terraform is an open source declarative tool developed by HashiCorp that allows developers to describe the desired infrastructure. Terraform then creates a plan for provisioning this infrastructure and executes this plan. What are the capabilities and why is Terraform popular? And how does the tool relate to Kubernetes?



 

Infrastructure as Code

For a good understanding of the benefits of Terraform, sufficient knowledge of Infrastructure as Code (IaC) is important. IaC is an approach that enables developers to code infrastructure in a way that automates, accelerates, and makes provisioning repeatable. IaC plays a crucial role in, for example, DevOps practices such as continuous integration & continuous deployment.

IaC increases, among other things, the reliability of an infrastructure. Especially when an infrastructure is extensive, misconfigurations of resources or provisioning services in the wrong order pose a risk. IaC automates this process and always ensures correct provisioning and configuration of resources.

Speed is also an important advantage of Infrastructure as Code. By automatically configuring resources and provisioning services, the approach achieves time savings, among other things. After all, automation is always faster than manually adjusting configurations through an interface, for example.

IaC also simplifies and accelerates the provisioning of new infrastructure. This offers important advantages. For example, you can more easily conduct experiments and release experimental changes to a configuration. Without requiring much time or resources. Are you satisfied with the end result? Then you can easily roll out the changes to the production environment.

Open Source Declarative Tool

A popular IaC tool is Terraform, an open source tool developed by HashiCorp. Using this so-called declarative tool, developers can describe the desired infrastructure in a configuration language called HashiCorp Configuration Language (HCL). Terraform uses simple syntax for this and can provision infrastructure distributed across multiple cloud environments and on-premise data centers. Do changes occur in the configuration? Then Terraform can efficiently and safely reprovision the infrastructure.

The IaC tool works with modules, among other things. These modules make it possible to group resources. This group of resources is then managed as a single resource. Modules are reusable, can communicate with each other, and can be called multiple times. An overview of available modules is available here.

What makes Terraform popular?

A number of characteristics make Terraform a popular choice for developers for Infrastructure as Code. A selection of the most important characteristics:

  • Platform-agnostic: Many IaC tools are designed for use in combination with a specific cloud provider. Terraform deviates from this and is platform-agnostic. In practice, this means that the tool is suitable for use in combination with any cloud service provider.
     
  • Immutable infrastructure: Another point where Terraform differs from many other IaC tools is the ability to create so-called immutable infrastructure. Many IaC tools create mutable infrastructure instead, which can adapt to changes. Think of upgrading middleware. However, mutable infrastructure can lead to so-called configuration drift. The actual provisioning of infrastructure increasingly deviates from the original configuration. This can lead to software errors and performance problems, among other things. However, Terraform creates immutable infrastructure. With every change to the infrastructure, this requires a new configuration in which this change is incorporated. Terraform thus prevents configuration drift. Preserving previous configurations also simplifies any necessary rollbacks.
     
  • Open source: Terraform is an open source tool with a broad user base; a large number of developers contribute to the development of the IaC tool. This simplifies finding plugins and extensions for expanding Terraform's capabilities, among other things. Thanks to the broad user base, Terraform also develops rapidly and is continuously renewed.

Terraform also simplifies connecting applications with external services. So-called providers are available for this purpose. A provider includes all the code needed to authenticate users and connect to an external service. Providers are available for virtually every major cloud provider and every popular SaaS product. An overview of available providers is available here.

Terraform and Kubernetes

Terraform and Kubernetes can form a powerful combination and work together effectively. Kubernetes is an open source container orchestration platform that allows developers to orchestrate deployments on nodes in computer clusters and manage containerized workloads. Developers can use Terraform for automated provisioning of Kubernetes. And for automated deployment of applications in a cluster.