Skip to content

Commit ea5c8c5

Browse files
committed
fix: Improve private interface determination logic in locals.tf
This commit enhances the logic for determining the private interface in the locals.tf file. The update refines the command to first check the network CIDR for the interface and, if not found, fall back to the gateway route. This change improves error handling and ensures a more reliable configuration for network setups, addressing potential issues with interface detection in varying environments. The modifications contribute to the overall robustness of the network setup in response to recent DHCP behavior changes.
1 parent f22ca04 commit ea5c8c5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

locals.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,13 @@ locals {
103103
"METRIC=512",
104104
"",
105105
"# Determine the private interface dynamically (no hardcoded eth1)",
106-
"PRIV_IF=$( (ip -4 route get ${local.network_gw_ipv4} || ip -4 route show ${var.network_ipv4_cidr}) 2>/dev/null | awk '{for(i=1;i<=NF;i++) if($i==\"dev\"){print $(i+1); exit}}' | head -n 1)",
106+
"PRIV_IF=$(ip -4 route show ${var.network_ipv4_cidr} 2>/dev/null | awk '{for(i=1;i<=NF;i++) if($i==\"dev\"){print $(i+1); exit}}' | head -n 1)",
107+
"if [ -z \"$PRIV_IF\" ]; then",
108+
" ROUTE_LINE=$(ip -4 route get ${local.network_gw_ipv4} 2>/dev/null)",
109+
" if [ -n \"$ROUTE_LINE\" ] && ! echo \"$ROUTE_LINE\" | grep -q ' via '; then",
110+
" PRIV_IF=$(echo \"$ROUTE_LINE\" | awk '{for(i=1;i<=NF;i++) if($i==\"dev\"){print $(i+1); exit}}' | head -n 1)",
111+
" fi",
112+
"fi",
107113
"if [ -n \"$PRIV_IF\" ]; then",
108114
" if systemctl is-active --quiet NetworkManager; then",
109115
" NM_CONN=$(nmcli -g GENERAL.CONNECTION device show \"$PRIV_IF\" 2>/dev/null | head -1)",

0 commit comments

Comments
 (0)