Created
May 4, 2024 21:30
-
-
Save taqiabdulaziz/0e86a491b5d684dfb1f203dd5ed59f65 to your computer and use it in GitHub Desktop.
terraform remove all state
This file contains 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
#!/bin/bash | |
# Run terraform state list command and store output in a variable | |
TF_STATE_LIST=$(terraform state list) | |
# Check if the TF_STATE_LIST variable is empty | |
if [ -z "$TF_STATE_LIST" ]; then | |
echo "No resources to remove from state." | |
exit 0 | |
fi | |
# Iterate over each line of the terraform state list output | |
while IFS= read -r RESOURCE; do | |
echo "Removing resource from state: $RESOURCE" | |
# Run terraform state rm for each resource | |
terraform state rm "$RESOURCE" | |
done <<< "$TF_STATE_LIST" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment