Skip to main content

Infrastructure as code · Beginner · 20 min

Choose between Terraform and OpenTofu for a new project

By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · Terraform 1.17.2 · OpenTofu 1.13.10 · hashicorp/random 3.9 · hashicorp/local 2.9

You will install Terraform 1.17 and OpenTofu 1.13 side by side, run one configuration through each, switch its state from one tool to the other and back, and finish with a written decision checklist for your project.

On this page

Terraform and OpenTofu share a history. OpenTofu was forked from Terraform in 2023, when HashiCorp moved Terraform from an open source licence to the Business Source License. Both still read the same HCL language, use the same providers and write the same state format. That makes the choice look small. It is not small, because some decisions are hard to reverse once a team has a year of state, modules and pipelines built on one tool.

The useful way to choose is to try both on the same code, then look at the points where they differ: the licence, where providers come from, the features only one of them has, and how hard it is to move later. That is what you do here, with two providers that need no cloud account and bill nothing.

By the end you will have:

  • Terraform 1.17.2 and OpenTofu 1.13.10 installed next to each other, both checked against published checksums
  • one configuration applied by each tool, with the differences in their lock and state files in front of you
  • a working example of a feature only OpenTofu has (encrypted state), and proof that Terraform cannot read the result
  • a project moved from Terraform to OpenTofu and back without recreating anything
  • a filled-in decision checklist in ~/iac-choice-demo/DECISION.md

This is not legal advice. If your company builds a product on top of either tool, have someone qualified read the licence.

Step 1 · Install Terraform 1.17

Install curl and unzip, then download the Terraform 1.17.2 archive for your processor and the checksum list HashiCorp publishes beside it:

Bash
sudo apt update
sudo apt install -y curl unzip ca-certificates
TF_VERSION=1.17.2
ARCH=$(dpkg --print-architecture)
cd "$(mktemp -d)"
curl -fsSLO "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_${ARCH}.zip"
curl -fsSLO "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_SHA256SUMS"
sha256sum --ignore-missing -c "terraform_${TF_VERSION}_SHA256SUMS"

dpkg --print-architecture prints amd64 or arm64, which matches both projects' file names. If sha256sum reports FAILED, delete the file and download it again before going further. When it says OK, put the binary on your path:

Bash
unzip -o "terraform_${TF_VERSION}_linux_${ARCH}.zip" terraform
sudo install -m 0755 terraform /usr/local/bin/terraform
terraform version

A binary installed by hand gets no security updates from apt. To upgrade, run the same commands with a newer TF_VERSION.

Check it worked

sha256sum printed terraform_1.17.2_linux_amd64.zip: OK (or arm64), and the first line of terraform version is Terraform v1.17.2.

Step 2 · Install OpenTofu 1.13 beside it

OpenTofu installs the same way. Its program is called tofu, so the two never overwrite each other:

Bash
TOFU_VERSION=1.13.10
cd "$(mktemp -d)"
curl -fsSLO "https://github.com/opentofu/opentofu/releases/download/v${TOFU_VERSION}/tofu_${TOFU_VERSION}_linux_${ARCH}.tar.gz"
curl -fsSLO "https://github.com/opentofu/opentofu/releases/download/v${TOFU_VERSION}/tofu_${TOFU_VERSION}_SHA256SUMS"
sha256sum --ignore-missing -c "tofu_${TOFU_VERSION}_SHA256SUMS"
tar -xzf "tofu_${TOFU_VERSION}_linux_${ARCH}.tar.gz" tofu
sudo install -m 0755 tofu /usr/local/bin/tofu
tofu version

The same upgrade rule applies: repeat the step with a newer TOFU_VERSION. OpenTofu also publishes an apt repository if you would rather have updates through apt once you have chosen it.

Both tools honour the same plugin cache setting. On metered or prepaid data, set it now, so each provider is downloaded once and reused by every folder in this tutorial instead of once per folder and per tool:

Bash
mkdir -p ~/.cache/iac-plugins
grep -qxF 'export TF_PLUGIN_CACHE_DIR="$HOME/.cache/iac-plugins"' ~/.bashrc || echo 'export TF_PLUGIN_CACHE_DIR="$HOME/.cache/iac-plugins"' >> ~/.bashrc
export TF_PLUGIN_CACHE_DIR="$HOME/.cache/iac-plugins"

Check it worked

sha256sum printed tofu_1.13.10_linux_amd64.tar.gz: OK (or arm64), and tofu version starts with OpenTofu v1.13.10. Run which terraform tofu and you see two separate paths in /usr/local/bin.

Step 3 · Write one configuration for both tools

The configuration names a release with a random two-word name and writes it to a file. Create it in a folder called base, which you will copy rather than run, so every run starts from the same files:

Bash
mkdir -p ~/iac-choice-demo/base
cd ~/iac-choice-demo/base

cat > versions.tf <<'HCL'
terraform {
  required_version = ">= 1.10.0"

  required_providers {
    random = {
      source  = "hashicorp/random"
      version = "~> 3.9"
    }
    local = {
      source  = "hashicorp/local"
      version = "~> 2.9"
    }
  }
}
HCL

cat > main.tf <<'HCL'
variable "environment" {
  type    = string
  default = "staging"
}

resource "random_pet" "release" {
  length = 2
}

resource "local_file" "release" {
  filename = "${path.module}/release.txt"
  content  = "${var.environment} release ${random_pet.release.id}\n"
}

output "release_name" {
  value = random_pet.release.id
}
HCL

Two details already behave differently between the tools, even though the text is identical:

  • required_version is checked against the version of whichever tool runs it. Terraform 1.17 and OpenTofu 1.13 both pass >= 1.10.0, but the numbers are unrelated: OpenTofu 1.13 is not "older" than Terraform 1.17. A shared module that sets >= 1.14 would lock OpenTofu out.
  • source = "hashicorp/random" is a short address. Terraform expands it to registry.terraform.io/hashicorp/random, and OpenTofu to registry.opentofu.org/hashicorp/random. Same provider code, two registries.

Check it worked

ls ~/iac-choice-demo/base lists main.tf and versions.tf, and nothing else.

Step 4 · Run the same code through each tool

Copy base twice and run the full loop in each copy. -chdir tells either tool which folder to work in, so you can stay in one place:

Bash
cd ~/iac-choice-demo
cp -R base with-terraform
cp -R base with-tofu

terraform -chdir=with-terraform init
terraform -chdir=with-terraform plan -out=tfplan
terraform -chdir=with-terraform apply tfplan

tofu -chdir=with-tofu init
tofu -chdir=with-tofu plan -out=tfplan
tofu -chdir=with-tofu apply tfplan

The plans read almost line for line the same: two resources to add, Plan: 2 to add, 0 to change, 0 to destroy. Now compare what each tool left behind:

Bash
cat with-terraform/release.txt with-tofu/release.txt
grep '^provider' with-terraform/.terraform.lock.hcl with-tofu/.terraform.lock.hcl
grep '"terraform_version"' with-terraform/terraform.tfstate with-tofu/terraform.tfstate

The lock files show the registry split from the previous step: every entry in with-terraform starts with registry.terraform.io/, every entry in with-tofu with registry.opentofu.org/. The state files have the same layout, and both still call the version field terraform_version. Only the value differs: 1.17.2 in one and 1.13.10 in the other.

Check it worked

Each release.txt holds one line such as staging release followed by a two-word name, different in each folder. The grep '^provider' output shows four lines, two per folder, with the two registry hostnames.

Step 5 · Read the differences that affect the decision

Running the code showed you the parts that are the same. The parts that differ are mostly not visible in a plan, so read them from the source. Start with the licences, fetched from the tagged releases you installed:

Bash
curl -fsSL https://raw.githubusercontent.com/hashicorp/terraform/v1.17.2/LICENSE | sed -n '1,12p'
curl -fsSL https://raw.githubusercontent.com/opentofu/opentofu/v1.13.10/LICENSE | sed -n '1,4p'

The first file is the Business Source License 1.1, with IBM named as the licensor (IBM now owns HashiCorp). It allows production use, but not offering Terraform to third parties, hosted or embedded, in a product that competes with IBM's paid versions. Further down it says each version converts to MPL 2.0 four years after it is published. The second file is the Mozilla Public License 2.0, an open source licence with no restriction of that kind. For most teams running their own infrastructure, both licences allow what they do. The licence matters when you sell a platform, a hosted service or a product that bundles the tool, or when your organisation only approves OSI-approved licences.

