fix: clean transient OpenTofu locks during repo sync

This commit is contained in:
juvenal.diaz 2026-10-28 19:15:34 -06:00
parent bbb9c46ee8
commit 23776ac0d5
1 changed files with 9 additions and 7 deletions

View File

@ -22,13 +22,15 @@ current_branch="$("${git_cmd[@]}" branch --show-current)"
echo "Git remote not found: ${remote}" >&2
exit 2
}
# OpenTofu leaves this transient lock metadata after an interrupted plan. It
# is safe to remove only when no OpenTofu process is still running; real source
# changes remain blocking as before.
stale_tofu_lock="${repo_root}/bootstrap/oci/.terraform.tfstate.lock.info"
if [[ -f "${stale_tofu_lock}" ]] && ! pgrep -af '[t]ofu' >/dev/null 2>&1; then
rm -f "${stale_tofu_lock}"
echo "Removed stale OpenTofu lock metadata: ${stale_tofu_lock}"
# OpenTofu leaves transient lock metadata after an interrupted plan. Remove
# only these generated files, and only when no OpenTofu process is running;
# real source changes remain blocking as before.
if ! pgrep -af '[t]ofu' >/dev/null 2>&1; then
while IFS= read -r stale_tofu_lock; do
[[ -n "${stale_tofu_lock}" ]] || continue
rm -f "${stale_tofu_lock}"
echo "Removed stale OpenTofu lock metadata: ${stale_tofu_lock}"
done < <(find "${repo_root}/bootstrap" -type f -name '.terraform.tfstate.lock.info' -print)
fi
if [[ -n "$("${git_cmd[@]}" status --porcelain)" ]]; then
echo "Refusing repo sync: working tree is not clean." >&2