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:
$ terraform -install-autocomplete
If your shell configuration file does not exist, create it first (example for bash):
$ touch ~/.bashrc
$ terraform -install-autocomplete
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:
$ terraform s<TAB>
show    state
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:
$ terraform --help
Usage: terraform [global options] <subcommand> [args]

The available commands for execution are listed below.
The primary workflow commands are given first, followed by
less common or more advanced commands.

Main commands:
  init      Prepare your working directory for other commands
  validate  Check whether the configuration is valid
  plan      Show changes required by the current configuration
  apply     Create or update infrastructure
  destroy   Destroy previously-created infrastructure
  ...
Per-command help provides detailed flag descriptions and usage examples. For example:
$ terraform plan --help
Usage: terraform [global options] plan [options]

Generates a speculative execution plan, showing what actions Terraform
would take to apply the current configuration. This command will not
actually perform the planned actions.

You can optionally save the plan to a file, which you can then pass to
the "apply" command to perform exactly the actions described in the plan.

Plan Customization Options:
  -destroy        Select the "destroy" planning mode, which creates a plan
                  to destroy all objects currently managed by this
                  configuration.
  ...
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:
resource "aws_instance" "example" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"
  tags = { Name = "example" }
}
Run terraform fmt in the working directory:
$ terraform fmt
To format files in subdirectories as well, use the recursive flag:
$ terraform fmt -recursive
Notes:
  • By default, terraform fmt processes files in the current directory only.
  • Add -recursive to traverse and format nested directories.

Quick command reference

CommandPurposeExample
terraform -install-autocompleteEnable shell autocomplete for Terraformterraform -install-autocomplete
terraform --helpShow global command list and usageterraform --help
terraform <subcommand> --helpShow options for a specific subcommandterraform plan --help
terraform fmtReformat configuration files in current directoryterraform fmt
terraform fmt -recursiveReformat files in current directory and subdirectoriesterraform fmt -recursive

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