Lesson 7 of 7 in Infrastructure as Code with Terraform and OpenTofu
Terraform vs OpenTofu: what is the same and what differs
Terraform is the IaC tool made by HashiCorp. OpenTofu is a fork of Terraform, started after HashiCorp changed Terraform's licence in 2023, and is now hosted by the Linux Foundation and accepted into the CNCF. They share a configuration language and most behaviour, with tofu replacing the terraform command.
Draft. This lesson is written and waiting for a person to run every command and review it. It is safe to learn from, but check the official documentation for anything you depend on.
Read these first: The workflow: init, plan, apply, destroy
The problem this solves
When you search for a tutorial you meet both names, and posts about them are often heated. As a learner you need the facts that affect your choice: what the licence terms are, who maintains each tool, and what changes if you switch.
Most of what you learn in this topic works on either tool. The practical question is which one fits your team's rules and your tooling.
How it works
- Control
- Runs code
- Data
The same configuration files can be read by either terraform or tofu, and each tool downloads providers from its own registry.
- Your .tf files to terraform: read by
- Your .tf files to tofu: read by
- terraform to Terraform registry: providers
- tofu to OpenTofu registry: providers
Licence history, stated as facts. On 10 August 2023 HashiCorp announced it was moving future releases of its products, including Terraform, from the Mozilla Public License 2.0 to the Business Source License 1.1. HashiCorp said end users can still copy, modify and redistribute the code, except when offering a product that competes with HashiCorp.
OpenTofu is a fork created in response, first called OpenTF. Its project site describes it as given to the Linux Foundation. It was accepted into the CNCF at the Sandbox level on 23 April 2025, and it uses the MPL 2.0 licence. Terraform remains developed by HashiCorp.
In daily use the configuration language is the same and providers are shared in practice. Differences are in features and registries. OpenTofu has its own registry and has added features of its own, such as client-side state encryption. Terraform has HashiCorp's hosted service, HCP Terraform. Both projects keep adding features, so read each tool's current documentation before relying on a difference.
To choose, look at your own constraints: your company's licence policy, which hosted platforms and CI templates you use, which provider or feature you need, and who supports the tool in your team. For learning, either one works for everything in this topic.
Try it yourself
You need at least one of the two tools. If you have both, run both. If you have one, run just that one. The config is copied without state so each tool starts fresh.
- 1Check which tools you have
terraform version tofu version
The first line of each prints the tool's name and version.
- 2Write a config that both can read
mkdir -p ~/iac-lab/compare/common && cd ~/iac-lab/compare cat > common/main.tf <<"EOF" terraform { required_providers { random = { source = "hashicorp/random" } } } resource "random_pet" "name" { length = 2 } output "name" { value = random_pet.name.id } EOF - 3Run it with Terraform
mkdir tf && cp common/main.tf tf/ && cd tf terraform init terraform apply -auto-approve grep -n registry .terraform.lock.hcl cd ..
The lock file records the provider address, which includes the registry host
registry.terraform.io. - 4Run the same file with OpenTofu
mkdir tofu && cp common/main.tf tofu/ && cd tofu tofu init tofu apply -auto-approve grep -n registry .terraform.lock.hcl cd ..
Same input, same behaviour. The lock file now names
registry.opentofu.org. OpenTofu also keeps the file name.terraform.lock.hcl. - 5Clean up
(cd tf && terraform destroy -auto-approve) (cd tofu && tofu destroy -auto-approve)
Skip the line for a tool you did not install.
What breaks, and where to look
Error: Unsupported Terraform Core version, or This configuration does not support Terraform version X.
- WHY IT HAPPENS
- The config has
required_versionin itsterraformblock, and the version of the tool you run does not satisfy it. Teams mix tools and versions. - CHECK FIRST
- Look at
required_versionin the config and runterraform versionortofu version. Align the tool version or relax the constraint on purpose.
Error: state snapshot was created by Terraform v..., which is newer than current v...
- WHY IT HAPPENS
- State written by a newer version cannot be read by an older one. Pointing a different tool or an older version at an existing state is a one-way step.
- CHECK FIRST
- Back up the state first. Check which version last wrote it and use the same or a newer one. Follow the OpenTofu migration guide before switching a real project.
Error: Failed to query available provider packages, a provider cannot be found.
- WHY IT HAPPENS
- Providers come from a registry. A provider that is only published in one registry cannot be downloaded from the other.
- CHECK FIRST
- Read the full provider address in the error and look it up in the registry your tool uses. Check network access too.
When not to use this
- Do not switch tools on a live project because a blog post told you to. Read the official migration guide, back up state, and test with a small change first.
- Do not assume a feature exists in both. The projects have diverged in places, and a config using a tool-specific feature will not run on the other.
Check yourself
What happened to Terraform's licence in 2023?
HashiCorp announced on 10 August 2023 a move for future releases from MPL 2.0 to the Business Source License 1.1.
What is OpenTofu and who hosts it?
A fork of Terraform that uses the MPL 2.0 licence. It is under the Linux Foundation and accepted into the CNCF as a Sandbox project in April 2025.
Why must you take care before pointing a different tool or version at existing state?
State written by a newer version may not be readable by an older one, so you should back it up and follow the migration guide first.
Keep going
Lesson 69 of 92 in the DevOps path