Skip to main content

Terraform

Pronunciation
TAIR-uh-form
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/terraform

In short

Terraform is an infrastructure-as-code tool: you describe cloud resources in configuration files, and one command creates or updates them to match.

What is Terraform?

Terraform was released by HashiCorp in 2014. Instead of clicking through a cloud console, you write what you want, for example two virtual machines, a database and a load balancer, in files using HCL, HashiCorp Configuration Language. Terraform reads those files and talks to the cloud's API to make reality match. Because the files live in Git, infrastructure gets reviews, history and rollbacks just like code.

Its workflow has two key steps. terraform plan compares the configuration with what exists and shows exactly what would be created, changed or destroyed. terraform apply then carries out that plan. Terraform remembers what it manages in a state file, which is usually stored remotely so a team shares one view of the infrastructure.

Terraform works with almost any platform through providers: plugins for AWS, Azure, Google Cloud, Kubernetes, Cloudflare, GitHub, databases and hundreds more. Reusable modules package common setups, such as a standard network, so teams don't rebuild them each time. The configuration is declarative: you describe the end state, and Terraform works out the order of the steps.

A common misconception is that Terraform configures what runs inside servers. It mainly creates and connects the resources themselves; installing packages and editing files on machines is the job of configuration tools such as Ansible, or of container images. In 2023 HashiCorp moved Terraform to a source-available license, and the community forked the last open-source version as OpenTofu, which works in largely the same way.

At a glance

The Terraform workflow. The configuration files describe the desired infrastructure. terraform plan compares them with the state file, which records what Terraform already manages, and shows the changes: one resource to add and one to change. terraform apply then calls the cloud provider's API to make those changes and updates the state file.main.tfdesired infrastructureterraform planwhat would change?terraform applycalls the cloud APICloudAWS, Azure, GCP…+ aws_s3_bucket.assets~ aws_instance.webPlan: 1 to add, 1 to changeterraform.tfstatewhat Terraform managescompares withrecords the result
You describe the end state; plan shows the difference before anything happens, and apply makes reality match, keeping a record in the state file.

Key takeaways

  • Terraform describes cloud infrastructure as code, in HCL files.
  • terraform plan previews changes; terraform apply makes them.
  • A state file records which real resources Terraform manages.
  • Providers connect it to AWS, Azure, Google Cloud, Kubernetes and more.
  • OpenTofu is an open-source fork that works in much the same way.

Example

Declaring a storage bucket on AWShcl
provider "aws" {
  region = "eu-central-1"
}

resource "aws_s3_bucket" "assets" {
  bucket = "example-site-assets"

  tags = {
    Environment = "production"
  }
}

# terraform plan   -> shows: 1 to add
# terraform apply  -> creates the bucket

Readers ask

Is Terraform free?

The Terraform CLI can be used free of charge, but since 2023 it is under the Business Source License, which restricts offering it as a competing product. OpenTofu is a fully open-source fork. HashiCorp also sells HCP Terraform, a managed service.

What is the difference between Terraform and Ansible?

Terraform mainly creates and manages infrastructure, such as networks, machines and databases, from a declared end state. Ansible mainly configures machines, installing software and changing settings over SSH. Many teams use both.

What is the Terraform state file?

A file in which Terraform records the real resources it manages and their settings. It lets Terraform work out what has changed, and teams usually keep it in remote storage with locking so that two people can't apply changes at once.

Often compared

See also

Sources

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings