Skip to main content
In this guide, you’ll learn how to migrate an existing Terraform project to OpenTofu, verify the changes, and then roll back to Terraform. We’ll cover:
  • Applying the initial Terraform configuration
  • Installing OpenTofu
  • Backing up state files
  • Initializing and planning with OpenTofu
  • Updating resources and applying changes
  • Rolling back to Terraform

1. Apply the Initial Terraform Configuration

  1. Navigate to your project directory and review main.tf:
  2. Initialize and apply:
  3. When prompted, enter yes. You should see:
  4. Verify that terraform.txt exists with the correct content.

2. Install OpenTofu

Refer to the OpenTofu installation guide and select the installer for your OS.
Make sure to check your distribution using cat /etc/os-release before running the installer.
The image shows a webpage for installing OpenTofu, detailing various installation methods for different operating systems like Alpine Linux, Debian, Fedora, and more. The page includes a navigation menu on the left and installation options in the main section.

Automated Debian/Ubuntu Installer

Or bundle the commands in install.sh:
Then run:
Verify the installation:

3. Backup the Terraform State

Always archive your existing Terraform state before migrating. Losing state can lead to resource drift or duplicates.
Confirm the archive:

4. Initialize with OpenTofu

Switch to the OpenTofu workflow:

5. Preview the OpenTofu Plan

Compare the two workflows with this quick reference: Run the plan:
You should see the same local_file.file resource with filename = "terraform.txt".

6. Update the main.tf for OpenTofu

Change main.tf to point to a new file and content:
Validate the updated configuration:

7. Apply with OpenTofu

Apply the OpenTofu configuration:
Type yes when prompted.
The image shows a split screen with a task interface on the left, indicating progress in a task related to applying changes using OpenTofu, and a code editor on the right displaying a file structure and terminal output related to a Terraform project.
Confirm that opentofu.txt has been created with the new content.

8. Roll Back to Terraform

  1. Backup the OpenTofu state:
  2. Re-initialize with Terraform:
The image shows a coding environment with a task to initialize a configuration directory using Terraform. The terminal indicates that Terraform has been successfully initialized.
  1. Revert main.tf to the original Terraform resource:
  2. Apply with Terraform:
    Enter yes and observe:
You’ve now successfully migrated to OpenTofu and rolled back to Terraform!

Watch Video

Practice Lab