Then the practical differences, as of Terraform 1.17 and OpenTofu 1.13:

  • Registries. Terraform installs providers and modules from registry.terraform.io, OpenTofu from registry.opentofu.org. The common providers are in both. Check that every provider and module your project needs is in the registry of the tool you pick before you commit to it.
  • Only in OpenTofu: encryption of state and plan files at rest, built into the tool (the next step tries it). Variables and locals inside the backend block, as long as they can be worked out at tofu init; Terraform does not allow variables or locals there. .tofu files, which OpenTofu reads and Terraform ignores, so one module can carry OpenTofu-only code.
  • Only in Terraform: official support for HCP Terraform and Terraform Enterprise (OpenTofu keeps a cloud block, but only for compatible third-party platforms). List resources and terraform query for finding existing infrastructure, and action blocks for provider-defined side effects, both from 1.14. Terraform Policy, generally available in 1.17, and variables or locals inside required_providers.
  • Hosted runners. HashiCorp's HCP Terraform runs Terraform. Several other automation platforms, which the OpenTofu docs call TACOS, run OpenTofu, and many run both.
  • Support windows. OpenTofu states that 1.13.x is supported until 1 August 2027 and that 1.13 is the last series with official 32-bit builds. If you still run 32-bit ARM boards, plan for that.

Each feature in the two "only in" lists makes switching harder. The other tool either rejects that code, ignores it (.tofu files in Terraform, so the two tools quietly behave differently), or, with encrypted state, cannot read the state at all.

Check it worked

The first curl shows a line with Business Source License and the line Licensor: International Business Machines Corporation (IBM). The second ends with Mozilla Public License, version 2.0.

Step 6 · Try a feature only OpenTofu has

State files hold every attribute of every resource in plain text, including passwords and keys that providers return. Terraform leaves protecting the file to wherever you store it. OpenTofu can encrypt it before it is written. Make a fresh copy of the configuration and add an encryption.tofu file. The .tofu extension keeps this file invisible to Terraform:

Bash
cd ~/iac-choice-demo
cp -R base encrypted
cd encrypted

cat > encryption.tofu <<'HCL'
variable "state_passphrase" {
  type      = string
  sensitive = true
}

terraform {
  encryption {
    key_provider "pbkdf2" "local" {
      passphrase = var.state_passphrase
    }

    method "aes_gcm" "local" {
      keys = key_provider.pbkdf2.local
    }

    state {
      method   = method.aes_gcm.local
      enforced = true
    }

    plan {
      method   = method.aes_gcm.local
      enforced = true
    }
  }
}
HCL

enforced = true makes OpenTofu refuse to write an unencrypted state or plan file if the configuration is ever broken. The passphrase is an input variable with no default, so it never sits in a file. Type it at a prompt instead, at least 16 characters, and store it in your password manager: if you lose it, OpenTofu cannot read this state again.

Bash
read -rsp 'State passphrase (16 or more characters): ' TF_VAR_state_passphrase && echo
export TF_VAR_state_passphrase

Now run the usual loop and look at the state file:

Bash
tofu init
tofu plan -out=tfplan
tofu apply tfplan
tofu state list
grep -o '"encrypted_data"' terraform.tfstate

tofu state list still shows local_file.release and random_pet.release, because OpenTofu decrypts with your passphrase. The file on disk no longer has a readable resource list, only fields such as meta and encrypted_data. The saved tfplan is encrypted too.

Now point Terraform at the same folder:

Bash
terraform init
terraform plan

Terraform does not load encryption.tofu, so it sees a plain configuration, but it cannot read the state and stops with an error like Unsupported state file format and The state file does not have a "version" attribute. This is the one-way door in practice. OpenTofu's docs describe how to decrypt back to a plain state if you need to leave.

Check it worked

grep prints "encrypted_data", tofu state list prints the two resource addresses, and Terraform exits with a state file error in this folder only. The with-terraform and with-tofu folders are untouched.

Step 7 · Move a Terraform project to OpenTofu

Most moves go in this direction: a team has a Terraform project and wants to try OpenTofu on it. with-terraform is that project. Back up the state first, then initialise OpenTofu in the same folder:

Bash
cd ~/iac-choice-demo/with-terraform
mkdir -p backups
cp terraform.tfstate backups/before-tofu.tfstate
tofu init
tofu plan

