OpenTofu: Why It Exists, Installation and Migrating from Terraform
Why OpenTofu was forked from Terraform, how to install it on Ubuntu, and how to migrate an existing Terraform project with tofu init, including the lock file warning.

ON THIS PAGE
OpenTofu is an open-source fork of Terraform, run by the community under the Linux Foundation. It uses the same HCL language, providers and state format, so existing Terraform projects run on it, usually without code changes. This guide explains why the fork happened, installs OpenTofu on Ubuntu, and migrates one of the AWS projects from part 1 of this series.
Why OpenTofu exists
Terraform was open source under the Mozilla Public License (MPL 2.0) from 2014, and a large ecosystem of providers, modules and tools grew around it. In August 2023, HashiCorp moved Terraform to the Business Source License (BUSL). The BUSL is source-available, not open source: it restricts use in products that compete with HashiCorp, and the wording left many companies unsure whether their own use was allowed.
The community responded with the OpenTF manifesto. It asked HashiCorp to return Terraform to an open-source license, and said the community would fork it otherwise. HashiCorp did not change course, so the last MPL version was forked. The fork was named OpenTofu and placed under the Linux Foundation, so no single company controls it.
The manifesto's promises for the project:
- Truly open source, under a well-known license that will not change suddenly. OpenTofu stays on MPL 2.0.
- Community-driven, with contributions accepted on their merit.
- Impartial, with features prioritized for users, not for one vendor.
- Layered and modular, so other tools can build on it.
- Backward-compatible, so existing Terraform code keeps working.
Since the fork, OpenTofu has also added features of its own, such as client-side state encryption. The workflow is the same as Terraform: write, tofu plan, tofu apply. The CLI command is tofu instead of terraform.
Prerequisites
- An Ubuntu or Debian machine with
sudoaccess (the screenshots use an Ubuntu Vagrant VM). - An existing Terraform project to migrate, such as the EC2 project from part 1.
Install OpenTofu
Option 1: the installer script
The standalone installation guide uses an installer script. Copy the commands from the official page, because they may change:
$ curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh
$ chmod +x install-opentofu.sh
$ less install-opentofu.sh
$ ./install-opentofu.sh --install-method standalone
$ rm -f install-opentofu.shThe less step is deliberate: always read a downloaded script before running it.
Option 2: the APT repository on Debian or Ubuntu
The Debian/Ubuntu guide adds the OpenTofu package repository, so apt upgrade keeps tofu up to date.
Install the tools needed to add a repository:
$ sudo apt-get update
$ sudo apt-get install -y apt-transport-https ca-certificates curl gnupgDownload the signing keys into /etc/apt/keyrings:
$ sudo install -m 0755 -d /etc/apt/keyrings
$ curl -fsSL https://get.opentofu.org/opentofu.gpg | sudo tee /etc/apt/keyrings/opentofu.gpg >/dev/null
$ curl -fsSL https://packages.opentofu.org/opentofu/tofu/gpgkey | sudo gpg --no-tty --batch --dearmor -o /etc/apt/keyrings/opentofu-repo.gpg >/dev/null
$ sudo chmod a+r /etc/apt/keyrings/opentofu.gpg /etc/apt/keyrings/opentofu-repo.gpgAdd the repository, limited to those keys with signed-by:
echo \
"deb [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main
deb-src [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main" | \
sudo tee /etc/apt/sources.list.d/opentofu.list > /dev/null
sudo chmod a+r /etc/apt/sources.list.d/opentofu.listInstall OpenTofu:
$ sudo apt-get update
$ sudo apt-get install -y tofuCheck the installation
$ tofu --version
In my lab, the Ubuntu VM ran OpenTofu 1.10.5 and the host ran Terraform 1.13.1. The two tools can coexist on one machine because their commands have different names.
Migrate a Terraform project to OpenTofu
The migration guide describes a process that is safe and reversible:
- Back up the state and the code. For a local backend, copy
terraform.tfstateandterraform.tfstate.backup. For a remote backend, follow that backend's backup method (for S3, bucket versioning helps). - Install OpenTofu and check it with
tofu --version. - Initialize with
tofu init. - Verify with
tofu plan. It should report no changes, or only changes you expected. - Apply once with
tofu apply, which may update the state file format. - Test with a small change, for example a new tag, then
tofu planandtofu apply.
If the migration fails, restore the backups and run terraform init and terraform plan to return to Terraform.
I ran the migration on a copy of my first EC2 project (example1-backup) so the original stayed untouched:
$ cd ~/shared_folder/terraform-examples/example1-backup
$ tofu init
The lock file warning
tofu init printed Warning: Dependency lock file entries automatically updated. This warning is expected during a migration:
- OpenTofu downloads providers from its own registry,
registry.opentofu.org, so it rewrote the lock file entry fromregistry.terraform.io/hashicorp/awstoregistry.opentofu.org/hashicorp/aws. - The provider version (6.11.0) was kept. The hashes were not, because the OpenTofu registry's provider builds are not byte-for-byte identical to HashiCorp's.
Review the updated .terraform.lock.hcl and commit it once you decide to stay on OpenTofu. After that, everything from part 1, such as variables, backends, workspaces and modules, works the same with tofu in place of terraform.
Key takeaways
- OpenTofu is the MPL-licensed fork of Terraform, created after HashiCorp moved Terraform to the BUSL in August 2023.
- It is a drop-in replacement: same HCL, same providers, same state; the command is
tofu. - Install it with the official installer script or the APT repository, and check with
tofu --version. - Migrate on a backup:
tofu init, confirmtofu planshows no changes, then test with a small change. - The lock file warning during
tofu initis expected; versions stay the same, the registry and hashes change.
Keep reading
- Terraform on AWS: EC2, State, Backends, Workspaces and Modules
A hands-on Terraform walkthrough on AWS: launch EC2, read the state file, handle drift, use map variables, provisioners, outputs, an S3 backend, workspaces and modules.
- Ansible Playbooks: Apache, MariaDB, Variables, Conditionals and Loops
Write Ansible playbooks that install Apache and MariaDB, create a database and user, and use variables, facts, when conditions and loops across Ubuntu and CentOS VMs.
- Getting Started with Ansible: Install, Inventory and Ad-hoc Commands
Install Ansible in a Python virtual environment, connect Vagrant VMs with passwords and SSH keys, write a first inventory and manage packages with ad-hoc commands.