Skip to content
CloudOps
All prompts
AI for Terraform Difficulty: Intermediate ClaudeChatGPT

Terraform → OpenTofu Migration Prompt

Migrate from Terraform to OpenTofu — state compatibility, provider replacement, CI updates, feature differences.

Target user
Platform engineers evaluating OpenTofu adoption
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior platform engineer who has evaluated and migrated to OpenTofu (Terraform fork after BUSL relicense).

I will provide:
- Current Terraform version
- Migration goal
- Concerns

Your job:

1. **Why OpenTofu**:
   - Open source fork (HashiCorp Terraform → BUSL)
   - Apache 2.0 license
   - Backward compatible with Terraform 1.x
   - Community-driven
2. **For compatibility**:
   - State file format compatible
   - Provider compatibility (initially same registry)
   - Most code works unchanged
   - Some divergence over time
3. **For migration steps**:
   - Install OpenTofu (`tofu` binary)
   - Replace `terraform` calls with `tofu`
   - State works as-is
   - CI/CD updates
4. **For provider source migration**:
   - HashiCorp provider registry → OpenTofu registry (optional)
   - `terraform state replace-provider`
   - For tighter coupling: still use HashiCorp providers
5. **For CI updates**:
   - Replace binary
   - Most tooling (Atlantis, custom CI) supports both
6. **For feature divergence**:
   - OpenTofu may add features Terraform doesn't
   - And vice versa
   - Plan for compatibility floor
7. **For local dev**:
   - Engineers install `tofu`
   - Alias `terraform=tofu` if mixed
8. **For risks**:
   - Provider ecosystem split (unlikely but possible)
   - Tool support lag
   - Team familiarity

Mark DESTRUCTIVE: state migration without backup, mixing tofu and terraform on same state, provider migration without verification.

---

Current TF version: [DESCRIBE]
Migration goal: [DESCRIBE]
Concerns: [DESCRIBE]

Why this prompt works

Migration is a strategic decision. This prompt walks practicalities.

How to use it

  1. Test in non-prod first.
  2. State backup.
  3. CI updates carefully.
  4. Monitor for divergence.

Useful commands

# Install OpenTofu (Linux)
curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh
chmod +x install-opentofu.sh
./install-opentofu.sh --install-method standalone

# macOS
brew install opentofu

# Verify
tofu version

# Standard commands (same as terraform)
tofu init
tofu plan
tofu apply
tofu destroy

Migration steps

1. Local dev

# Install tofu
brew install opentofu

# Test on a sample
cd test-project
tofu init
tofu plan

# Should work identically to terraform plan

2. Update CI

# Before (GitLab CI)
plan:
  image: hashicorp/terraform:1.9
  script:
    - terraform init
    - terraform plan -out=tfplan

# After
plan:
  image: ghcr.io/opentofu/opentofu:1.8
  script:
    - tofu init
    - tofu plan -out=tfplan

3. Provider migration (optional)

# Backup state
tofu state pull > pre-migration.tfstate

# Replace AWS provider source (if migrating registry)
tofu state replace-provider \
    registry.terraform.io/hashicorp/aws \
    registry.opentofu.org/opentofu/aws

# Verify
tofu plan                            # should show no changes

4. Repo-level config

# Option A: keep HashiCorp providers (simplest)
terraform {
  required_version = ">= 1.5.0"      # tofu compatible

  required_providers {
    aws = {
      source  = "hashicorp/aws"      # still hashicorp registry
      version = "~> 5.0"
    }
  }
}

# Option B: switch to OpenTofu provider registry
terraform {
  required_version = ">= 1.5.0"

  required_providers {
    aws = {
      source  = "opentofu/aws"
      version = "~> 5.0"
    }
  }
}

5. Verify

# Run plan; should be identical
tofu plan -out=tfplan
tofu show tfplan | head -50

Decision matrix

ConcernStay on TerraformMigrate to OpenTofu
LicenseBUSL (production OK; some restrictions)Apache 2.0 (fully open)
VendorHashiCorpCommunity
FeaturesSome HashiCorp-onlySome OpenTofu-only
ToolingMatureCatching up
RiskEstablishedEvolving

Common findings this catches

  • State works as-is — good.
  • CI binary swap simple — image change.
  • Provider sources optional — keep HashiCorp’s if works.
  • No team training needed — same syntax.
  • Some scanners (Checkov) may need updates.
  • CDK for Terraform + alternatives.
  • Long-term divergence — periodic check.

When to escalate

  • License compliance — legal.
  • Org-wide adoption — coordinated.
  • Risk assessment — strategic.

Related prompts

Newsletter

Get weekly AI workflows for DevOps engineers

Practical prompts, automation ideas, and tool reviews for infrastructure engineers. One email per week. No spam.