Skip to content

Commit 5876e0c

Browse files
mrclrchtrclaude
andcommitted
fix(firewall): respect enable_ipv6 when auto-detecting IPs
- Change IPv6 data source count to require both firewall_use_current_ip AND enable_ipv6 - Restructure current_ips local to conditionally include IPv6 using concat pattern - Add retry blocks to both IPv4 and IPv6 data sources for better resilience - Update firewall_use_current_ip variable description to clarify IPv6 behavior Users without IPv6 connectivity can now safely use firewall_use_current_ip = true with enable_ipv6 = false without encountering HTTP request errors. Fixes #341 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 0a8779c commit 5876e0c

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

firewall.tf

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,35 @@
22
data "http" "personal_ipv4" {
33
count = var.firewall_use_current_ip ? 1 : 0
44
url = "https://ipv4.icanhazip.com"
5+
6+
retry {
7+
attempts = 3
8+
min_delay_ms = 1000
9+
max_delay_ms = 2000
10+
}
511
}
612

713
data "http" "personal_ipv6" {
8-
count = var.firewall_use_current_ip ? 1 : 0
14+
count = var.firewall_use_current_ip && var.enable_ipv6 ? 1 : 0
915
url = "https://ipv6.icanhazip.com"
16+
17+
retry {
18+
attempts = 3
19+
min_delay_ms = 1000
20+
max_delay_ms = 2000
21+
}
1022
}
1123

1224
locals {
13-
current_ips = var.firewall_use_current_ip ? [
14-
"${chomp(data.http.personal_ipv4[0].response_body)}/32",
15-
"${chomp(data.http.personal_ipv6[0].response_body)}/128",
16-
] : []
25+
# Current IPs list - always includes IPv4, conditionally includes IPv6
26+
current_ips = var.firewall_use_current_ip ? concat(
27+
[
28+
"${chomp(data.http.personal_ipv4[0].response_body)}/32",
29+
],
30+
var.firewall_use_current_ip && var.enable_ipv6 ? [
31+
"${chomp(data.http.personal_ipv6[0].response_body)}/128",
32+
] : []
33+
) : []
1734

1835
base_firewall_rules = concat(
1936
var.firewall_kube_api_source == null && !var.firewall_use_current_ip ? [] : [

variables.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ variable "firewall_use_current_ip" {
6868
default = false
6969
description = <<EOF
7070
If true, the current IP address will be used as the source for the firewall rules.
71-
ATTENTION: to determine the current IP, a request to a public service (https://ipv4.icanhazip.com) is made.
71+
ATTENTION: to determine the current IP, requests to public services are made:
72+
- IPv4 address is always fetched from https://ipv4.icanhazip.com
73+
- IPv6 address is only fetched from https://ipv6.icanhazip.com if enable_ipv6 = true
7274
EOF
7375
}
7476

0 commit comments

Comments
 (0)