DEV Community

Alex Spinov
Alex Spinov

Posted on

OpenTofu Has a Free API — The Open-Source Terraform Alternative

OpenTofu is the community-driven fork of Terraform, created after HashiCorp switched to a BSL license. It's 100% compatible with Terraform 1.5.x and fully open-source under MPL-2.0.

Why OpenTofu?

  • Truly open source — MPL-2.0 license, backed by Linux Foundation
  • Drop-in replacement — compatible with existing Terraform code
  • State encryption — built-in, not available in Terraform
  • Community-driven — features decided by users, not a corporation

Quick Start

# Install (macOS)
brew install opentofu

# Install (Linux)
curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh | sh

# Verify
tofu --version
Enter fullscreen mode Exit fullscreen mode

Basic Configuration

# main.tf
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

provider "aws" {
  region = "us-east-1"
}

resource "aws_instance" "web" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t3.micro"

  tags = {
    Name = "web-server"
  }
}
Enter fullscreen mode Exit fullscreen mode
tofu init
tofu plan
tofu apply
Enter fullscreen mode Exit fullscreen mode

State Encryption (OpenTofu Exclusive!)

terraform {
  encryption {
    key_provider "pbkdf2" "mykey" {
      passphrase = var.state_passphrase
    }
    method "aes_gcm" "encrypt" {
      keys = key_provider.pbkdf2.mykey
    }
    state {
      method = method.aes_gcm.encrypt
    }
    plan {
      method = method.aes_gcm.encrypt
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

This encrypts your state file at rest — critical for teams storing state in S3 or other backends.

Migrating from Terraform

# 1. Rename binary usage
alias terraform=tofu

# 2. Initialize (downloads providers)
tofu init

# 3. Verify state
tofu plan
# Should show "No changes"
Enter fullscreen mode Exit fullscreen mode

No code changes needed. All existing Terraform providers work with OpenTofu.

Modules Work Identically

module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "5.0.0"

  name = "production"
  cidr = "10.0.0.0/16"
  azs  = ["us-east-1a", "us-east-1b"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24"]
}
Enter fullscreen mode Exit fullscreen mode

Testing with tofu test

# tests/main.tftest.hcl
run "creates_instance" {
  command = plan

  assert {
    condition     = aws_instance.web.instance_type == "t3.micro"
    error_message = "Wrong instance type"
  }
}
Enter fullscreen mode Exit fullscreen mode
tofu test
Enter fullscreen mode Exit fullscreen mode

Managing infrastructure for scraping at scale? Check out my Apify actors — production-ready scrapers that handle infrastructure for you. Email spinov001@gmail.com for custom solutions.

Have you migrated from Terraform to OpenTofu? Share your experience!

Top comments (0)