website/docs/intro/migration/migration-guide.mdx
This guide walks you through migrating from Terraform to OpenTofu. It is designed to be safe and reversible, allowing you to test OpenTofu without disrupting your existing infrastructure.
terraform and tofu commands during the migrationBefore starting the migration, create backups of:
Your Terraform state files
terraform.tfstate and terraform.tfstate_backup filesYour Terraform configuration files
Follow the installation guide to install OpenTofu on your system. Verify the installation:
tofu --version
In your Terraform project directory, initialize OpenTofu:
tofu init
This command will:
Run a plan to ensure OpenTofu can read your state and configuration:
tofu plan
Expected result: You should see "No changes" or the same plan output you would see with Terraform.
If you see unexpected changes:
Once you've verified the plan shows no unexpected changes, run:
tofu apply
Even if there are no infrastructure changes, this ensures OpenTofu updates the state file format if needed.
Make a small, non-critical change to your configuration (e.g., add a tag to a resource) and run:
tofu plan
tofu apply
This verifies that OpenTofu can successfully manage your infrastructure going forward.
If you encounter issues during migration, you can safely roll back:
terraform init
terraform plan
If you encounter issues during migration: