Files
tf-prep-utils/tdestroy

29 lines
746 B
Plaintext
Raw Permalink Normal View History

2023-11-02 23:27:08 +08:00
#!/bin/bash
set -e
# Pick tfvars file
TFVAR_COUNT=$( find . -type f -name "*.tfvars" | wc -l )
if (( TFVAR_COUNT <= 0 )); then
printf "No tfvars file found.\n"
exit 1
fi
printf "${TFVAR_COUNT} tfvar files found. Pick the number.\n"
FILELIST_OUTPUT=$(find . -type f -name "*.tfvars")
printf "${FILELIST_OUTPUT}\n" | nl
read -p "Pick file number (1): " TFVAR_PICK
if (( TFVAR_PICK > 0 )) && (( TFVAR_PICK <= TFVAR_COUNT )); then
:
else
printf "Pick is invalid\n" && exit 1
fi
# Get picked file
TFVAR_PICK_FILE=$( printf "${FILELIST_OUTPUT}\n" | head -n "${TFVAR_PICK}" | tail -1 )
if [[ $1 == '-y' ]]; then
terraform destroy -var-file="${TFVAR_PICK_FILE}" <<< 'yes'
else
terraform destroy -var-file="${TFVAR_PICK_FILE}"
fi