Here is some CLI shortcuts I use day-to-day to simplify and speed-up my Terraform workflow. Requirements — bash-compatible interpreter, because aliases and functions described below will work with bash, zsh and ohmyzsh.

In order to use any of described aliases of functions, you need to place it in your ~/.bashrc or ~/.zshrc file (or any other configuration file you have for your shell).

Then just source this file, for example: source ~/.zshrc

Function: list outputs and variables of given module

You need to provide the path to module directory, and this function will list all declared variables and outputs module has. It comes very useful when you don’t remember them all and just need to take a quick look.

# TerraForm MOdule Explained
function tfmoe {
  echo -e "\nOutputs:"
  grep -r "output \".*\"" $1 |awk '{print "\t",$2}' |tr -d '"'
  echo -e "\nVariables:"
  grep -r "variable \".*\"" $1 |awk '{print "\t",$2}' |tr -d '"'

Example usage:

[email protected] $: tfmoe ./module_alb



Function: pre-fill module directory with configuration files

You need to provide a path to the module directory and this function will create a bunch of empty ‘default’ .tf files in it.

#TerraForm MOdule Initialize
function tfmoi {
  touch $1/
  touch $1/
  touch $1/
  touch $1/

Example usage:

[email protected] $: mkdir ./module_foo && temoi $_

[email protected] $: ls ./module_foo


The purpose of these aliases is just to keep you from typing long commands when you want to do a simple action.

alias tf='terraform'

alias tfv='terraform validate'

alias tfi='terraform init'

alias tfp='terraform plan' 

This one is useful because it makes format tool to go in-depth (recursively) through directories.

alias tfm='terraform fmt -recursive'

Example usage:

[email protected] $: tfm