TExcelTAD
Home › Infrastructure as Code: Terraform & OpenTofu › OpenTofu: the Fork & What Differs

OpenTofu: the Fork & What Differs

Every session in this course ran on OpenTofu, and almost every one would have run unchanged on Terraform. This lesson is about the "almost": where the projects came from, how they have diverged since 2023, and how to choose.

History in five lines

  • 2014–2023: Terraform is open source (MPL 2.0) and becomes the standard IaC tool; a large ecosystem of providers, modules and companies grows around it.
  • August 2023: HashiCorp relicenses new Terraform versions under the Business Source License (BUSL 1.1): free to use, but not to build a competing commercial product.
  • Autumn 2023: a group of companies and community members forks the last MPL code as OpenTofu, hosted by the Linux Foundation; OpenTofu 1.6.0, the first stable release, follows in January 2024.
  • 2024–2025: OpenTofu ships its own features release by release; it is later accepted into the CNCF. IBM completes its acquisition of HashiCorp in 2025.
  • Today: two compatible-but-diverging tools. The language, the state format and the providers are shared; each CLI has features the other lacks.

What is the same

  • HCL, the block types, expressions and functions you learned in this course.
  • The providers: the same releases of hashicorp/aws, kubernetes, helm and the rest, served from each project's registry.
  • The state format and backends (S3, GCS, azurerm, …).
  • The workflow: init, plan, apply, test, import/moved/removed blocks.

What OpenTofu adds

Features by release (all present in the 1.13.2 used here):

Release Features
1.7 state and plan encryption (next lesson), provider-defined functions, removed blocks, for_each in import blocks
1.8 early evaluation: variables and locals in backend, module source and encryption blocks; .tofu files; mock_provider and overrides in tofu test
1.9 provider for_each (one provider configuration per region or account), -exclude
1.10 OCI registries for providers and modules, native S3 state locking, OpenTelemetry tracing (experimental), -target-file/-exclude-file
1.11 ephemeral values and write-only attributes, the enabled lifecycle meta-argument
1.12 prevent_destroy from variables, destroy = false in lifecycle, full provider checksums recorded by init

Terraform, for its part, has features OpenTofu doesn't: tight integration with HCP Terraform (remote runs, the private registry, policy as code with Sentinel), Terraform Stacks, and its own newer language additions. Check both changelogs for the version you run.

Three OpenTofu features, live

.tofu files. When x.tofu and x.tf both exist, OpenTofu reads the .tofu file and ignores the .tf one; Terraform never reads .tofu. A module can therefore use OpenTofu-only features while staying usable from Terraform:

bash · try it yourself
mkdir both && cd both
cat > main.tf <<'HCL'
resource "terraform_data" "cli" {
  input = "read by terraform"
}
output "cli" {
  value = terraform_data.cli.output
}
HCL
cat > main.tofu <<'HCL'
resource "terraform_data" "cli" {
  input = "read by opentofu"
}
output "cli" {
  value = terraform_data.cli.output
}
HCL
tofu init >/dev/null && tofu apply -auto-approve | tail -1
rm -f terraform.tfstate*
terraform init >/dev/null && terraform apply -auto-approve | tail -1
cli = "read by opentofu"
cli = "read by terraform"

enabled and -exclude. lifecycle { enabled = … } replaces the count = cond ? 1 : 0 idiom from count for zero-or-one resources, and keeps the address free of [0]. -exclude is the inverse of -target:

bash · try it yourself
mkdir opt && cd opt
cat > main.tf <<'HCL'
variable "debug" {
  type    = bool
  default = false
}

resource "terraform_data" "debug_marker" {
  input = "verbose logging on"
  lifecycle {
    enabled = var.debug
  }
}

resource "terraform_data" "always" {
  input = "always here"
}
HCL
tofu init >/dev/null
echo "--- debug=false"
tofu plan | grep -E '^  #|^Plan:'
echo "--- debug=true"
tofu plan -var debug=true | grep -E '^  #|^Plan:'
echo "--- debug=true, everything except terraform_data.always"
tofu plan -var debug=true -exclude=terraform_data.always | grep -E '^  #|^Plan:'
--- debug=false
  # terraform_data.always will be created
Plan: 1 to add, 0 to change, 0 to destroy.
--- debug=true
  # terraform_data.always will be created
  # terraform_data.debug_marker will be created
Plan: 2 to add, 0 to change, 0 to destroy.
--- debug=true, everything except terraform_data.always
  # terraform_data.debug_marker will be created
Plan: 1 to add, 0 to change, 0 to destroy.

Provider for_each. One provider block can create a configuration per region (or per account role), and resources pick theirs with provider = aws.by_region[each.key]. Planned offline:

bash · try it yourself
mkdir regions && cd regions
cat > main.tf <<'HCL'
terraform {
  required_providers {
    aws = { source = "hashicorp/aws", version = "~> 6.0" }
  }
}

variable "regions" {
  type    = set(string)
  default = ["eu-west-1", "us-east-1"]
}

provider "aws" {
  alias    = "by_region"
  for_each = var.regions
  region   = each.key

  access_key                  = "offline"     # teaching setup
  secret_key                  = "offline"
  skip_credentials_validation = true
  skip_requesting_account_id  = true
  skip_metadata_api_check     = true
}

resource "aws_s3_bucket" "logs" {
  for_each = var.regions
  provider = aws.by_region[each.key]
  bucket   = "linkly-logs-${each.key}"
}
HCL
tofu init >/dev/null
tofu plan | grep -E '^  #|^Plan:|^      \+ region '
  # aws_s3_bucket.logs["eu-west-1"] will be created
      + region                      = "eu-west-1"
  # aws_s3_bucket.logs["us-east-1"] will be created
      + region                      = "us-east-1"
Plan: 2 to add, 0 to change, 0 to destroy.

Choosing

If… Lean towards
you want an open-source licence and a community-governed project OpenTofu
you need client-side state encryption, provider for_each, .tofu overrides OpenTofu
you use HCP Terraform / Terraform Enterprise, Sentinel or Stacks Terraform
you build a product that offers IaC as a service OpenTofu (BUSL restricts competing offerings)
your modules must work for both communities write for the common subset; put tool-specific code in .tofu files

Whichever you pick, pin the CLI version (required_version, a .opentofu-version or .terraform-version file for tenv) and don't mix the two CLIs on one state: the lock file and state are compatible, but features one CLI writes may be unknown to the other. Migrating State Between Backends covers switching.

Test yourself

A folder has network.tf and network.tofu. Which file does each CLI read?

  1. Both read both
  2. OpenTofu reads network.tofu (ignoring network.tf); Terraform reads network.tf
  3. Terraform reads network.tofu
  4. Neither; it is an error

Which is an OpenTofu-only feature?

  1. moved blocks
  2. import blocks
  3. Client-side state and plan encryption
  4. Saved plan files

What does tofu plan -exclude=ADDR do?

  1. Plans only ADDR
  2. Plans everything except ADDR (and what depends on it)
  3. Removes ADDR from state
  4. Ignores ADDR's drift forever