tofu(1)
OpenTofu is an infrastructure as code tool for building, changing, and versioning infrastructure safely and efficiently.
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
| Flag | What it does |
|---|---|
-chdir=PATH | Switch to a different directory before executing the command |
-help | Show help message for the command or subcommand |
-version | Display the OpenTofu version |
-var 'key=value' | Set a variable value from the command line |
-var-file=FILE | Load variable values from an HCL or JSON file |
-auto-approve | Skip interactive approval of plan (use carefully in production) |
-compact-warnings | Show warnings in compact form |
-lock=true|false | Enable or disable state locking during operations |
-parallelism=n | Limit the number of parallel operations (default: 10) |
-input=true|false | Ask for input for variables if not directly set |
Examples
Initialize a working directory, download providers, and set up backend storage
tofu initShow what changes would be made to reach the desired state (dry-run)
tofu planCreate or update infrastructure to match the configuration
tofu applyApply changes without prompting for interactive approval
tofu apply -auto-approveDestroy all infrastructure managed by this configuration
tofu destroyGenerate a plan with custom variables and save it to a file
tofu plan -var 'region=us-west-2' -out=plan.tfplanFormat all HCL files in the current directory and subdirectories
tofu fmt -recursiveDisplay all resources currently managed in the state file
tofu state list