What is Terraform?

BY TOOLS.FUN  ·  MARCH 28, 2026  ·  6 min read

Terraform is an open-source Infrastructure as Code (IaC) tool that lets you define cloud resources in declarative configuration files. Instead of clicking through cloud consoles, you describe your desired infrastructure in code, and Terraform creates, modifies, and destroys resources to match that description.

Why Infrastructure as Code?

Manual infrastructure management does not scale. Clicking through AWS, Azure, or GCP consoles is slow, error-prone, and impossible to reproduce reliably. IaC treats infrastructure like application code: it is version-controlled, peer-reviewed, tested, and automated. If a server is misconfigured, you fix the code and reapply — no detective work to figure out who changed what in the console.

HCL: HashiCorp Configuration Language

Terraform uses HCL, a declarative language designed for infrastructure configuration:

resource "aws_instance" "web" { ami = "ami-0c55b159cbfafe1f0" instance_type = "t3.micro" tags = { Name = "web-server" } }

HCL is not a general-purpose programming language — it describes the desired end state, not the steps to get there. Terraform figures out the execution plan. Format your Terraform variable files (tfvars) with the JSON Formatter when using JSON-format variable definitions.

Key point: Terraform is declarative — you describe what you want, not how to build it. If a resource already exists and matches the configuration, Terraform does nothing. If it differs, Terraform computes the minimal set of changes needed.

Providers

Providers are plugins that let Terraform manage specific platforms: AWS, Azure, GCP, Kubernetes, Cloudflare, Datadog, GitHub, and hundreds more. Each provider defines resource types and data sources. You declare which providers you need, and Terraform downloads them automatically. The provider ecosystem is what makes Terraform truly multi-cloud.

The Plan/Apply Workflow

The core Terraform workflow has three steps:

terraform init — downloads providers and initialises the backend.

terraform plan — compares the desired state (your code) with the current state and shows what will change. No resources are modified.

terraform apply — executes the plan, creating, updating, or destroying resources.

Always review the plan before applying. In CI/CD pipelines, plan runs on pull requests and apply runs after merge. Use the Code Diff tool to compare Terraform plan outputs between runs.

State Management

Terraform tracks the resources it manages in a state file (terraform.tfstate). This file maps your configuration to real-world resource IDs. Without it, Terraform cannot know what it has already created. Store state remotely (S3 + DynamoDB, Terraform Cloud, or GCS) with locking to prevent concurrent modifications. Never commit state files to version control — they may contain secrets.

Key point: State is the single source of truth for Terraform. Losing or corrupting it requires manual reconciliation with cloud resources. Use remote state with locking from day one — local state files are for learning only.

Modules

Modules are reusable Terraform configurations — the equivalent of functions in programming. A module encapsulates a set of resources (e.g., a VPC with subnets, route tables, and NAT gateways) and exposes input variables and output values. The Terraform Registry hosts thousands of community modules. Use modules to enforce standards and reduce duplication across environments.

Terraform vs Alternatives

CloudFormation is AWS-only. Pulumi uses general-purpose languages (TypeScript, Python) instead of HCL. CDK generates CloudFormation from code. Terraform's strengths are multi-cloud support, a massive provider ecosystem, and a large community. Its weaknesses include state management complexity and HCL's limited expressiveness for complex logic. Convert configuration between formats using the JSON to YAML Converter when working with Terraform's JSON configuration syntax.

Best Practices

Use remote state with locking. Organise code by environment (dev/staging/prod) using workspaces or directory structure. Pin provider versions. Use modules for reusable patterns. Run terraform fmt for consistent formatting. Enable plan output in CI/CD for code review. Use terraform import to bring existing resources under management gradually.

Key point: Start small — manage one environment or one service with Terraform before trying to manage everything. Terraform is powerful but has a learning curve, and mistakes can destroy production resources. The plan step is your safety net — always review it carefully.
← Back