Skip to content

Commit 87ee5d3

Browse files
fix: resolve "Cannot use a null value in for_each" when ips field is omitted (#35)
- Change default value for missing ips field from null to [] in locals - Update validation to make ips field truly optional - Allow resolver rules without target IP specifications - Maintain backward compatibility with existing configurations Fixes #11 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: lgallard <lgallard@users.noreply.github.com>
1 parent de8b3e0 commit 87ee5d3

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ locals {
6464
domain_name = lookup(rule, "domain_name", null)
6565
ram_name = lookup(rule, "ram_name", "r53-${lookup(rule, "domain_name")}")
6666
vpc_ids = lookup(rule, "vpc_ids", [])
67-
ips = lookup(rule, "ips", null)
67+
ips = lookup(rule, "ips", [])
6868
principals = lookup(rule, "principals", [])
6969
}
7070
}

variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ variable "rules" {
2323

2424
validation {
2525
condition = alltrue([
26-
for rule in var.rules : can(rule.ips) && alltrue([
26+
for rule in var.rules : !can(rule.ips) || rule.ips == null || alltrue([
2727
for ip in rule.ips : can(regex("^((25[0-5]|(2[0-4]|1\\d|[1-9]?)\\d)\\.){3}(25[0-5]|(2[0-4]|1\\d|[1-9]?)\\d)(:[1-9]\\d{0,4}|:6553[0-5]|:655[0-2]\\d|:65[0-4]\\d{2}|:6[0-4]\\d{3})?$", ip)) || can(regex("^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$|^::1$|^::$|^([0-9a-fA-F]{1,4}:)*::([0-9a-fA-F]{1,4}:)*[0-9a-fA-F]{1,4}$", ip))
2828
])
2929
])
30-
error_message = "Each IP in the ips list must be a valid IPv4 address (optionally with port 1-65535) or IPv6 address."
30+
error_message = "When provided, each IP in the ips list must be a valid IPv4 address (optionally with port 1-65535) or IPv6 address."
3131
}
3232

3333
validation {

0 commit comments

Comments
 (0)