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.
After installing autocomplete, reload your shell configuration (for example,
source ~/.bashrc or source ~/.zshrc) or restart the terminal to activate completion.terraform s and pressing Tab will present matching subcommands:
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:
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:
terraform fmt in the working directory:
- By default,
terraform fmtprocesses files in the current directory only. - Add
-recursiveto traverse and format nested directories.
Quick command reference
| Command | Purpose | Example |
|---|---|---|
terraform -install-autocomplete | Enable shell autocomplete for Terraform | terraform -install-autocomplete |
terraform --help | Show global command list and usage | terraform --help |
terraform <subcommand> --help | Show options for a specific subcommand | terraform plan --help |
terraform fmt | Reformat configuration files in current directory | terraform fmt |
terraform fmt -recursive | Reformat files in current directory and subdirectories | terraform fmt -recursive |
Summary
- Enable autocomplete with
terraform -install-autocompleteto speed up typing and reduce errors. - Use
terraform --helpandterraform <subcommand> --helpfor quick, contextual CLI documentation. - Keep Terraform code consistent with
terraform fmt; add-recursiveto format nested directories.
Links and references
- Official Terraform documentation: https://developer.hashicorp.com/terraform