The OpenTofu CLI is a command-line interface for managing infrastructure as code using the OpenTofu framework, a community-driven fork of Terraform. It allows users to define, provision, and manage infrastructure across multiple cloud providers using declarative configuration files.
If youβve used Terraform before, youβll feel right at home. OpenTofu mirrors much of the same functionality β commands like init, plan, apply, and destroy work just as you expect. You also get state management, resource graphing, and execution planning built right in.
In this OpenTofu CLI cheat sheet, youβll find:
Want to go beyond the basics? Check out our OpenTofu tutorial or learn how to manage OpenTofu at scale.
To install OpenTofu, download the binary from the official releases and add it to your systemβs PATH. Below are the installation steps:
- Visit the OpenTofu GitHub Releases and download the appropriate archive for your OS and architecture (e.g.,
opentofu_linux_amd64.zip). - Unzip the archive and move the
tofubinary to a directory in yourPATH, such as/usr/local/bin:
unzip opentofu_linux_amd64.zip
sudo mv tofu /usr/local/bin/
chmod +x /usr/local/bin/tofu- Confirm itβs installed by running
tofu version.
Alternatively, you can install it via package managers like Homebrew (macOS/Linux) using:
brew install opentofuFor full platform support, see the installation docs.
The basic commands for the OpenTofu CLI follow the same structure as Terraform and include initialization, validation, planning, application, and destruction of infrastructure configurations. These are the core commands youβll use most often.
tofu init βΒ Initializes the working directory, downloads providers, and configures the backen
tofu validate βΒ Checks your configuration for syntax and logical errors
tofu plan β Previews what changes will happen before you apply them
tofu apply β Executes the plan and applies changes to reach the desired state. It can optionally take a plan file.
tofu destroy β Removes all defined resources, effectively tearing down the infrastructure
tofu fmt β Formats your configuration files for consistency
tofu show β Displays the current state or a saved plan in a human-readable format
tofu import β Brings existing infrastructure resources under management by importing them into state
The OpenTofu CLI tracks deployed resources using a state file. These commands help you inspect, update, or repair that state.
tofu state list β Lists all resources tracked in the current state file
tofu state show <address> β Displays detailed information about a specific resource in the state
tofu state mv <source> <destination> β Moves or renames resources within the state file without modifying infrastructure
tofu state rm <address> β Removes a resource from the state (for example, if you deleted it manually)
tofu state pull β Downloads the entire state file from a remote backend
tofu state push β Releases a stale state lock when an operation has failed or timed out
Note: OpenTofu automatically creates a backup state file when modifying state.
Workspaces allow you to isolate environments, such as development, staging, and production, under the same configuration. Each workspace maintains its own state, making it easy to manage multiple environments in parallel.
The primary workspace management commands are:
tofu workspace list β Lists all existing workspaces
tofu workspace show β Displays the currently active workspace
tofu workspace new <name> β Creates a new workspace with the specified name
tofu workspace select <name> β Switches to an existing workspace
tofu workspace delete <name> β Deletes a workspace and its associated state
Modules let you reuse configuration blocks across projects. OpenTofu doesnβt have many module-specific commands beyond get, but these are the key ones for managing and updating modules:
tofu get β Downloads modules declared in the configuration
tofu get -update β Re-downloads modules even if already present
tofu init β Also retrieves modules as part of initialization
These commands primarily support configuration consistency, dependency management, and secure remote operations, complementing OpenTofuβs core workflow commands.
tofu output β Displays values defined as outputs in your configuration
tofu graph β Generates a dependency graph in DOT format for visualization
tofu providers β Lists required providers and their sources
tofu providers lock β Creates or updates the dependency lock file to ensure consistent provider versions
tofu login β Authenticates with a remote backend or registry, if supported
tofu logout β Removes stored credentials from previous logins
tofu version β Shows the current OpenTofu version and build details
tofu test β Runs infrastructure tests and assertions defined in the configuration
tofu console β Opens an interactive console for evaluating expressions and testing configurations
Each OpenTofu command supports a range of flags and options to adjust behavior, control output, and fine-tune execution. Below are the most common ones by command.
tofu init
-backend=falseβ Skips backend configuration-upgradeβ Upgrades providers and modules-reconfigureβ Ignores previous backend settings and reinitializes configuration-migrate-stateβ Migrates existing state to a new backend configuration-force-copyβ Force copy of existing state when reinitializing-backend-config=FILEβ Specify backend configuration files or key=value pairs (see documentation for more info)-input=falseβ Disables prompts in CI-from-module=SOURCEβ Scaffolds an empty dir from a module repo then init-get=falseβ Skips downloading child modules (handy in pre-seeded builds)-plugin-dir=PATHβ Uses only local provider pluginsΒ-lockfile=readonlyβ Verifies dependency lockfile without modifying it
tofu plan
-out=FILEβ Saves the plan to a file for later use withapply-var 'key=value'β Sets a variable inline-var-file=FILEβ Loads variables from a.tfvarsfile-input=falseβ Disables interactive input prompts- -target=RESOURCE β Plans only the specified resource(s)
-destroyβ Creates a plan to destroy resources-replace=RESOURCEβ Forces replacement of a specific resource-refresh-onlyβ plan that only refreshes state/outputs-refresh=falseβ skips the pre-plan refresh (faster, use with care)-detailed-exitcodeβ CI-friendly exit codes (0/1/2)-target-file=FILEβ Provides multiple target addresses from a file.-exclude=ADDRESS/-exclude-file=FILEβ Omits specified addresses-jsonβ Outputs machine-readable JSON results
tofu apply
-auto-approveβ Skips interactive approval-input=falseβ Prevents prompts for inputFILEβ If provided, applies a plan file generated by plan-replace=RESOURCEβ Forces replacement of resources during apply-lock/ -lock-timeout=DURATION β Controls state locking-parallelism=Nβ Sets number of parallel operations-jsonβ Outputs machine-readable JSON results-no-color/ -concise β Cleaner logs in CI-show-sensitiveβ Shows unredacted sensitive values (use carefully)-deprecation=module:{all|local|none}β Tunes deprecation warnings
tofu destroy
-auto-approveβ Destroys resources without confirmation-target=RESOURCEβ Destroys only specified resource(s)-var/ –var-file/-input=falseβ Supported same as plan/apply
tofu validate
-jsonβ Returns validation results as JSON for programmatic use-no-colorβ Produces plain output-var/-var-fileβ Sets variables if configuration references them
tofu fmt
-recursiveβ Recursively formats all .tf files in subdirectories-checkβ Checks formatting without changing files-write=falseβ Performs a dry run format check-list=falseβ Doesnβt print filenames needing changes-diffβ Shows diffs of what would change
Global options (apply to any command)
-chdir=DIRβ Runs command in another directory-helpβ Displays command help-versionβ Shows CLI version information
Note: This is not a complete list. For all options, see the official documentation.
Here are some known deprecated or discouraged commands/options in OpenTofu (or things flagged as deprecated / legacy):
tofu refresh β deprecated because it directly updates the state without opportunity to review changes; using tofu apply -refresh-only is now preferred
tofu taint β deprecated; recommended alternative is tofu apply -replace="β¦"; tofu untaint remains supported and is not deprecated
tofu env β deprecated, replaced by tofu workspace
Spacelift is an infrastructure orchestration platform that supports both OpenTofu and Terraform, as well as other tools such as Pulumi, CloudFormation, Terragrunt, Ansible, and Kubernetes. Spacelift offers a variety of features that map easily to your OpenTofu and Terraform workflow.
Spacelift stacks enable you to plug in the VCS repository containing your Terraform and OpenTofu configuration files and do a GitOps workflow for them.Β
At the stack level, you can add a variety of other components that will influence this GitOps workflow, such as:
- Policies control the kind of resources engineers can create, their parameters, the number of approvals you need for runs, where to send notifications, and more.
- Stack dependencies allow you to build dependencies between your configurations and even share outputs between them. There are no constraints on creating dependencies between multiple tools or the number of dependencies you can have.
- Cloud integrations are dynamic credentials for major cloud providers (AWS, Microsoft Azure, Google Cloud).
- Contexts are shareable containers for your environment variables, mounted files, and lifecycle hooks.
- Drift detection allows you to detect infrastructure drift easily and optionally remediate it.
- Resources view provides enhanced observability of all resources deployed with your Spacelift account.
If you need help migrating from Terraform to OpenTofu or are looking for an infrastructure management platform that supports the top flavors of infrastructure as code, configuration management, and container orchestration, contact Spacelift.
As a founding partner of the initiative, Spacelift offers the native and commercial support you need to ensure your OpenTofu success. Learn more about OpenTofu Commercial Support & Services.
OpenTofu makes managing infrastructure simple, predictable, and fully open source. With just a few commands, you can plan, deploy, and manage your environments much like Terraform β but without vendor lock-in.
Keep this cheat sheet nearby as a quick reference. As you get more comfortable, explore automation through CI/CD pipelines or modular workflows for more complex setups.
If you want to improve your OpenTofu workflow, Spacelift can help. Create a free account today or schedule a demo with one of our engineers.
OpenTofu Commercial Support
Spacelift offers native and commercial support to ensure your OpenTofu success. If you need a reliable partner to run your critical workloads with OpenTofu, accelerate your migration, provide support coverage, or train your team β we are here to help.
