1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# Variables ====================================================================
variable "name_prefix" {
description = "Prefix prepended to resource names created by this module"
type = string
validation {
condition = length(trimspace(var.name_prefix)) > 0
error_message = "name_prefix must not be empty."
}
}
variable "vpc_id" {
description = "ID of the VPC to associate NACLs with"
type = string
validation {
condition = length(var.vpc_id) > 0
error_message = "vpc_id must not be empty."
}
}
variable "network_acls" {
description = "Map of NACLs to create. Each entry defines a NACL with its subnet associations and ingress/egress rules. The NACL name is generated from name_prefix."
type = map(object({
subnet_ids = list(string)
ingress_rules = list(object({
rule_number = number
action = string # allow or deny
protocol = string # -1 for all, 6 for TCP, 17 for UDP, 1 for ICMP
from_port = optional(number, 0)
to_port = optional(number, 65535)
cidr_block = optional(string, null)
icmp_type = optional(number, null) # only when protocol = "1"
icmp_code = optional(number, null) # only when protocol = "1"
}))
egress_rules = list(object({
rule_number = number
action = string # allow or deny
protocol = string # -1 for all, 6 for TCP, 17 for UDP, 1 for ICMP
from_port = optional(number, 0)
to_port = optional(number, 65535)
cidr_block = optional(string, null)
icmp_type = optional(number, null) # only when protocol = "1"
icmp_code = optional(number, null) # only when protocol = "1"
}))
}))
default = {}
validation {
condition = alltrue(flatten([
for k, v in var.network_acls : [
for r in v.ingress_rules : r.rule_number >= 1 && r.rule_number <= 32766
]
]))
error_message = "Each ingress rule_number must be between 1 and 32766."
}
validation {
condition = alltrue(flatten([
for k, v in var.network_acls : [
for r in v.egress_rules : r.rule_number >= 1 && r.rule_number <= 32766
]
]))
error_message = "Each egress rule_number must be between 1 and 32766."
}
}
variable "tags" {
description = "Resource tags to apply to all resources"
type = map(string)
default = {}
}
|