Skip to content

Commit

Permalink
Update usage doc
Browse files Browse the repository at this point in the history
  • Loading branch information
containerscrew committed Mar 31, 2024
1 parent 4ff46cf commit 5d2d931
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- [Installation](#installation)
- [Install latest version](#install-latest-version)
- [Install specific release](#install-specific-release)
- [Container image](#container-image)
- [Usage](#usage)
- [Built-in subcommand](#built-in-subcommand)
- [Example](#example)
Expand Down
58 changes: 48 additions & 10 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

- [Usage](#usage)
- [Summarize](#summarize)
- [Function for zsh or bash shell](#function-for-zsh-or-bash-shell)
- [Function for fish shell](#function-for-fish-shell)
- [Function for zsh](#function-for-zsh)
- [Function for fish](#function-for-fish)
- [Function for bash](#function-for-bash)
- [Load new functions](#load-new-functions)
- [Example](#example)
- [JSON output support](#json-output-support)
- [JSON output with arns](#json-output-with-arns)
Expand All @@ -18,22 +20,22 @@

## Summarize

```bash
```shell
terraform plan -out plan.tfplan
terraform show -json plan.tfplan | tftools summarize
terraform show -json plan.tfplan | tftools summarize --show-tags
```

Or if you have the file in json:

```bash
```shell
terraform plan -out plan.tfplan
terraform show -json plan.tfplan > plan.json
cat plan.json | tftools summarize
tftools summarize ;
```

## Function for zsh or bash shell
Copy [this function](../scripts/tfsum.sh) in your `~/.zshrc` or `~/.bashrc` file.
## Function for zsh

Edit your `~/.zshrc`

```bash
function tfsum() {
Expand All @@ -51,7 +53,9 @@ function tfsum() {
}
```

# Function for fish shell
## Function for fish

Edit your `~/.config/fish/config.fish` or create a new file inside `~/.config/fish/functions/tfsum.fish`

```shell
function tfsum
Expand All @@ -68,7 +72,41 @@ function tfsum
end
```
Load new functions:
## Function for bash
Edit your `~/.bashrc`
```shell
tfsum() {
if [ -z "$1" ]; then
echo "You should type 'tfsum terraform|terragrunt'"
exit 1
fi

echo -en "Starting tf summary... Please wait\n"

if [ -n "$2" ] && [ "$2" == "-v" ]; then
"$1" plan -out plan.tfplan
else
"$1" plan -out plan.tfplan 1> /dev/null
fi

"$1" show -json plan.tfplan | tftools summarize --show-tags
if [ -f "plan.tfplan" ]; then rm plan.tfplan; fi
}
```
> [!NOTE]
> Note that the bash function has the possibility of activating the output or not using the `-v` flag
```shell
tfsum terraform -v # show full output
```
> [!WARNING]
> Adapt the rest of zsh or fish functions according to your needs.
## Load new functions
```shell
source ~/.zshrc
Expand Down

0 comments on commit 5d2d931

Please sign in to comment.