Skip to content

Commit

Permalink
Add a custom list of cidrs to allow on each NACL table
Browse files Browse the repository at this point in the history
  • Loading branch information
adenot committed Jan 28, 2025
1 parent 7415034 commit 94584ae
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
18 changes: 18 additions & 0 deletions _variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,24 @@ variable "secure_nacl_allow_public" {
description = "Allow traffic between public and secure"
}

variable "public_nacl_allow_cidrs" {
type = list(string)
default = []
description = "CIDRs to allow traffic from public subnet"
}

variable "private_nacl_allow_cidrs" {
type = list(string)
default = []
description = "CIDRs to allow traffic from private subnet"
}

variable "secure_nacl_allow_cidrs" {
type = list(string)
default = []
description = "CIDRs to allow traffic from secure subnet"
}

variable "vpc_flow_logs" {
type = bool
default = true
Expand Down
25 changes: 25 additions & 0 deletions nacl-private.tf
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,28 @@ resource "aws_network_acl_rule" "out_private_from_secure" {
from_port = 0
to_port = 0
}


resource "aws_network_acl_rule" "in_private_from_allowed_cidrs" {
count = length(var.private_nacl_allow_cidrs)
network_acl_id = aws_network_acl.private.id
rule_number = count.index + 601
egress = false
protocol = -1
rule_action = "allow"
cidr_block = var.private_nacl_allow_cidrs[count.index]
from_port = 0
to_port = 0
}

resource "aws_network_acl_rule" "out_private_from_allowed_cidrs" {
count = length(var.private_nacl_allow_cidrs)
network_acl_id = aws_network_acl.private.id
rule_number = count.index + 601
egress = true
protocol = -1
rule_action = "allow"
cidr_block = var.private_nacl_allow_cidrs[count.index]
from_port = 0
to_port = 0
}
25 changes: 25 additions & 0 deletions nacl-public.tf
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,28 @@ resource "aws_network_acl_rule" "in_public_from_secure" {
from_port = 0
to_port = 0
}


resource "aws_network_acl_rule" "in_public_from_allowed_cidrs" {
count = length(var.public_nacl_allow_cidrs)
network_acl_id = aws_network_acl.public.id
rule_number = count.index + 801
egress = false
protocol = -1
rule_action = "allow"
cidr_block = var.public_nacl_allow_cidrs[count.index]
from_port = 0
to_port = 0
}

resource "aws_network_acl_rule" "out_public_from_allowed_cidrs" {
count = length(var.public_nacl_allow_cidrs)
network_acl_id = aws_network_acl.public.id
rule_number = count.index + 801
egress = true
protocol = -1
rule_action = "allow"
cidr_block = var.public_nacl_allow_cidrs[count.index]
from_port = 0
to_port = 0
}
24 changes: 24 additions & 0 deletions nacl-secure.tf
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,27 @@ resource "aws_network_acl_rule" "out_secure_to_dynamodb" {
from_port = 0
to_port = 0
}

resource "aws_network_acl_rule" "in_secure_from_allowed_cidrs" {
count = length(var.secure_nacl_allow_cidrs)
network_acl_id = aws_network_acl.secure.id
rule_number = count.index + 801
egress = false
protocol = -1
rule_action = "allow"
cidr_block = var.secure_nacl_allow_cidrs[count.index]
from_port = 0
to_port = 0
}

resource "aws_network_acl_rule" "out_secure_from_allowed_cidrs" {
count = length(var.secure_nacl_allow_cidrs)
network_acl_id = aws_network_acl.secure.id
rule_number = count.index + 801
egress = true
protocol = -1
rule_action = "allow"
cidr_block = var.secure_nacl_allow_cidrs[count.index]
from_port = 0
to_port = 0
}

0 comments on commit 94584ae

Please sign in to comment.