tofu commands to validate, format, visualize, and apply your configurations.
OpenTofu Command Overview
1. Validate Configuration
Usetofu validate to check your HCL files for syntax errors and internal consistency. It flags errors with precise file and line numbers.
When validation fails, OpenTofu highlights the incorrect attribute. For example, replace
file permission with file_permission to match HCL naming conventions.2. Format HCL Files
Thetofu fmt command enforces a consistent style across all .tf files in the current directory, handling indentation, alignment, and spacing automatically.
3. Show Infrastructure State
tofu show prints the current state stored by OpenTofu. Add --json for a machine-readable output.
4. Providers
tofu providers lists providers declared in your configuration versus those recorded in the state file.
5. Outputs
Usetofu output to inspect all declared outputs or fetch a single output by name.
6. Refresh and Plan
By default,tofu plan and tofu apply refresh the state before execution. To update only the state file without planning or applying, run:
7. Dependency Graph
Generate a dependency graph in DOT format usingtofu graph. You can then visualize it with GraphViz:
Save the DOT output (e.g.,
graph.dot) and render it with: