OpenTofu vs Terraform

OpenTofu began as a copy of Terraform. Since the 2023 split they share a language, providers and state format, but not a licence, a roadmap or a managed service.

Updated

The short answer

If you want an open-source tool under a foundation, or you build a product on top of infrastructure as code, OpenTofu is the safer choice: it is MPL 2.0, run under the Linux Foundation, and reads the same configuration and providers you already have. It also has features Terraform doesn't, chief among them built-in encryption of state and plan files.

If you use HCP Terraform or Terraform Enterprise, want a single vendor to support the tool, or depend on Terraform features added since the fork, stay on Terraform. HashiCorp's licence doesn't restrict using Terraform to manage your own infrastructure.

Switching is cheap in both directions at first and gets harder the longer you wait. OpenTofu reads Terraform 1.x state, but once a configuration uses a feature only one tool has, the other can't run it.

OpenTofu and Terraform side by side

FeatureOpenTofuTerraform
Made byThe OpenTofu project, a Linux Foundation project and part of the CNCF. Started in 2023 by Gruntwork, Spacelift, Harness, env0, Scalr and others.HashiCorp, now part of IBM.
LicenceMPL 2.0, open source.Business Source License 1.1 since version 1.6 (August 2023). Earlier releases stay MPL 2.0.
Commandtofu (tofu init, tofu plan, tofu apply).terraform (terraform init, terraform plan, terraform apply).
LanguageHCL in .tf files, plus .tofu files that OpenTofu prefers over a .tf file of the same name.HCL in .tf files, or JSON.
Default registryregistry.opentofu.org (browse at search.opentofu.org). Modules and providers can also come from OCI registries.registry.terraform.io.
StateReads Terraform 1.x state. State and plan files can be encrypted by OpenTofu itself, with a passphrase or AWS KMS, GCP KMS, Azure Key Vault or OpenBao.Plain-text state; protect it with your backend's encryption and access controls.
Added since the forkState and plan encryption, for_each on provider configurations, the enabled meta-argument, -exclude on plan and apply, variables in backend and module source settings.Stacks (in HCP Terraform), terraform query for finding existing resources to import, and its own features in each release since 1.6.
Shared by bothEphemeral values, a test command (tofu test), import blocks, moved and removed blocks, provider-defined functions, S3 state locking without DynamoDB.Ephemeral values, a test command (terraform test), import blocks, moved and removed blocks, provider-defined functions, S3 state locking without DynamoDB.
Managed runsThird-party platforms (often called TACOS) such as Spacelift, env0, Scalr and Harness. No managed service from the project itself.HCP Terraform and Terraform Enterprise from HashiCorp, plus the same third-party platforms.
CostNothing to run. Managed platforms set their own prices.The CLI costs nothing to run. HCP Terraform and Terraform Enterprise are priced on HashiCorp's pricing page.

Why there are two

In August 2023 HashiCorp moved Terraform from the MPL 2.0 to the Business Source License 1.1, starting with version 1.6. The BUSL restricts offering products that compete with HashiCorp's; it doesn't restrict a team using Terraform to manage its own infrastructure. A group of vendors whose products run Terraform forked the last MPL release, first as OpenTF, then as OpenTofu under the Linux Foundation, and shipped OpenTofu 1.6 as its first stable release in January 2024.

For an infrastructure team, the licence matters most when you build Terraform into something you sell or host for others, or when your company's policy prefers open-source licences. If neither applies, the decision comes down to features, support and where your runs happen.

How compatible they still are

Most configuration written for Terraform runs unchanged on OpenTofu. Both speak the same provider protocol, so hashicorp/aws, hashicorp/google, azurerm and the rest work on both; OpenTofu fetches them from its own registry, which is where an address without a hostname points. Check that every provider and module you use is listed at search.opentofu.org before you plan a move.

Because the default registry differs, the first tofu init writes new provider entries into .terraform.lock.hcl. Commit the updated lock file, and expect a reviewer to see that change.

Compatibility is one-way and narrows over time. OpenTofu guarantees it reads Terraform 1.x state; Terraform may not read state OpenTofu has written, especially once OpenTofu-only features are in use, and cannot read encrypted state at all. Each tool also rejects language the other has added since the split, so a module that uses OpenTofu's enabled meta-argument or Terraform's newer blocks runs only on the tool it was written for.

State encryption

The feature that most often decides the question is OpenTofu's state and plan encryption. State can hold database passwords, private keys and tokens in plain text, and in Terraform the only protection is the backend's: an encrypted S3 bucket, tight IAM, versioning. OpenTofu can encrypt the state and plan files themselves before they reach the backend, with keys from a passphrase, AWS KMS, GCP KMS, Azure Key Vault or OpenBao.

It comes with a real risk: lose the key and the state is unrecoverable. OpenTofu's documentation asks you to back up the unencrypted state and the keys first, to use a separate KMS key per state file, and to turn encryption on for an existing project through a fallback to the unencrypted method so it can read the old file once. Encryption also doesn't hide secrets from whoever runs tofu, so production runs still belong in CI.

