Created
May 14, 2026 18:42
-
-
Save tlhakhan/3a10392d93db524ce953fe6eadb96761 to your computer and use it in GitHub Desktop.
A helper script to remove hashicorp tools from existing machines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| # Remove HashiCorp packages | |
| apt-get remove -y terraform packer vault 2>/dev/null || true | |
| # Remove terraform-docs binary | |
| rm -f /usr/local/bin/terraform-docs | |
| # Remove HashiCorp APT repository | |
| rm -f /etc/apt/sources.list.d/hashicorp.list \ | |
| /etc/apt/sources.list.d/*hashicorp* | |
| # Remove HashiCorp GPG key (apt_key stores in the legacy keyring) | |
| apt-key del "$(apt-key list 2>/dev/null | grep -B1 -i hashicorp | grep pub | awk '{print $2}' | cut -d/ -f2)" 2>/dev/null || true | |
| # Remove tf and tfdocs aliases from all users' .bash_aliases | |
| for home_dir in /root /home/*; do | |
| aliases_file="${home_dir}/.bash_aliases" | |
| if [[ -f "${aliases_file}" ]]; then | |
| sed -i "/alias tf='terraform'/d" "${aliases_file}" | |
| sed -i "/alias tfdocs='terraform-docs'/d" "${aliases_file}" | |
| fi | |
| done | |
| apt-get update | |
| echo "HashiCorp tooling removed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment