Skip to main content
Terraform includes several built-in CLI conveniences—autocomplete, comprehensive help, and automatic formatting—that help you stay productive without leaving your terminal. This guide walks through enabling and using these features so you can discover commands, reduce typos, and keep configuration style consistent.

Autocomplete: speed up typing and reduce errors

Shell autocomplete lets your shell predict and complete Terraform commands, subcommands, flags, and file paths as you type. If you already have shell completion enabled, this is a quick review. If not, enabling it consolidates useful CLI ergonomics in one place.
The image is a promotional graphic for using auto-complete with the Terraform CLI, explaining that tab completion aids in filling subcommands, flags, and file paths by pressing the Tab key. It features geometric lines and logos on a dark background.
Install autocomplete for your shell with:
If your shell configuration file does not exist, create it first (example for bash):
After installing autocomplete, reload your shell configuration (for example, source ~/.bashrc or source ~/.zshrc) or restart the terminal to activate completion.
Usage example: type a partial command then press Tab. Typing terraform s and pressing Tab will present matching subcommands:
Autocomplete is especially helpful for remembering long flag names, provider-specific subcommands, and relative file paths.

Built-in help: discover commands and flags

Terraform ships contextual help at both the global and subcommand levels. Use --help to view available commands, flags, and short explanations without leaving your terminal. Global overview:
Per-command help provides detailed flag descriptions and usage examples. For example:
Use per-command help whenever you need to confirm a flag name, understand an option’s effect, or find switches for advanced behavior.
For extended guides, examples, and tutorials, see the official Terraform documentation: developer.hashicorp.com/terraform.

Formatting with terraform fmt

Consistent formatting improves readability and reduces diffs in commits. terraform fmt rewrites Terraform configuration files to the canonical style. Example of a compact resource before formatting:
Run terraform fmt in the working directory:
To format files in subdirectories as well, use the recursive flag:
Notes:
  • By default, terraform fmt processes files in the current directory only.
  • Add -recursive to traverse and format nested directories.

Quick command reference

Summary

  • Enable autocomplete with terraform -install-autocomplete to speed up typing and reduce errors.
  • Use terraform --help and terraform <subcommand> --help for quick, contextual CLI documentation.
  • Keep Terraform code consistent with terraform fmt; add -recursive to format nested directories.
These built-in tools make it easy to discover commands, confirm flag behavior, and maintain consistent configuration style—all without leaving your terminal.

Watch Video