Introduction
In the rapidly evolving world of Infrastructure as Code (IaC), OpenTofu has emerged as a powerful open-source alternative to Terraform, offering a more open, community-driven, and flexible future. Suppose you’re considering a switch or just want to stay current. In that case, this guide walks you through everything you need to know about migrating from Terraform to OpenTofu – from preparation to leveraging its newest features.
OpenTofu vs Terraform: What’s the Difference?
Licensing: Open for All vs Source-Available
The most significant and important difference between OpenTofu and Terraform is the licensing. OpenTofu is open-source under the MPL 2.0, and Terraform is under the BSL. Being open-source makes OpenTofu community-driven, and this enables the community to influence the implementation of certain features without being directly influenced by any vendor. However, Terraform is influenced directly by its vendor, HashiCorp, when developing new features.
OpenTofu also offers state encryption, a feature the Terraform community has requested for the last five years but has never received.
This article explains how to encrypt your state.
In addition to this, with OpenTofu 1.8, you can leverage early variable evaluation, meaning that you can take advantage of variables and locals inside your Terraform block and inside your module sources and versions.
As OpenTofu and Terraform continue to evolve, they will probably diverge, meaning that more key differences will emerge in the future. OpenTofu 1.9.1 started as a fork of Terraform and maintains compatibility but also adds new improvements.
Additional features introduced in OpenTofu 1.9.1:
- Backward-compatible with Terraform 1.5+, including most modules and providers
- Faster plan/apply performance
- Improved state file handling
- CLI improvements and bug fixes not yet in Terraform 1.7.1.
- Benefit: You get a familiar experience with a potentially better-performing tool
Commitment to Backward Compatibility
- OpenTofu aims to remain compatible with the Terraform ecosystem (providers, modules) while improving openness
- Benefit: Easy migration path from Terraform with little disruption
Vendor Independence
- No reliance on a single vendor (like HashiCorp) for tooling, updates, or support
- Benefit: More sustainable for long-term infrastructure planning

Preparing for the Migration
Step 1: Back up your state file
Before doing anything, always back up your state file:
cp terraform.tfstate terraform.tfstate.backup
Or if using remote state (e.g., S3):
aws s3 cp s3://your-bucket/path/to/terraform.tfstate ./terraform.tfstate.backup
How to Migrate to OpenTofu (Step-by-Step)
Step 2: Installation
Install OpenTofu via Homebrew (on macOS):
brew install opentofu/opentofu/opentofu
Step 3: Initialize with OpenTofu
If you are using OpenTofu in an existing Terraform project:
tofu init
This will reinitialize the backend, download providers, and prepare the project.
Step 4: Plan and Apply Infrastructure
Run a plan to ensure compatibility:
tofu plan
Then apply changes (if any):
tofu apply
This ensures OpenTofu is working with your existing state and configuration.
Step 5: Upgrade to OpenTofu 1.9.1 Features
Update your required version in main.tf:
terraform {
required_version = ">= 1.9.1"
}
Then upgrade your providers (if needed):
tofu init -upgrade
And verify:
tofu validate
tofu plan
Enable State Encryption (Optional but Recommended)
In your tofu block, enable state encryption using an encryption key (e.g., AWS KMS):
tofu {
state {
encryption = {
provider = "aws"
key_id = "arn:aws:kms:us-east-1:123456789012:key/xxxx-xxxx-xxxx"
}
}
}
Then re-initialize and encrypt state:
tofu init
tofu plan
How to Roll Back to Terraform (if needed)
You can safely switch back to Terraform if:
- The provider versions are compatible.
- You do not use OpenTofu-only features like encrypted state or early variable evaluation.
terraform init
terraform plan
alias terraform=’tofu’
Migration Notes & Best Practices
If you use for example, v1.7.1 OpenTofu version and your Terraform version is the same:
- No need to update provider version.
- If you want to migrate to 1.9.1 for example, you need to update the terraform provider version to 1.9Some terraform features are not supported by tofu, or need to be updated
- If you use lifecycle in some of your modules, you will have to update/prepare the modules first
If you use directly v1.9.1:
- No issues if update the terraform provider version directly to 1.9 and run “tofu init/plan“ with Tofu version 1.9.1 and then roll back the provider version to 1.7 and run “terraform init/plan”. The state file will not be broken!
Why ITGix Recommends OpenTofu
At ITGix, we promote sustainable, vendor-neutral, and flexible DevOps practices. OpenTofu embodies all of these principles. Its backward compatibility, community-driven roadmap, and added security features make it a smart choice for teams seeking long-term IaC stability.
