hack: add script to remove terraform providers

Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
Paul Meyer 2022-11-29 16:50:40 +01:00
parent fffd2b79f2
commit 1663b3d795

View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Script removes the .terraform directorys with the providers that were
# downloaded by terraform init.
set -euo pipefail
shopt -s inherit_errexit
dirs=$(find . -type d -name "*.terraform" | sort -ud)
if [[ -z ${dirs} ]]; then
echo "No .terraform directories found"
exit 0
fi
echo "Size of $(pwd): $(du -hs | cut -f1)"
echo
echo "Removing Terraform providers from the following directories:"
echo
echo "${dirs}"
echo
read -p "Should we delete them all? [y/n] " -n 1 -r
if [[ ! ${REPLY} =~ ^[Yy]$ ]]; then
echo "Aborting."
[[ $0 == "${BASH_SOURCE[0]}" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
echo
for dir in ${dirs}; do
echo "Removing ${dir}"
rm -rf "${dir}"
done
echo
echo "Size of $(pwd): $(du -hs | cut -f1)"