Terraform VSCode Extension: Syntax Highlighting, Autocomplete, and Formatting
Install and configure the HashiCorp Terraform VSCode extension. Enable syntax highlighting, autocomplete, format on save, validation
Software Development
Enable Terraform tab autocomplete in Bash, Zsh, and Fish. One command setup, troubleshooting, and what gets auto-completed (subcommands, flags
One command enables autocomplete for your shell:
terraform -install-autocompleteThen restart your shell:
exec $SHELL # Or close and reopen your terminalNow press Tab after typing terraform and subcommands auto-complete.
After enabling autocomplete:
terraform pl<Tab> → terraform plan
terraform ap<Tab> → terraform apply
terraform st<Tab> → terraform state
terraform state l<Tab> → terraform state list
terraform state s<Tab> → terraform state show
terraform w<Tab> → terraform workspaceTerraform autocomplete covers:
init, plan, apply, destroy, state, workspace, etc.-auto-approve, -target, -var, -var-file, etc.state list, state show, state mv, workspace new, etc.# Install autocomplete (adds to ~/.bashrc)
terraform -install-autocomplete
# Restart shell
exec bashWhat it adds to ~/.bashrc:
complete -C /usr/local/bin/terraform terraformThis tells Bash to use the terraform binary itself for completion suggestions.
Manual install (if the auto-install doesn't work):
echo 'complete -C /usr/local/bin/terraform terraform' >> ~/.bashrc
source ~/.bashrcReplace /usr/local/bin/terraform with the actual path — find it with which terraform.
# Install autocomplete (adds to ~/.zshrc)
terraform -install-autocomplete
# Restart shell
exec zshWhat it adds to ~/.zshrc:
autoload -U +X bashcompinit && bashcompinit
complete -C /usr/local/bin/terraform terraformManual install:
cat >> ~/.zshrc << 'EOF'
autoload -U +X bashcompinit && bashcompinit
complete -C /usr/local/bin/terraform terraform
EOF
source ~/.zshrcFish shell requires a different approach since it doesn't use complete -C:
# Create the completion file
terraform -install-autocompleteIf that doesn't work for Fish, install the community completions:
# Using Fisher
fisher install lgathy/google-cloud-sdk-fish-completion
# Or manually create completions
mkdir -p ~/.config/fish/completions
# Add terraform completionsOn macOS, Bash uses ~/.bash_profile instead of ~/.bashrc by default. If autocomplete doesn't work:
# Check which file your shell loads
echo $SHELL
# For macOS Bash (before Catalina)
echo 'complete -C /usr/local/bin/terraform terraform' >> ~/.bash_profile
source ~/.bash_profile
# For macOS Zsh (Catalina and later, default shell)
terraform -install-autocomplete # Writes to ~/.zshrc
exec zshAfter installation:
terraform <Tab><Tab>You should see a list of all Terraform subcommands:
apply console fmt get import
init login logout output plan
providers refresh show state taint
test untaint validate version workspace
destroy force-unlock graph metadata Check the terraform path:
which terraform
# /usr/local/bin/terraformMake sure the path in your shell config matches:
grep terraform ~/.bashrc # or ~/.zshrc
# complete -C /usr/local/bin/terraform terraformIf the paths don't match, update the complete -C line.
Missing bashcompinit. Add this before the complete line:
autoload -U +X bashcompinit && bashcompinitError installing autocomplete: already installed in /home/user/.bashrcAutocomplete is already set up. Just restart your shell:
exec $SHELLThe complete -C path may point to the old binary. Update it:
# Remove old entry
terraform -uninstall-autocomplete
# Reinstall
terraform -install-autocomplete
exec $SHELLMake sure your shell config file is sourced in non-login shells. Add to ~/.bashrc (not just ~/.bash_profile).
terraform -uninstall-autocomplete
exec $SHELLIf you use a Terraform alias, add completion for it too:
# In ~/.bashrc or ~/.zshrc
alias tf="terraform"
complete -C /usr/local/bin/terraform tfNow tf pl<Tab> completes to tf plan.
Learn by doing with interactive courses on CopyPasteLearn:
Run terraform -install-autocomplete and restart your shell. That's it. Works with Bash, Zsh, and Fish. If you use a tf alias, add complete -C $(which terraform) tf to your shell config. Tab completion saves time and prevents typos on every Terraform command.
Install and configure the HashiCorp Terraform VSCode extension. Enable syntax highlighting, autocomplete, format on save, validation
Use LocalStack with Terraform to test AWS infrastructure locally. Create S3 buckets, DynamoDB tables, and Lambda functions without AWS costs or credentials.
Deploy AWS CloudFront distributions with Terraform. S3 origin, ALB origin, custom domains, SSL certificates, cache policies, and WAF integration.
Deploy AWS ElastiCache Redis with Terraform. Cluster mode, replication groups, subnet groups, encryption, and parameter group configuration.