fix: reconcile existing OCI compartments
This commit is contained in:
parent
52b3fcdc8f
commit
548ea2991f
|
|
@ -3638,10 +3638,7 @@ oci_foundation_save_config() {
|
||||||
}
|
}
|
||||||
|
|
||||||
oci_foundation_reconcile_existing() {
|
oci_foundation_reconcile_existing() {
|
||||||
local oci_bin="" output_file status
|
local oci_bin="" output_file status compartment_id compartment_name
|
||||||
if disabled_value "${LAB_OCI_COMPUTE_ENABLED:-true}"; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
if command -v oci >/dev/null 2>&1; then
|
if command -v oci >/dev/null 2>&1; then
|
||||||
oci_bin="$(command -v oci)"
|
oci_bin="$(command -v oci)"
|
||||||
elif [[ -x "${HOME}/.local/share/homelab/venvs/oci-cli/bin/oci" ]]; then
|
elif [[ -x "${HOME}/.local/share/homelab/venvs/oci-cli/bin/oci" ]]; then
|
||||||
|
|
@ -3650,6 +3647,41 @@ oci_foundation_reconcile_existing() {
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Reuse named child compartments when a previous state file was lost or a
|
||||||
|
# prior apply completed only partway. OCI rejects a second compartment with
|
||||||
|
# the same name, so discover the active OCID before Terraform plans.
|
||||||
|
for status in homelab email; do
|
||||||
|
case "${status}" in
|
||||||
|
homelab)
|
||||||
|
[[ "${LAB_OCI_CREATE_COMPARTMENT:-true}" == "true" ]] || continue
|
||||||
|
compartment_id="${LAB_OCI_COMPARTMENT_ID:-}"
|
||||||
|
compartment_name="${LAB_OCI_COMPARTMENT_NAME:-homelab-learning}"
|
||||||
|
;;
|
||||||
|
email)
|
||||||
|
[[ "${LAB_OCI_EMAIL_CREATE_COMPARTMENT:-true}" == "true" ]] || continue
|
||||||
|
compartment_id="${LAB_OCI_EMAIL_COMPARTMENT_ID:-}"
|
||||||
|
compartment_name="${LAB_OCI_EMAIL_COMPARTMENT_NAME:-homelab-email}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
[[ -n "${compartment_id}" && "${compartment_id}" != "null" ]] || {
|
||||||
|
compartment_id="$("${oci_bin}" iam compartment list \
|
||||||
|
--compartment-id "${LAB_OCI_TENANCY_ID}" \
|
||||||
|
--name "${compartment_name}" --all \
|
||||||
|
--query 'data[0].id' --raw-output 2>/dev/null || true)"
|
||||||
|
if [[ -n "${compartment_id}" && "${compartment_id}" != "null" ]]; then
|
||||||
|
if [[ "${status}" == "homelab" ]]; then
|
||||||
|
export LAB_OCI_COMPARTMENT_ID="${compartment_id}"
|
||||||
|
export LAB_OCI_CREATE_COMPARTMENT=false
|
||||||
|
else
|
||||||
|
export LAB_OCI_EMAIL_COMPARTMENT_ID="${compartment_id}"
|
||||||
|
export LAB_OCI_EMAIL_CREATE_COMPARTMENT=false
|
||||||
|
fi
|
||||||
|
printf 'Reusing existing OCI %s compartment %s (%s).\n' \
|
||||||
|
"${status}" "${compartment_name}" "${compartment_id}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
done
|
||||||
|
|
||||||
[[ -n "${LAB_OCI_EDGE_EXISTING_INSTANCE_ID:-}" ]] || return 0
|
[[ -n "${LAB_OCI_EDGE_EXISTING_INSTANCE_ID:-}" ]] || return 0
|
||||||
output_file="$(mktemp)"
|
output_file="$(mktemp)"
|
||||||
if ! "${oci_bin}" compute instance get \
|
if ! "${oci_bin}" compute instance get \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue