Skip to content

OpenTofu: Introduction & Getting Started

OpenTofu is an open-source infrastructure as code (IaC) tool, forked from Terraform, designed to provision and manage cloud and on-premises resources declaratively.

Why Use OpenTofu?

  • Open-source alternative to Terraform
  • Manage infrastructure as code across multiple providers
  • Declarative, version-controlled infrastructure

How OpenTofu Works

  • Uses HCL (HashiCorp Configuration Language) for configuration files
  • Providers enable support for different platforms (AWS, Azure, etc.)
  • State files track resource status

Quick Start Example

  1. Install OpenTofu:
    curl -sSfL https://get.opentofu.org/install.sh | sh
    tofu --version
    
  2. Write a simple configuration (main.tf):
    terraform {
      required_providers {
        random = {
          source = "hashicorp/random"
        }
      }
    }
    
    provider "random" {}
    
    resource "random_pet" "name" {}
    
    output "pet_name" {
      value = random_pet.name.id
    }
    
  3. Initialize and apply:
    tofu init
    tofu apply
    

Learn More