Adopt legacy OCI VCNs by CIDR
Homelab Main / validate (push) Waiting to run Details
Homelab Main / running-update (push) Blocked by required conditions Details
Homelab Main / debian-ops (push) Blocked by required conditions Details

This commit is contained in:
juvenal.diaz 2026-10-29 12:39:42 -06:00
parent fbed94b309
commit 254823e064
1 changed files with 6 additions and 4 deletions

View File

@ -3891,7 +3891,7 @@ oci_foundation_reconcile_existing() {
printf 'Preserving state-managed OCI VCN and network resources.\n'
elif [[ -z "${LAB_OCI_EXISTING_VCN_ID:-}" ]]; then
local discovered_vcn_id
discovered_vcn_id="$(oci_discover_vcn_id "${LAB_OCI_TENANCY_ID}" "${LAB_OCI_VCN_DISPLAY_NAME:-homelab-vcn}" || true)"
discovered_vcn_id="$(oci_discover_vcn_id "${LAB_OCI_TENANCY_ID}" "${LAB_OCI_VCN_DISPLAY_NAME:-homelab-vcn}" "${LAB_OCI_VCN_CIDR:-10.50.0.0/16}" || 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}"
@ -4346,19 +4346,21 @@ PY
}
oci_discover_vcn_id() {
local root_compartment="$1" display_name="$2" oci_bin compartments compartment_id payload result
local root_compartment="$1" display_name="$2" target_cidr="${3:-}" oci_bin compartments compartment_id payload result
oci_bin="$(oci_cli_resolve)" || return 1
compartments="${root_compartment}"$'\n'$("${oci_bin}" iam compartment list --compartment-id "${root_compartment}" --compartment-id-in-subtree true --all --query 'data[].id' --raw-output 2>/dev/null || true)
while IFS= read -r compartment_id; do
[[ -n "${compartment_id}" ]] || continue
payload="$("${oci_bin}" network vcn list --compartment-id "${compartment_id}" --all --output json 2>/dev/null || true)"
[[ -n "${payload}" ]] || continue
result="$(OCI_DISCOVERY_JSON="${payload}" python3 - "${display_name}" <<'PY'
result="$(OCI_DISCOVERY_JSON="${payload}" python3 - "${display_name}" "${target_cidr}" <<'PY'
import json, os, sys
name = sys.argv[1]
target_cidr = sys.argv[2]
for item in json.loads(os.environ["OCI_DISCOVERY_JSON"]).get("data", []):
tags = item.get("freeform-tags") or {}
if item.get("display-name") == name or tags.get("managed_by") == "jeannie":
cidrs = item.get("cidr-blocks") or []
if item.get("display-name") == name or tags.get("managed_by") == "jeannie" or target_cidr in cidrs:
print(item.get("id", ""))
break
PY