Skip to main content

How to manage infrastructure with OpenTofu

Install OpenTofu and run the init, plan, and apply workflow as an open-source, HCL-compatible alternative to Terraform that runs most existing configs unchanged.

Difficulty
Beginner
Duration
40 minutes
Steps
6

What and why

OpenTofu is an open-source, community-governed fork of Terraform under the Linux Foundation. It uses the same HCL configuration language and a compatible workflow, so most existing Terraform code runs unchanged. This tutorial provisions infrastructure with the tofu CLI.

Prerequisites

  • A cloud account with credentials available in your environment.
  • Basic command-line skills.
  • Familiarity with HCL is helpful but not required.

Steps

1. Install OpenTofu

Install using the official installer or your package manager, then confirm:

tofu version

The binary is tofu, mirroring the terraform command.

2. Write a configuration

Create main.tf:

terraform {
  required_providers {
    aws = { source = "hashicorp/aws", version = "~> 5.0" }
  }
}

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

resource "aws_s3_bucket" "demo" {
  bucket = "acme-opentofu-demo"
}

The terraform block name is retained for compatibility.

3. Initialize the working directory

tofu init

This downloads the provider and prepares the backend, exactly like terraform init.

4. Plan and apply

tofu plan
tofu apply

Review the plan and confirm. OpenTofu creates the resources and writes state.

5. Inspect state

tofu state list
tofu output

State commands match Terraform's, so muscle memory transfers directly.

Verification

Run tofu plan again; it should report no changes. Check the resource in your cloud console. Existing Terraform .tf files placed in the directory should also work without edits.

Next Steps

Point your CI to call tofu instead of terraform. Configure a remote backend the same way you would in Terraform. Review OpenTofu-specific features such as state encryption when you need them.

Prerequisites

  • A cloud account with credentials
  • Basic command line skills
  • Familiarity with HCL is helpful

Steps

  • 1
    Install OpenTofu
  • 2
    Write a configuration
  • 3
    Initialize the working directory
  • 4
    Plan and apply
  • 5
    Inspect state
  • 6
    Verify and clean up