Skip to content
IT glossary
DevOps and cloudUpdated December 3, 2026

Terraform

Terraform is a tool for managing infrastructure from configuration files. You describe the resources you want, such as cloud networks or databases, and Terraform works out what to create, change, or remove.

Also known as: OpenTofu, HCL

What Terraform does

Say your application needs a private network, a load balancer, and two virtual machines. Instead of setting them up by clicking through a cloud console, you describe them in .tf files. Your team can review those files in a pull request and reuse the configuration for another environment. This is infrastructure as code (IaC).

Terraform is declarative: you say what should exist, and Terraform determines the operations needed to get there. Most .tf files are written in HCL (HashiCorp Configuration Language). HCL is a configuration language, not another name for Terraform. OpenTofu is a separate open-source fork of Terraform; check version, provider, and state compatibility before switching between the two.

How a Terraform run works

A provider is a plugin that defines resource types and talks to the relevant API. For example, the AWS provider can look up, create, and manage an S3 bucket. Terraform keeps a state record that maps configuration addresses to real objects and stores known attributes. State lets Terraform tell which existing bucket belongs to which resource declaration; a matching name alone isn't enough.

  • terraform init prepares the working directory by initializing the state backend and installing required providers and modules.
  • terraform plan reads the current attributes of tracked objects by default and compares them with the configuration to propose changes. It doesn't make those changes.
  • terraform apply carries out the changes and updates state. Terraform orders operations using dependencies, not the order blocks appear in a file. For example, a resource that references a subnet's ID depends on that subnet.

Example: an S3 bucket

resource "aws_s3_bucket" "logs" {
  bucket = "example-app-logs-123456"
}

The resource address is aws_s3_bucket.logs; the bucket argument sets the name in AWS. With the AWS provider configured and credentials that have the required permissions, the plan should show a new bucket if nothing is tracked at that address. Applying it requires an available bucket name. If you're taking over a bucket that already exists, import it to bind the existing object to the address, then review the plan for any differences before applying.

Where teams use it and what to watch for

Teams often use reusable Terraform modules to provision similar infrastructure in staging and production while keeping their state separate. A CI/CD pipeline can generate a plan for review before applying changes. For shared infrastructure, use a remote state backend with restricted access and locking support. Locking prevents concurrent Terraform operations from writing to the same state; access controls matter because state can contain secrets.

Terraform doesn't watch infrastructure continuously. A change made directly in the cloud console can cause drift, where the real resource no longer matches the configuration. The next plan may propose undoing that change. Also check for replacements: a small configuration edit can require deleting a resource and creating another. Reverting a Git commit won't recover data from a deleted database.

How it comes up in interviews

A common question is whether Terraform and Ansible solve the same problem. Explain the usual division of work: Terraform provisions infrastructure such as networks and virtual machines, while Ansible often configures software and services inside those machines. There is overlap, so give a concrete example rather than drawing an absolute line: Terraform creates a VM and its network, then Ansible installs and configures the web server.