fix: discover OCI edge IP from VNIC

This commit is contained in:
juvenal.diaz 2026-10-28 11:33:50 -06:00
parent 9f3c3fe479
commit 0d3e0537f0
1 changed files with 28 additions and 0 deletions

View File

@ -7991,6 +7991,9 @@ refresh_oci_edge_endpoint() {
local state_file="${LAB_OCI_FOUNDATION_STATE_FILE:-}"
local -a tofu_state_args=()
local discovered_edge_ip=""
local discovered_edge_instance_id=""
local oci_bin=""
local vnic_id=""
# A recreated OCI instance can receive a new public IP. Prefer the
# foundation output over inventory so a standalone `edge` run is
@ -8002,6 +8005,28 @@ refresh_oci_edge_endpoint() {
return 0
fi
discovered_edge_ip="$(tofu -chdir="${stack}" output "${tofu_state_args[@]}" -raw edge_public_ip 2>/dev/null || true)"
discovered_edge_instance_id="$(tofu -chdir="${stack}" output "${tofu_state_args[@]}" -raw edge_instance_id 2>/dev/null || true)"
# Existing-instance mode can retain an old/null public_ip in state. Query
# OCI directly from the instance OCID and read the attached VNIC instead.
if [[ -z "${discovered_edge_instance_id}" || "${discovered_edge_instance_id}" == "null" ]]; then
discovered_edge_instance_id="${LAB_OCI_EDGE_INSTANCE_ID:-${LAB_OCI_EDGE_EXISTING_INSTANCE_ID:-}}"
fi
if [[ -n "${discovered_edge_instance_id}" && "${discovered_edge_instance_id}" != "null" ]] &&
declare -F oci_cli_resolve >/dev/null 2>&1; then
oci_bin="$(oci_cli_resolve 2>/dev/null || true)"
if [[ -n "${oci_bin}" && -n "${LAB_OCI_COMPARTMENT_ID:-}" ]]; then
vnic_id="$("${oci_bin}" compute vnic-attachment list \
--compartment-id "${LAB_OCI_COMPARTMENT_ID}" \
--instance-id "${discovered_edge_instance_id}" \
--query 'data[0]."vnic-id"' --raw-output 2>/dev/null || true)"
if [[ -n "${vnic_id}" && "${vnic_id}" != "null" ]]; then
discovered_edge_ip="$("${oci_bin}" network vnic get \
--vnic-id "${vnic_id}" \
--query 'data."public-ip"' --raw-output 2>/dev/null || true)"
fi
fi
fi
if [[ -z "${discovered_edge_ip}" || "${discovered_edge_ip}" == "null" ]]; then
return 0
fi
@ -8010,6 +8035,9 @@ refresh_oci_edge_endpoint() {
fi
export LAB_EDGE_HOST="${discovered_edge_ip}"
export TF_VAR_edge_host="${discovered_edge_ip}"
if [[ -n "${discovered_edge_instance_id}" && "${discovered_edge_instance_id}" != "null" ]]; then
export LAB_OCI_EDGE_INSTANCE_ID="${discovered_edge_instance_id}"
fi
if declare -F oci_foundation_save_config >/dev/null 2>&1; then
oci_foundation_save_config
fi