OpenTofu language
The MPL-licensed fork of Terraform, governed by the Linux Foundation: the same HCL configuration and plan/apply cycle, plus client-side state and plan encryption and its own provider registry.
Overview
OpenTofu is the community fork of Terraform, created
after HashiCorp moved Terraform to the Business Source License in August 2023.
It keeps the language and the .tf file format, and is described by its
maintainers as a drop-in replacement.
Code
locals {
region = "eu-west-1"
instances = 3
enabled = true
prefix = "env-${local.region}" # interpolation
big = local.instances > 2 ? "yes" : "no" # conditional
}
locals {
zones = ["eu-west-1a", "eu-west-1b"]
tags = { team = "infra" }
first = local.zones[0]
names = [for z in local.zones : upper(z)]
by_az = { for i, z in local.zones : z => i }
}
variable "size" {
type = string
}
resource "aws_instance" "web" {
instance_type = var.size
}
module "net" {
source = "./modules/net"
cidr = aws_vpc.main.cidr_block
}
terraform {
encryption {
key_provider "pbkdf2" "main" { passphrase = var.passphrase }
method "aes_gcm" "aes" { keys = key_provider.pbkdf2.main }
state { method = method.aes_gcm.aes }
}
}
// in a .tftest.hcl / .tofutest.hcl file:
run "check_type" {
assert {
condition = aws_instance.web.instance_type == "t3.micro"
error_message = "unexpected instance type"
}
}
for expressions
and variable/resource/module — and the fourth is what it added:
encryption
of state and plan files, plus run/assert tests
both forks read.Distinctive traits
- Configuration compatibility is the contract: existing
.tffiles and providers work unchanged, and the migration guide is a rename and a state-file check rather than a rewrite. - A reference to another resource's attribute is a dependency edge, and the resulting graph is walked in parallel.
- State and plan encryption
is client-side and configured in the language: a
key_provider, amethod, and per-artifactstate/planblocks with afallbackfor rollover. - Keys come from PBKDF2 passphrases, AWS/GCP/Azure KMS, OpenBao, or an external program, so the same mechanism spans self-managed and cloud-held keys.
tofu testreads both.tftest.hcland.tofutest.hcl, so one test suite can target Terraform and OpenTofu.- The registry is a git repository of providers and modules, published by pull request — and, being a Linux Foundation project, the manifesto stands in for a vendor's licence promise.
Status
Active: stable releases carry a published
1.x compatibility promise
for the language. Distributed as a binary named tofu; source is under the
MPL 2.0, with the
original Terraform copyright retained.
History
HashiCorp announced the licence change on 10 August 2023. When no response to the community's request to revert arrived by 25 August, the fork was published as OpenTF; it was renamed OpenTofu and adopted by the Linux Foundation before its first stable release. OpenTofu 1.6.0 shipped on 10 January 2024 — a drop-in replacement for Terraform, with the 1.6.0 tag four months after the fork. State encryption, designed in the open through an RFC, followed in 1.7.
Sources & references
- Official siteopentofu.org
- OpenTofu Language Documentationopentofu.org
- OpenTofu — State and Plan Encryptionopentofu.org
- OpenTofu — Command: testopentofu.org
- OpenTofu — Migrating from Terraformopentofu.org
- The OpenTofu Manifestoopentofu.org
- OpenTofu v1.6.0, the first stable release (10 January 2024)github.com
- OpenTofu is going GA (10 January 2024)opentofu.org