diff --git a/.bashrc b/.bashrc index 4443c63134a67df958664343ad756eb03071eaeb..3cea62016142bcc78a074928533cc2a76f5fac4b 100644 --- a/.bashrc +++ b/.bashrc @@ -146,8 +146,10 @@ alias screenshot-cleanup='find "$HOME/Pictures" -name "Screenshot from *.png" -d alias smtp-server='python3 -m smtpd -ndc DebuggingServer' alias sudo="sudo " alias sudome="sudome " -alias tfa='terraform apply tfplan' -alias tfvf='tfv && terraform fmt -diff' +alias tfa='tf apply tfplan' +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" # shellcheck disable=SC2142 alias tolower='awk "{print tolower(\$0)}"' @@ -257,56 +259,6 @@ sync_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 () { touch "$@" chmod +x "$@" diff --git a/Documents/bin/tf b/Documents/bin/tf new file mode 100644 index 0000000000000000000000000000000000000000..16e7471870a813f3301103c3efd2483dc1f0ef85 --- /dev/null +++ b/Documents/bin/tf @@ -0,0 +1,21 @@ +#!/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 "$@"