1
0

feat: new nacl module improved with Qoder

This commit is contained in:
xpk
2026-04-10 23:43:10 +08:00
parent 998636f079
commit ebdbd19d28
6 changed files with 142 additions and 54 deletions
+33 -23
View File
@@ -1,3 +1,8 @@
/**
* # nacl module
*
* Code reviewed and improved with Qoder
*/
resource "aws_network_acl" "this" {
vpc_id = var.vpc_id
@@ -5,28 +10,33 @@ resource "aws_network_acl" "this" {
tags = {
Name = var.acl_name
}
dynamic "ingress" {
for_each = var.ingress_rules
content {
rule_no = ingress.value[0]
protocol = ingress.value[1]
from_port = ingress.value[2]
to_port = ingress.value[3]
cidr_block = ingress.value[4]
action = ingress.value[5]
}
}
}
dynamic "egress" {
for_each = var.egress_rules
content {
rule_no = egress.value[0]
protocol = egress.value[1]
from_port = egress.value[2]
to_port = egress.value[3]
cidr_block = egress.value[4]
action = egress.value[5]
}
}
resource "aws_network_acl_rule" "ingress" {
for_each = { for k, v in var.ingress_rules : k => v }
network_acl_id = aws_network_acl.this.id
rule_number = 100 + tonumber(each.key)
egress = false
protocol = split(",", each.value)[0]
rule_action = split(",", each.value)[4]
# Support both IPv4 and IPv6 CIDR blocks
cidr_block = strcontains(split(",", each.value)[3], "::") ? null : split(",", each.value)[3]
ipv6_cidr_block = strcontains(split(",", each.value)[3], "::") ? split(",", each.value)[3] : null
from_port = tonumber(split(",", each.value)[1])
to_port = tonumber(split(",", each.value)[2])
}
}
resource "aws_network_acl_rule" "egress" {
for_each = { for k, v in var.egress_rules : k => v }
network_acl_id = aws_network_acl.this.id
rule_number = 100 + tonumber(each.key)
egress = true
protocol = split(",", each.value)[0]
rule_action = split(",", each.value)[4]
# Support both IPv4 and IPv6 CIDR blocks
cidr_block = strcontains(split(",", each.value)[3], "::") ? null : split(",", each.value)[3]
ipv6_cidr_block = strcontains(split(",", each.value)[3], "::") ? split(",", each.value)[3] : null
from_port = tonumber(split(",", each.value)[1])
to_port = tonumber(split(",", each.value)[2])
}