Ephemeral values, which both tools now have, attack the same problem from the other side: a value marked ephemeral is never written to state or plan at all. Where a provider supports them, they are the cleaner fix in either tool.

Where each has moved on

OpenTofu has used its releases to ship long-standing requests from Terraform's issue tracker: for_each on provider blocks (one provider configuration per Region or account from a map), the enabled meta-argument in place of count = var.create ? 1 : 0, an -exclude flag that is the inverse of -target, variables and locals in backend blocks and module sources, and modules and providers served from OCI registries such as the ones you already run for container images.

Terraform's newer work leans towards HCP Terraform. Stacks, which deploy one set of components across many environments, are run through HCP Terraform; terraform query lists existing resources that match list blocks in a .tfquery.hcl file and can generate the configuration to import them. Before you treat either list as final, read the release notes of the versions you would run: both projects ship minor releases several times a year.

Where your runs happen

If plans and applies run in HCP Terraform or Terraform Enterprise, that platform runs Terraform, and moving to OpenTofu means moving your runs as well. If they run in your own CI (GitHub Actions, GitLab CI, Atlantis) the switch is mostly a change of binary and command name. Platforms such as Spacelift, env0, Scalr and Harness, which backed the fork, run both; check each one's documentation for the versions it supports.

Drift checks and policy are part of the same decision. Whatever runs your scheduled plans has to support the tool you choose; our guide to drift detection and remediation in Terraform-managed infrastructure applies to OpenTofu too, with tofu in place of terraform.

Migrating from Terraform to OpenTofu

OpenTofu's migration guide is short and reversible. Back up the state (for S3, make sure versioning is on) and commit the configuration. Run tofu init, then tofu plan, and expect no changes: anything the plan wants to change is a difference to understand before you apply. Then apply once with no changes so OpenTofu writes the state, and make one small change, such as a tag, to prove it can manage the stack.

If something goes wrong, stop, restore the backed-up state and carry on with terraform init and terraform plan. Hold off on encryption and other OpenTofu-only features until every configuration has moved, so rolling back stays possible.

Where configurations read each other's outputs through terraform_remote_state, migrate from the bottom up: start with configurations nothing depends on and finish with the shared foundations (networking, accounts). A configuration already on OpenTofu can read state written by Terraform, but not always the other way round. OpenTofu also recommends bringing every configuration to the same Terraform version first.

Which one to choose

Choose OpenTofu if

  • You want an open-source licence and a project run by a foundation rather than one vendor.
  • You build a product or internal platform that embeds or hosts infrastructure-as-code runs.
  • You want state and plan files encrypted by the tool itself.
  • You want for_each on providers, the enabled meta-argument or modules and providers from OCI registries.
  • Your runs happen in your own CI or a third-party platform that supports OpenTofu.

Choose Terraform if

  • You run plans and applies in HCP Terraform or Terraform Enterprise.
  • You want commercial support for the tool itself from its maker.
  • You use Stacks or other Terraform features added since version 1.6.
  • The BUSL doesn't affect how you use Terraform and you would rather not change anything.

Questions people ask

Is OpenTofu a drop-in replacement for Terraform?

For most configurations written for Terraform 1.5 and earlier, close to it: the language, providers and state format are the same, and OpenTofu reads Terraform 1.x state. Configurations that use features Terraform added after the fork may need changes. Run tofu plan against your existing state and expect no changes before you rely on it.

Can I go back to Terraform after switching to OpenTofu?

Yes, if you haven't used OpenTofu-only features. Restore the state you backed up before migrating, or check that Terraform can read the current state, then run terraform init and terraform plan. Encrypted state and configuration using OpenTofu-only language make the way back much harder.

Do Terraform providers and modules work with OpenTofu?

Yes. OpenTofu uses the same provider protocol and serves the common providers and modules through its own registry at registry.opentofu.org. Check search.opentofu.org for each one you use.

Does the Terraform licence stop me using it?

Not for managing your own infrastructure. The Business Source License 1.1 restricts products that compete with HashiCorp's. Read HashiCorp's licensing FAQ, or ask your legal team, if you build or host infrastructure tooling for others.

Does HCP Terraform run OpenTofu?

No, it runs Terraform. To run OpenTofu as a managed service, use a platform that supports it, such as Spacelift, env0, Scalr or Harness, or run tofu in your own CI.

Are OpenTofu and Terraform free?

Both CLIs cost nothing to run. HCP Terraform and Terraform Enterprise are paid; check HashiCorp's pricing page. Third-party platforms that run either tool set their own prices.

Sources

  1. OpenTofu FAQ
  2. OpenTofu: Migration guide
  3. OpenTofu: Migrating interdependent configurations
  4. OpenTofu: State and plan encryption
  5. OpenTofu: Ephemerality
  6. OpenTofu: Files and directories
  7. OpenTofu: Provider configuration (for_each)
  8. OpenTofu: The enabled meta-argument
  9. OpenTofu: OCI registry integrations
  10. OpenTofu v1.13.0 release
  11. Terraform: State
  12. Terraform: Stacks
  13. HashiCorp licensing FAQ
  14. HashiCorp pricing