Skip to content

ecaminero/terraform-aliases

Repository files navigation

terraform-aliases

This repository contains a script to generate hundreds of convenient shell aliases for terraform, so you no longer need to spell out every single command and --flag over and over again.

An example shell alias created from command/flags permutation looks like:

alias tfprefnoc='terraform plan -refresh-only -no-color'

Confused? Read on.

Examples

Some of the 200 generated aliases are:

alias tf='terraform'
alias tfi='terraform init'

alias tfp='terraform plan'
alias tfa='terraform apply'

alias tfws='terraform workspace'
alias tfwsls='terraform workspace list'
alias tfwsse='terraform workspace select'
alias tfwsnw='terraform workspace new'
alias tfwssh='terraform workspace show'
...

See the full list.

Installation

You can directly download the .terraform_aliases file for bash/zsh or the .terraform_aliases.fish file for fish and save it to your $HOME directory.

Bash/Zsh

Add the following to your .bashrc/.zshrc file:

[ -f ~/.terraform_aliases ] && source ~/.terraform_aliases

Fish

Add the following to your ~/.config/fish/config.fish file:

test -f ~/.terraform_aliases.fish && source ~/.terraform_aliases.fish

This actually adds the more powerful fish abbreviations instead of aliases, so that pressing space shows the full command before execution.

Syntax explanation

  • tf=terraform
  • commands:
    • i=init
    • p=plan
    • a=apply
    • ws:workspace
    • wsls:workspace list

Running the script

The script has only one optional argument, the shell to which the aliases will be generated. If not given, it assumes bash. Ex:

# Generate aliases for bash/zsh
python generate_aliases.py > .terraform_aliases

# Generate abbr for fish
python generate_aliases.py fish > .terraform_aliases.fish

FAQ

  • Doesn't this slow down my shell start up? Sourcing the file that contains ~500 aliases takes about 30-45 milliseconds in my shell (zsh). I don't think it's a big deal for me. Measure it with echo $(($(date +%s%N)/1000000)) command yourself in your .bashrc/.zshrc.

  • Can I add more Terraform resource types to this? Please consider forking this repo and adding the resource types you want. Not all resource types are used by everyone, and adding more resource types slows down shell initialization see above).

Authors

Inspired by