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.

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.

Commitment to Backward Compatibility

Vendor Independence

Open Tofu vs Terraform

*** Issue ranking system

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

Install OpenTofu via Homebrew (on macOS):

brew install opentofu/opentofu/opentofu

If you are using OpenTofu in an existing Terraform project:

tofu init

This will reinitialize the backend, download providers, and prepare the project.

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.

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

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

You can safely switch back to Terraform if:

terraform init

terraform plan

alias terraform=’tofu’

If you use for example, v1.7.1 OpenTofu version and your Terraform version is the same:

  1. No need to update provider version.
    1. 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
    1. 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:

  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!

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.