From 61b4a222de3822fbc941507f6852bd9875980641 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Thu, 29 Oct 2026 12:34:15 -0600 Subject: [PATCH] Discover stale OCI compartments before planning --- lib/jeannie/commands.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/jeannie/commands.sh b/lib/jeannie/commands.sh index 072a5e3..96fcd84 100644 --- a/lib/jeannie/commands.sh +++ b/lib/jeannie/commands.sh @@ -3827,6 +3827,13 @@ oci_foundation_reconcile_existing() { return 0 fi + # Persisted OCIDs can refer to deleted resources after a tenancy reset. + # Validate the compartment before using it as the discovery root. + if [[ -n "${LAB_OCI_COMPARTMENT_ID:-}" && "${LAB_OCI_COMPARTMENT_ID}" != "null" ]] && ! "${oci_bin}" iam compartment get --compartment-id "${LAB_OCI_COMPARTMENT_ID}" >/dev/null 2>&1; then + printf 'Persisted OCI compartment %s is absent; rediscovering by name.\n' "${LAB_OCI_COMPARTMENT_ID}" >&2 + unset LAB_OCI_COMPARTMENT_ID + 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. @@ -3849,6 +3856,7 @@ oci_foundation_reconcile_existing() { [[ -n "${compartment_id}" && "${compartment_id}" != "null" ]] || { compartment_id="$("${oci_bin}" iam compartment list \ --compartment-id "${LAB_OCI_TENANCY_ID}" \ + --compartment-id-in-subtree true \ --name "${compartment_name}" --all \ --query 'data[0].id' --raw-output 2>/dev/null || true)" if [[ -n "${compartment_id}" && "${compartment_id}" != "null" ]]; then