All languages

Terraform language

HashiCorp's infrastructure-as-code language: a declarative configuration of resources in HCL, resolved through providers into a dependency graph, diffed as a plan, and applied against a recorded state file.

Overview

Terraform is HashiCorp's infrastructure-as-code language, written in the HCL native syntax. It is declarative: a configuration names the resources that should exist, and Terraform computes the ordering, the diff, and the calls needed to reach that state.

Code

locals {
  region    = "eu-west-1"
  instances = 3
  enabled   = true
  sum       = 1 + 2 * 3                          # arithmetic operators
  label     = "env-${local.region}"              # string interpolation
  limit     = local.sum > 100 ? local.sum : 100  # conditional expression
}
Literals and operators fill locals attributes; lists and maps are consumed by index and for expressions; variable and module are the abstraction, and count / for_each are the idiom. The idiom also shows the mechanism no other slot can: a reference to aws_vpc.main is a dependency edge that Terraform walks in parallel.

Distinctive traits

  • Types are constraints, not declarations: type = string on a variable is a static type the value must satisfy, rather than the declaration of the value itself.
  • A reference is the dependency. Using aws_vpc.main.id orders the apply, so depends_on is the exception rather than the rule.
  • The plan is a first-class artifact: Terraform computes the diff before it changes anything, and a plan can be saved and applied later.
  • Execution is stateful: a state file maps configuration addresses to real objects, so the same configuration deployed twice does not create duplicates.
  • Providers are plugins: the language names resource types, and the provider binary decides which properties exist and how the call is made.
  • Tests are configuration too: terraform test (v1.6+) runs run/assert blocks against short-lived infrastructure.

Status

Active: 1.x releases are published several times a year under a stated compatibility promise. Distributed as a single Go binary; sources since 1.6 fall under the Business Source License, which converts to MPL 2.0 four years after each release.

History

The first tag, v0.1.0, is dated 28 July 2014 and shipped under the MPL 2.0. Version 1.0 in June 2021 began the 1.x compatibility promise. In August 2023 HashiCorp announced the move to the Business Source License, effective from release 1.6.0; OpenTofu forked the last MPL-licensed code and became a Linux Foundation project instead.

Sources & references