# Migrate Between Terraform and OpenTofu

Source: https://docs.ops0.com/docs/iac/migrate

Switch an existing IaC project between Terraform and OpenTofu without recreating it. ops0 handles the CLI swap and updates internal tags so future deployments use the target engine.

## When to Migrate

| Scenario | Direction |
|----------|-----------|
| Move to open-source licensing | Terraform → OpenTofu |
| Need a HashiCorp-specific provider feature | OpenTofu → Terraform |
| Organization standardizing on one engine | Either direction |

**Compatibility**

Terraform and OpenTofu are fully compatible at the configuration level. Your `.tf` files, state files, and providers work with both engines without modification.

---

## What Changes

| Aspect | Before | After |
|--------|--------|-------|
| **CLI used for plan/apply** | `terraform` | `tofu` (or vice versa) |
| **ManagedIaC tags** | Updated to reflect new engine | Automatically rewritten |
| **State file** | No change — same format | Compatible across both |
| **Provider plugins** | Re-downloaded on first run | Same registry sources |
| **Configuration files** | No change | No change |

What does **not** change:
- Your `.tf` files remain identical
- State backend configuration stays the same
- Policy mappings and compliance status are preserved
- GitHub sync continues working
- Deployment history is retained

---

## How to Migrate

### Open Project Settings
Navigate to **IaC → Projects** and find the project you want to migrate.

### Click Migrate
In the project actions menu, select **Migrate to OpenTofu** or **Migrate to Terraform** depending on the current engine.

### Review the Impact
A confirmation dialog explains what will change:
- Future deployments will use the target CLI
- ops0 will review code and update ManagedIaC tags
- Existing state and configuration are preserved

### Confirm Migration
Click **Confirm** to proceed. The migration completes in seconds.

### Verify
Run a **Plan** to confirm the project works correctly with the new engine. You should see no unexpected changes.

---

## Migration Considerations

### Provider Compatibility

Most providers work identically across Terraform and OpenTofu. Check for edge cases:

| Provider | Notes |
|----------|-------|
| **AWS** | Fully compatible |
| **GCP** | Fully compatible |
| **Azure** | Fully compatible |
| **Oracle Cloud** | Fully compatible |
| **HashiCorp Vault** | May require version pinning on OpenTofu |

### State File Compatibility

Terraform and OpenTofu use the same state file format. Migration does not modify your state file. You can migrate back and forth without state issues.

### Lock File

The `.terraform.lock.hcl` file is compatible between both engines. On first plan after migration, the target CLI may update provider checksums in the lock file — this is normal.

---

## Rollback

If you need to switch back, repeat the same process in reverse. There is no one-way commitment — you can migrate between Terraform and OpenTofu as needed.

---

## Related

- [IaC Overview](https://docs.ops0.com/docs/iac/overview): IaC features including deployments, AI coding, and scheduling.

- [Projects](https://docs.ops0.com/docs/iac/projects): Create and manage IaC projects.

- [Deployments](https://docs.ops0.com/docs/iac/deployments): Plan and apply infrastructure changes.
