- Getting started
- Migrating to OpenTofu
- Migration Guide
Migration Guide
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.
Prerequisites​
- An existing Terraform configuration
- Access to your Terraform state files
- Ability to run both
terraform
andtofu
commands during the migration
Step 1: Back up your infrastructure​
Before starting the migration, create backups of:
-
Your Terraform state files
- For local state: Copy your
terraform.tfstate
andterraform.tfstate_backup
files - For remote state: Follow your backend's backup procedures (e.g., S3 versioning, snapshot your state bucket)
- For local state: Copy your
-
Your Terraform configuration files
- Commit all changes to version control
- Consider creating a migration branch
Step 2: Install OpenTofu​
Follow the installation guide to install OpenTofu on your system. Verify the installation:
tofu --version
Step 3: Initialize OpenTofu​
In your Terraform project directory, initialize OpenTofu:
tofu init
This command will:
- Download required providers from the OpenTofu registry
- Initialize your backend configuration
- Prepare your working directory
Step 4: Verify your configuration​
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:
- Do not apply the changes
- Investigate the differences
- Consider rolling back (see below)
Step 5: Apply with OpenTofu​
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.
Step 6: Test with a small change​
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.
Rolling back to Terraform​
If you encounter issues during migration, you can safely roll back:
- Stop using OpenTofu immediately
- Restore from your backups (if any state changes were made)
- Run Terraform commands:
Code Block terraform init
terraform plan - Verify no unexpected changes appear in the plan
- Continue using Terraform as before
Getting help​
If you encounter issues during migration:
- Join the OpenTofu Slack
- Ask on GitHub Discussions
- Report bugs on GitHub Issues