Created
June 12, 2023 14:17
-
-
Save chagui/ae17d23f9a622e1cb1d25187f7ffcf63 to your computer and use it in GitHub Desktop.
For all direct sub-directory find if there is a the lock on the terraform state and remove it
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
#!/usr/bin/env bash | |
function unlock_module { | |
pushd "$1" | |
local -r lock_id="$(terraform refresh 2>&1 | rg ID | awk -F ' ' '{print $4}')" | |
if [[ -n $lock_id ]]; then | |
echo "lock: $lock_id" | |
terraform force-unlock -force "$lock_id" | |
else | |
echo "no lock" | |
fi | |
popd | |
} | |
export -f unlock_module | |
find . -mindepth 1 -maxdepth 1 -type d -print | parallel -j 8 unlock_module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment