FRGet In Touch
← Tech stack

Terraform

An infrastructure-as-code tool: you describe servers, networks, databases and clusters in files, and Terraform creates them for you.

Type
Infrastructure as code tool
Created by
HashiCorp, now part of IBM (Business Source License)
Language
HCL, a readable configuration language
In my stack
Cloud infrastructure, versioned and reviewed like code

What it is

Instead of clicking through a cloud console, you write what the infrastructure should be: a resource group, a Kubernetes cluster, a database, DNS records. terraform plan compares those files with what exists and shows exactly what will be created, changed or destroyed. terraform apply makes it happen.

Terraform works with almost every provider through plugins, including Azure, AWS, Google Cloud, OVHcloud, Cloudflare and GitHub, so one tool describes the whole setup. It keeps a state file that records what it manages. In 2023 HashiCorp moved Terraform to a source-available license, and the community created OpenTofu, an open-source fork that uses the same language.

Why I use it

Environments you can rebuild. Staging and production come from the same files, so they don’t drift apart, and a lost environment can be recreated.

Changes are reviewed before they happen. A plan is read in a merge request like any code change, and nobody is surprised by what gets deleted.

A history of every change. Git shows who changed the infrastructure, when and why, which auditors appreciate as much as developers do.

Fewer manual mistakes. No forgotten checkbox in a console, and security settings are applied the same way every time.

Where I use it

I use Terraform to describe cloud infrastructure as code: resource groups, networks, Kubernetes clusters, databases, DNS records and access rights, on Azure or with other providers such as OVH. Changes go through the same review and CI/CD process as the application.

Best use cases

  • Cloud setups with several environments: development, staging and production kept identical.
  • Infrastructure that must be auditable, with every change reviewed and recorded.
  • Multi-provider setups, such as Azure for the cluster, Cloudflare for DNS and GitHub for repositories.
  • Handing a project over: the files document exactly what exists and how it is configured.

When I’d use something else

For a single small server, Terraform can be more ceremony than value, and a short documented setup is enough. To configure software inside servers, a tool like Ansible fits better, and inside Kubernetes, manifests or Helm charts usually manage the applications. Teams that want an open-source license can use OpenTofu with the same files.

A small example

A resource group and an AKS cluster on Azure. Running terraform plan shows what will be created before anything is touched.

resource "azurerm_resource_group" "main" {
  name     = "rg-app-prod"
  location = "westeurope"
}

resource "azurerm_kubernetes_cluster" "main" {
  name                = "aks-app-prod"
  location            = azurerm_resource_group.main.location
  resource_group_name = azurerm_resource_group.main.name
  dns_prefix          = "app-prod"

  default_node_pool {
    name       = "system"
    node_count = 2
    vm_size    = "Standard_D2s_v5"
  }

  identity {
    type = "SystemAssigned"
  }
}

Often used with

Need cloud infrastructure you can rebuild, review and audit?

Get in touch and tell me about your project.