From ed8760cc56817b367e1413515f77ff17c722e714 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Mon, 28 Oct 2019 11:12:44 +0200
Subject: [PATCH] Terraform shell functions and alias.

- Rename them to tf* instead of t* (tr is already taken, so avoid that).
- Don't use a variable file for the workspace if not variable file
exists.
---
 .bashrc | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/.bashrc b/.bashrc
index 813ea9f..c9f2108 100644
--- a/.bashrc
+++ b/.bashrc
@@ -121,7 +121,7 @@ alias check_unix='nc -Uvzw3'
 alias listen_tcp='nc -vlk 0.0.0.0'
 alias listen_udp='nc -uvlk 0.0.0.0'
 alias listen_unix='nc -Uvlk'
-alias ta='terraform apply tfplan'
+alias tfa='terraform apply tfplan'
 
 if ! command -v notify-send > /dev/null
 then
@@ -132,9 +132,9 @@ then
     alias notify-send="notify-send --hint \"string:desktop-entry:$(basename "$GIO_LAUNCHED_DESKTOP_FILE")\""
 fi
 
-tp () {
+tfp () {
     workspace="$(terraform workspace show)"
-    if [ "$workspace" = "default" ]
+    if [ "$workspace" = "default" ] || [ ! -f "$workspace.tfvars" ]
     then
         terraform plan -out tfplan "$@"
     else
@@ -142,9 +142,9 @@ tp () {
     fi
 }
 
-taa () {
+tfaa () {
     workspace="$(terraform workspace show)"
-    if [ "$workspace" = "default" ]
+    if [ "$workspace" = "default" ] || [ ! -f "$workspace.tfvars" ]
     then
         terraform apply -auto-approve "$@"
     else
@@ -152,9 +152,9 @@ taa () {
     fi
 }
 
-tr () {
+tfr () {
     workspace="$(terraform workspace show)"
-    if [ "$workspace" = "default" ]
+    if [ "$workspace" = "default" ] || [ ! -f "$workspace.tfvars" ]
     then
         terraform refresh "$@"
     else
@@ -162,9 +162,9 @@ tr () {
     fi
 }
 
-ti () {
+tfi () {
     workspace="$(terraform workspace show)"
-    if [ "$workspace" = "default" ]
+    if [ "$workspace" = "default" ] || [ ! -f "$workspace.tfvars" ]
     then
         terraform import "$@"
     else
-- 
GitLab