constellation/hack/remove-tf-providers/remove.sh
Paul Meyer 1663b3d795 hack: add script to remove terraform providers
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
2022-11-29 18:47:30 +01:00

37 lines
810 B
Bash
Executable File

#!/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)"