Home

Awesome

GitHub pre-commit Release

zsh-terraform

zsh plugin for Terraform, a tool from Hashicorp for managing infrastructure safely and efficiently.

This plugins extends original oh-my-zsh plugin with aliases, functions and autocompletion.

It will also install and load some useful tools :

Table of content

This documentation section is generated automatically

<!--TOC--> <!--TOC-->

Requirements

You can install, manage different terraform versions using terraform for example

Usage

Bundle zsh-terraform in your .zshrc

antigen bundle ptavares/zsh-terraform

Load zsh-terraform as a plugin in your .zshrc

zplug "ptavares/zsh-terraform"

Include the load command in your .zshrc

zget load ptavares/zsh-terraform

Clone zsh-terraform into your custom plugins repo and load as a plugin in your .zshrc

git clone https://github.com/ptavares/zsh-terraform.git ~/.oh-my-zsh/custom/plugins/zsh-terraform
plugins+=(zsh-terraform)

Keep in mind that plugins need to be added before oh-my-zsh.sh is sourced.

Clone this repository somewhere (~/.zsh-terraform for example) and source it in your .zshrc

git clone https://github.com/ptavares/zsh-terraform ~/.zsh-terraform
source ~/.zsh-terraform/zsh-terraform.plugin.zsh

Aliases

AliasCommand
tfterraform
tfftf fmt
tfvtf validate
tfitf init
tfptf plan
tfatf apply
tfdtf destroy
tfotf output
tfrtf refresh
tfstf show
tfwtf workspace
tffrtff -recursive
tfiptfi & tfp
tfiatfi & tfa
tfidtfi & tfd
tfa!tfa -auto-approve
tfia!tfi && tfa!
tfd!tfd -auto-approve
tfid!tfi && tfd!
tfversiontf version

Function

tfws [workspace_name]

Will execute command :

tfw select [workspace_name] || tfw new [workspace_name]

Prompt function

You can add the current Terraform workspace in your prompt by adding $(tf_prompt_info) to your PROMPT or RPROMPT variable.

RPROMPT` | `$(tf_prompt_info)'

You can also specify the PREFIX and SUFFIX for the workspace with the following variables:

ZSH_THEME_TF_PROMPT_PREFIX="%{$fg[white]%}"
ZSH_THEME_TF_PROMPT_SUFFIX="%{$reset_color%}"

Updating Terraform tools

The plugin comes with a zsh function to update all Terraform tools manually

# From zsh shell
update_zsh_terraform

License

MIT