Compatibility
OpenTofu aims to stay compatible with Terraform configurations, and the project says most code runs without changes. Your .tf files, modules and state are used as they are: tofu init downloads providers from the OpenTofu registry and initialises the same backend, then tofu plan reads the existing state.
“Most” is the operative word. The only proof that your configuration is one of them is a plan that shows no changes.
Before you switch
- Back up the state. For local state, copy
terraform.tfstateand its backup file. For remote state, use your backend’s own mechanism, such as bucket versioning or a snapshot. - Commit the configuration, ideally on a branch made for the migration.
- Install OpenTofu and check it with
tofu --version. - In the project directory, run
tofu init, thentofu plan. You want “No changes”, or exactly the plan Terraform would print. - If the plan shows anything you did not expect, do not apply it. Find out why first.
- Run
tofu applyonce even with no changes, so OpenTofu can update the state format if it needs to. - Make a small, harmless change, such as a tag, and plan and apply it to confirm OpenTofu manages the infrastructure.
Pitfalls
- Configurations that feed each other through the
terraform_remote_statedata source need more care. OpenTofu documents that case on a separate page, linked from the guide; read it before migrating them. - Going back is possible: restore the state backup if anything was written, then run
terraform initandterraform planand check the plan is clean.