Skip to content
Snippets Groups Projects
Commit 023ca7d1 authored by nimrod's avatar nimrod
Browse files

Refactor the Terraform aliases and functions.

First of all, a lot of common code is now in a single file (the tf shell
script). Another benefit is that the `tf` script can be used by others,
as a way to make workspaces and variable files easier.
parent 70e67c2f
No related branches found
No related tags found
No related merge requests found
...@@ -146,8 +146,10 @@ alias screenshot-cleanup='find "$HOME/Pictures" -name "Screenshot from *.png" -d ...@@ -146,8 +146,10 @@ alias screenshot-cleanup='find "$HOME/Pictures" -name "Screenshot from *.png" -d
alias smtp-server='python3 -m smtpd -ndc DebuggingServer' alias smtp-server='python3 -m smtpd -ndc DebuggingServer'
alias sudo="sudo " alias sudo="sudo "
alias sudome="sudome " alias sudome="sudome "
alias tfa='terraform apply tfplan' alias tfa='tf apply tfplan'
alias tfvf='tfv && terraform fmt -diff' alias tfaa='tf apply -auto-approve'
alias tfp='tf plan -out tfplan'
alias tfvf='tf validate && tf fmt -diff'
alias todo="vim \$HOME/Documents/TODO.yml" alias todo="vim \$HOME/Documents/TODO.yml"
# shellcheck disable=SC2142 # shellcheck disable=SC2142
alias tolower='awk "{print tolower(\$0)}"' alias tolower='awk "{print tolower(\$0)}"'
...@@ -257,56 +259,6 @@ sync_podcasts () ( ...@@ -257,56 +259,6 @@ sync_podcasts () (
unison podcasts unison podcasts
) )
tfaa () {
workspace="$(terraform workspace show)"
if [ "$workspace" = "default" ] || [ ! -f "$workspace.tfvars" ]
then
terraform apply -auto-approve "$@"
else
terraform apply -auto-approve -var-file "$workspace.tfvars" "$@"
fi
}
tfi () {
workspace="$(terraform workspace show)"
if [ "$workspace" = "default" ] || [ ! -f "$workspace.tfvars" ]
then
terraform import "$@"
else
terraform import -var-file "$workspace.tfvars" "$@"
fi
}
tfp () {
workspace="$(terraform workspace show)"
if [ "$workspace" = "default" ] || [ ! -f "$workspace.tfvars" ]
then
terraform plan -out tfplan "$@"
else
terraform plan -out tfplan -var-file "$workspace.tfvars" "$@"
fi
}
tfr () {
workspace="$(terraform workspace show)"
if [ "$workspace" = "default" ] || [ ! -f "$workspace.tfvars" ]
then
terraform refresh "$@"
else
terraform refresh -var-file "$workspace.tfvars" "$@"
fi
}
tfv () {
workspace="$(terraform workspace show)"
if [ "$workspace" = "default" ] || [ ! -f "$workspace.tfvars" ]
then
terraform validate "$@"
else
terraform validate -var-file "$workspace.tfvars" "$@"
fi
}
toux () { toux () {
touch "$@" touch "$@"
chmod +x "$@" chmod +x "$@"
......
#!/bin/sh
set -eu
# A wrapper for Terraform to include a variables file is one exists that matches
# the workspace name (on commands that support that).
workspace="$(terraform workspace show)"
if [ ! -f "$workspace.tfvars" ]
then
exec terraform "$@"
fi
for arg in "$@"
do
if [ "$arg" = "plan" ] || [ "$arg" = "console" ] || [ "$arg" = "import" ] ||
[ "$arg" = "refresh" ]
then
exec terraform "$@" "-var-file=$workspace.tfvars"
fi
done
exec terraform "$@"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment