Fixes stale state in tofu

This commit is contained in:
juvenal.diaz 2026-07-22 22:35:23 -06:00
parent 318ba53eb0
commit 101668fbc9
1 changed files with 16 additions and 1 deletions

17
jeannie
View File

@ -270,11 +270,26 @@ adopt_tofu_helm_release() {
local resource_address="$2"
local namespace="$3"
local release_name="$4"
local has_state=false
local has_release_secret=false
if tofu_state_has_resource "${stack}" "${resource_address}"; then
has_state=true
fi
if helm_release_secret_exists "${namespace}" "${release_name}"; then
has_release_secret=true
fi
if [[ "${has_state}" == "true" && "${has_release_secret}" == "false" ]]; then
echo "Removing stale Helm release state for ${namespace}/${release_name} from ${stack} (${resource_address}) because no Helm release secret exists..."
tofu -chdir="${REPO_ROOT}/${stack}" state rm "${resource_address}"
return 0
fi
if ! helm_release_secret_exists "${namespace}" "${release_name}"; then
if [[ "${has_state}" == "true" ]]; then
return 0
fi
if [[ "${has_release_secret}" == "false" ]]; then
return 0
fi