From a36bf244e2db44b4e0cbfcc919f43358684f4c1a Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Mon, 26 Oct 2026 17:13:31 -0600 Subject: [PATCH] fix: handle OCI default network resources --- scripts/oci-cleanup | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/oci-cleanup b/scripts/oci-cleanup index 665db78..2e6ed15 100755 --- a/scripts/oci-cleanup +++ b/scripts/oci-cleanup @@ -87,9 +87,17 @@ for item in "${instances[@]}"; do wait_instance_terminated "${id}" done for item in "${subnets[@]}"; do IFS='|' read -r compartment id <<<"${item}"; delete_resource "subnet ${id}" "${oci_bin}" network subnet delete --subnet-id "${id}" --force; done -for item in "${route_tables[@]}"; do IFS='|' read -r compartment id <<<"${item}"; delete_resource "route table ${id}" "${oci_bin}" network route-table delete --rt-id "${id}" --force; done -for item in "${security_lists[@]}"; do IFS='|' read -r compartment id <<<"${item}"; delete_resource "security list ${id}" "${oci_bin}" network security-list delete --security-list-id "${id}" --force; done -for item in "${dhcp_options[@]}"; do IFS='|' read -r compartment id <<<"${item}"; delete_resource "DHCP options ${id}" "${oci_bin}" network dhcp-options delete --dhcp-id "${id}" --force; done + +# OCI does not allow deletion of default route tables, security lists, or DHCP +# options. Clear route rules so gateways can be removed, delete only custom +# route tables, and let VCN deletion remove the default objects. +for item in "${route_tables[@]}"; do + IFS='|' read -r compartment id <<<"${item}" + delete_resource "route rules ${id}" "${oci_bin}" network route-table update --rt-id "${id}" --route-rules '[]' + is_default="$("${oci_bin}" network route-table get --rt-id "${id}" --query 'data."is-default"' --raw-output 2>/dev/null || true)" + [[ "${is_default}" == true ]] || delete_resource "route table ${id}" "${oci_bin}" network route-table delete --rt-id "${id}" --force +done +echo "Skipping direct deletion of security lists and DHCP options; OCI removes them with their VCN." for item in "${nsgs[@]}"; do IFS='|' read -r compartment id <<<"${item}"; delete_resource "NSG ${id}" "${oci_bin}" network nsg delete --nsg-id "${id}" --force; done for item in "${gateways[@]}"; do IFS='|' read -r resource compartment id <<<"${item}"