OpenTofu: The Open Source Alternative to Terraform

OpenTofu: The Open Source Alternative to Terraform

After HashiCorp’s switch to the Business Source License (BSL) for Terraform, OpenTofu emerged as a community-driven, fully open-source alternative. This guide will help you understand OpenTofu, how to migrate from Terraform, and what differences to expect.

What is OpenTofu?

OpenTofu is a fork of Terraform that maintains the Apache 2.0 license. It’s supported by the Linux Foundation and backed by major companies like Gruntwork, Spacelift, and Harness. The project aims to maintain compatibility with existing Terraform configurations while ensuring the tool remains truly open source.

Installation

Installing OpenTofu

# macOS with Homebrew
brew tap opentofu/stable
brew install opentofu

# Verify installation
tofu version

# Manual installation for other platforms
# 1. Download the latest release from GitHub
curl -L https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_darwin_amd64.zip -o opentofu.zip

# 2. Unzip the package
unzip opentofu.zip

# 3. Move the binary to your PATH
sudo mv tofu /usr/local/bin/

Setting Up Shell Aliases (Optional)

To make the transition smoother, you can set up aliases in your shell:

# Add to ~/.zshrc or ~/.bashrc
alias tf="tofu"
alias terraform="tofu"

Migrating from Terraform

1. State Migration

OpenTofu is compatible with Terraform state files. You can continue using your existing state files:

# If using local state
cp terraform.tfstate tofu.tfstate

# For remote state, update your backend configuration
terraform {
  backend "s3" {
    bucket         = "my-terraform-state"
    key            = "global/s3/tofu.tfstate"  # Optional: rename state file
    region         = "us-west-2"
    dynamodb_table = "terraform-locks"
    encrypt        = true
  }
}

2. Configuration Updates

Most Terraform configurations work unchanged with OpenTofu. Here are the main areas to check:

  1. Provider Source Blocks ```hcl

    Previous Terraform configuration

    terraform { required_providers { aws = { source = “hashicorp/aws” version = “~> 5.0” } } }

OpenTofu configuration (remains the same for now)

terraform { required_providers { aws = { source = “hashicorp/aws” version = “~> 5.0” } } }


2. **Backend Configuration**
```hcl
# Both configurations currently work the same way
terraform {
  backend "s3" {
    bucket = "my-state-bucket"
    key    = "path/to/my/state"
    region = "us-west-2"
  }
}

3. Workflow Changes

The main commands remain the same, just replace terraform with tofu:

# Initialize working directory
tofu init

# Plan changes
tofu plan

# Apply changes
tofu apply

# Show state
tofu show

# Other common commands
tofu fmt
tofu validate
tofu workspace list
tofu state list

Key Differences from Terraform

1. Licensing

  • Terraform: Business Source License (BSL)
  • OpenTofu: Apache 2.0 License

2. Community Governance

  • Terraform: Controlled by HashiCorp
  • OpenTofu: Linux Foundation project with open governance

3. Provider Ecosystem

Currently, OpenTofu uses the same provider ecosystem as Terraform. However, there are plans to establish an independent provider registry in the future.

4. Enterprise Features

While Terraform Enterprise features are proprietary, OpenTofu is working on open-source alternatives:

  • Remote state storage
  • Team collaboration features
  • Policy as code
  • Remote execution

Best Practices for OpenTofu Usage

  1. Version Control
    terraform {
      required_version = ">= 1.6.0"
      required_providers {
     aws = {
       source  = "hashicorp/aws"
       version = "~> 5.0"
     }
      }
    }
    
  2. State Management
    • Continue using remote state
    • Implement state locking
    • Maintain backup procedures
  3. CI/CD Integration ```yaml

    Example GitHub Actions workflow

    name: OpenTofu CI

on: push: branches: [ main ] pull_request: branches: [ main ]

jobs: tofu: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3

  - name: Setup OpenTofu
    uses: opentofu/setup-opentofu@v1
    with:
      tofu_version: "1.6.0"
  
  - name: OpenTofu Init
    run: tofu init
  
  - name: OpenTofu Format Check
    run: tofu fmt -check
  
  - name: OpenTofu Plan
    run: tofu plan ```

Future Developments

The OpenTofu community is working on several enhancements:

  1. Independent provider registry
  2. Enhanced testing frameworks
  3. Improved documentation system
  4. Community-driven feature development
  5. Cloud-agnostic remote operations

Making the Decision

Consider these factors when choosing between Terraform and OpenTofu:

Choose OpenTofu if:

  • Open source licensing is critical
  • You want community-driven development
  • You need to modify the source code
  • You’re concerned about future licensing changes

Stay with Terraform if:

  • You rely on HashiCorp’s enterprise features
  • You need official HashiCorp support
  • Your organization requires vendor backing

Conclusion

OpenTofu provides a viable open-source alternative to Terraform, maintaining compatibility while ensuring the future of infrastructure as code remains in the hands of the community. Whether you choose to migrate or not depends on your specific needs, but OpenTofu is positioning itself as a robust option for those who value open-source software.

Additional Resources

Remember to stay updated with the OpenTofu project as it continues to evolve and potentially diverge from Terraform in the future.

Written on July 13, 2025