diff --git a/lib/jeannie/commands.sh b/lib/jeannie/commands.sh index 5b7cc95..ffb5298 100644 --- a/lib/jeannie/commands.sh +++ b/lib/jeannie/commands.sh @@ -3697,6 +3697,21 @@ oci_foundation_reconcile_existing() { } done + # Recover an existing VCN when the persisted input was lost. This keeps + # subnet CIDR derivation and all dependent resources anchored to the + # surviving network instead of falling back to the default VCN inputs. + if [[ -z "${LAB_OCI_EXISTING_VCN_ID:-}" && -n "${LAB_OCI_COMPARTMENT_ID:-}" ]]; then + local discovered_vcn_id + discovered_vcn_id="$(${oci_bin} network vcn list \ + --compartment-id "${LAB_OCI_COMPARTMENT_ID}" --all \ + --query 'data[?"display-name"==`homelab-vcn`].id | [0]' \ + --raw-output 2>/dev/null || true)" + if [[ -n "${discovered_vcn_id}" && "${discovered_vcn_id}" != "null" ]]; then + export LAB_OCI_EXISTING_VCN_ID="${discovered_vcn_id}" + printf 'Reusing existing OCI VCN (%s).\n' "${discovered_vcn_id}" + fi + fi + # Existing VCNs may outlive the local state file. Use the VCN owner # compartment for discovery and avoid creating a duplicate Bastion. if truthy "${LAB_OCI_BASTION_ENABLED:-true}" && [[ -z "${LAB_OCI_BASTION_ID:-}" ]]; then