tofu init reads the existing lock file and treats each registry.terraform.io/hashicorp/... entry as its registry.opentofu.org equivalent, keeping the same version and recording new checksums. It does this only for providers in the hashicorp namespace; providers from other namespaces are found by the full address in your configuration. The plan should say No changes. Your infrastructure matches the configuration. If it proposes any change, do not apply it: work out why first, and if you cannot, go back to Terraform with the backup.

With an empty plan, apply once so OpenTofu saves the state in its own form:

Bash
tofu plan -out=tfplan
tofu apply tfplan
grep '^provider' .terraform.lock.hcl

Check it worked

tofu plan reported no changes, the apply says 0 added, 0 changed, 0 destroyed, release.txt still has the same release name as before, and the lock file now lists registry.opentofu.org/hashicorp/local and registry.opentofu.org/hashicorp/random.

Step 8 · Move it back to Terraform

Knowing the way back is part of the decision. If you only tried OpenTofu and made no changes, restoring backups/before-tofu.tfstate is enough. After real use, the state may now name the OpenTofu registry for each provider, so tell Terraform to rename them, then initialise:

Bash
cp terraform.tfstate backups/before-terraform.tfstate
Bash
terraform state replace-provider registry.opentofu.org/hashicorp/random registry.terraform.io/hashicorp/random
terraform state replace-provider registry.opentofu.org/hashicorp/local registry.terraform.io/hashicorp/local

Each command lists the resources it will change and asks you to type yes. If it prints No matching resources found., that provider was already under the Terraform address and there is nothing to do. Then:

Bash
terraform init
terraform plan
grep -c 'registry.opentofu.org' terraform.tfstate || true

The move back works here because the project uses nothing from the "only in OpenTofu" list. Had you added state encryption, you would first decrypt with OpenTofu, and any .tofu files or variables in the backend block would need rewriting.

Check it worked

terraform plan reports No changes., the grep -c prints 0, and release.txt still shows the original release name. The project has been through both tools without a single resource being replaced.

Step 9 · Write your decision checklist

Turn what you saw into a page your team can review. Create the checklist, then fill in each answer for your project in a text editor:

Bash
cat > ~/iac-choice-demo/DECISION.md <<'MD'
# Terraform or OpenTofu: decision for <project name, replace this>

Decided by: <names>    Date: <YYYY-MM-DD>    Review again: <date, at least yearly>

## Licence
- [ ] Do we sell, host or bundle this tool for other people? If yes, a qualified person has read the BUSL 1.1 additional use grant.
- [ ] Does our policy require an OSI-approved licence? If yes, OpenTofu (MPL 2.0).

## Providers and modules
- [ ] Every provider we need is in the registry of the chosen tool, at the version we need.
- [ ] Every module we use from a registry is available there too.

## Features
- [ ] Do we need HCP Terraform, Terraform Policy, list resources or action blocks? (Terraform only)
- [ ] Do we need state and plan encryption in the tool, variables in backend blocks or .tofu files? (OpenTofu only)

## Running it
- [ ] Our CI system or automation platform supports the chosen tool and version.
- [ ] The tool version is pinned in CI and in required_version, with an owner for upgrades.
- [ ] The support window of our version covers the next twelve months.

## Leaving later
- [ ] We have tried the move in both directions on a copy of a real project (plan shows no changes).
- [ ] We have listed every tool-specific feature we adopt, so the cost of switching stays visible.

## Decision
Tool and version:
Reason, in two sentences:
MD
grep -c '^- \[ \]' ~/iac-choice-demo/DECISION.md

Keep the file in the repository the infrastructure code lives in, so the reasons travel with the code. If your team works across several languages, write the reason line in the one your reviewers read most easily; the checklist items are short enough to translate.

When you have copied what you need, remove the demo. Nothing here created cloud resources, so nothing bills. Remove whichever binary you decided not to use with sudo rm /usr/local/bin/terraform or sudo rm /usr/local/bin/tofu, and delete the plugin cache line from ~/.bashrc if you no longer want it. The commands below also delete the plugin cache this tutorial filled at ~/.cache/iac-plugins.

Bash
unset TF_VAR_state_passphrase
cp ~/iac-choice-demo/DECISION.md ~/DECISION-terraform-or-opentofu.md
rm -rf ~/iac-choice-demo ~/.cache/iac-plugins

Check it worked

grep -c printed 11, the number of checklist items, before the demo was removed. ~/DECISION-terraform-or-opentofu.md is your copy, and ls ~/iac-choice-demo now reports that the folder does not exist.

Next steps

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.