Skip to main content
Now that you know the core Terraform CLI commands, this guide shows how to help yourself when you get stuck. Terraform ships several helpful, built-in features you can use directly from the terminal: shell autocomplete, contextual CLI help, and automatic code formatting. These improve productivity, reduce errors, and make collaborating across teams easier.

Autocomplete

Shell autocomplete lets your terminal predict and complete Terraform commands, subcommands, and flags as you type. This reduces typos and speeds up workflows. Install autocomplete for your current shell with the installer:
After running the installer, restart your terminal or reload your shell configuration (for example source ~/.bashrc or source ~/.zshrc) so the completion scripts take effect.
If you use Zsh, make sure you create or update ~/.zshrc instead of ~/.bashrc. Restart or reload your shell after installing autocomplete to enable completions.
Once enabled, type part of a command and press Tab to view suggestions:
Your shell will show available matches:

Built-in CLI help

Terraform’s CLI provides contextual, on-demand help for every command and flag. When you need quick guidance, use the global help or target a specific subcommand. General help:
Example (truncated) output for global help:
Help for any specific command:
This prints a description of what terraform plan does and lists all its available flags and options:
Start with terraform --help or terraform <subcommand> --help for fast, accurate guidance in the terminal. For deeper examples, tutorials, and full reference material, consult the official documentation at developer.hashicorp.com/terraform.

Formatting code with terraform fmt

Terraform includes terraform fmt to reformat configuration files to a canonical, consistent style across your repository. Use it locally or in CI to enforce a shared style and make diffs easier to review. Example resource before formatting:
Run terraform fmt in a directory to rewrite .tf files with Terraform’s canonical formatting:
Use terraform fmt -check in CI pipelines to fail the build when files are not formatted, ensuring contributors run the formatter before opening pull requests.
A purple presentation slide titled "Making the Most of the Terraform CLI." It shows the subtitle "Easily Format Your Code To a Canonical Format and Style" and a HashiCorp Terraform logo in the top corner.
When adding terraform fmt -check to CI, ensure contributors run terraform fmt locally (or integrate it into pre-commit hooks) to avoid blocking pull requests with formatting-only changes.

Quick reference table

Summary

  • Enable shell autocomplete with terraform -install-autocomplete and reload your shell to speed up command entry and reduce errors.
  • Use terraform --help and terraform <subcommand> --help for fast, contextual, terminal-native documentation.
  • Use terraform fmt and terraform fmt -recursive to automatically format Terraform configuration files; add terraform fmt -check to CI to enforce formatting standards.

Watch Video