diff --git a/plugins/terragrunt/README.md b/plugins/terragrunt/README.md new file mode 100644 index 000000000..d2b5d8809 --- /dev/null +++ b/plugins/terragrunt/README.md @@ -0,0 +1,53 @@ +# Terragrunt plugin + +Terragrunt is a thin wrapper for opentofu/terraform that provides extra tools +and features to enhance the management of Infrastructure as Code (IaC) using +opentofu/terraform. This plugin adds completion for `terragrunt` command, as well +as aliases and a prompt function. + +To use it, add `terragrunt` to the plugins array of your `~/.zshrc` file: + +```shell +plugins=(... terragrunt) +``` + +## Requirements + +- [Terragrunt](https://docs.terragrunt.com/) v0.77.22 or later + +## Aliases + +| Alias | Command | +| ------ | ----------------------------------------- | +| `tg` | `terragrunt` | +| `tga` | `terragrunt run -- apply` | +| `tgaa` | `terragrunt run -- apply -auto-approve` | +| `tgc` | `terragrunt run -- console` | +| `tgd` | `terragrunt run -- destroy` | +| `tgd!` | `terragrunt run -- destroy -auto-approve` | +| `tgi` | `terragrunt run -- init` | +| `tgo` | `terragrunt run -- output` | +| `tgp` | `terragrunt run -- plan` | +| `tgv` | `terragrunt run -- validate` | +| `tgs` | `terragrunt run -- state` | +| `tgsh` | `terragrunt run -- show` | +| `tgr` | `terragrunt run -- refresh` | +| `tgt` | `terragrunt run -- test` | +| `tgws` | `terragrunt run -- workspace` | + +## Prompt function + +- `terragrunt_version_prompt_info` shows the current version of the `terragrunt` command. + +To use it, add it to a `PROMPT` or `RPROMPT` variable in your theme or `.zshrc` file. + +```sh +RPROMPT='$(terragrunt_version_prompt_info)' +``` + +You can also specify the PREFIX and SUFFIX strings with the following variables. + +```sh +ZSH_THEME_TERRAGRUNT_VERSION_PROMPT_PREFIX="%{$fg[white]%}" +ZSH_THEME_TERRAGRUNT_VERSION_PROMPT_SUFFIX="%{$reset_color%}" +``` diff --git a/plugins/terragrunt/terragrunt.plugin.zsh b/plugins/terragrunt/terragrunt.plugin.zsh new file mode 100644 index 000000000..c2c71425e --- /dev/null +++ b/plugins/terragrunt/terragrunt.plugin.zsh @@ -0,0 +1,27 @@ +# set up the terragrunt completion (compatible for zsh) +autoload -Uz bashcompinit && bashcompinit +complete -C terragrunt terragrunt + +# terragrunt version prompt function +function terragrunt_version_prompt_info() { + # get the output of `terragrunt --version` in a single line, and get the third word after splitting by a space + local terragrunt_version=${${(s: :)$(terragrunt --version)}[3]} + # make sure to escape % signs in the version string to prevent command injection + echo "${ZSH_THEME_TERRAGRUNT_VERSION_PROMPT_PREFIX-[}${terragrunt_version:gs/%/%%}${ZSH_THEME_TERRAGRUNT_VERSION_PROMPT_SUFFIX-]}" +} + +alias tg='terragrunt' +alias tga='terragrunt run -- apply' +alias tgaa='terragrunt run -- apply -auto-approve' +alias tgc='terragrunt run -- console' +alias tgd='terragrunt run -- destroy' +alias tgd!='terragrunt run -- destroy -auto-approve' +alias tgi='terragrunt run -- init' +alias tgo='terragrunt run -- output' +alias tgp='terragrunt run -- plan' +alias tgv='terragrunt run -- validate' +alias tgs='terragrunt run -- state' +alias tgsh='terragrunt run -- show' +alias tgr='terragrunt run -- refresh' +alias tgt='terragrunt run -- test' +alias tgws='terragrunt run -- workspace'