$linuxjunkies
>

tofu(1)

OpenTofu is an infrastructure as code tool for building, changing, and versioning infrastructure safely and efficiently.

UbuntuDebianFedoraArch

Synopsis

tofu [GLOBAL OPTIONS] COMMAND [OPTIONS] [ARGUMENTS]

Description

OpenTofu is an open-source infrastructure as code (IaC) tool that lets you define cloud and on-premises resources using declarative configuration files. It manages the full lifecycle of infrastructure—creating, updating, and destroying resources across multiple cloud providers and services.

Tofu reads configuration files written in HCL (HashiCorp Configuration Language) and determines what actions need to be taken to reach the desired state. It maintains a state file to track resource metadata and dependencies.

Common options

FlagWhat it does
-chdir=PATHSwitch to a different directory before executing the command
-helpShow help message for the command or subcommand
-versionDisplay the OpenTofu version
-var 'key=value'Set a variable value from the command line
-var-file=FILELoad variable values from an HCL or JSON file
-auto-approveSkip interactive approval of plan (use carefully in production)
-compact-warningsShow warnings in compact form
-lock=true|falseEnable or disable state locking during operations
-parallelism=nLimit the number of parallel operations (default: 10)
-input=true|falseAsk for input for variables if not directly set

Examples

Initialize a working directory, download providers, and set up backend storage

tofu init

Show what changes would be made to reach the desired state (dry-run)

tofu plan

Create or update infrastructure to match the configuration

tofu apply

Apply changes without prompting for interactive approval

tofu apply -auto-approve

Destroy all infrastructure managed by this configuration

tofu destroy

Generate a plan with custom variables and save it to a file

tofu plan -var 'region=us-west-2' -out=plan.tfplan

Format all HCL files in the current directory and subdirectories

tofu fmt -recursive

Display all resources currently managed in the state file

tofu state list

Related commands