Skip to content

Commit 3cb319c

Browse files
authored
Add a custom list of cidrs to allow on each NACL table (#58)
* Add a custom list of cidrs to allow on each NACL table * terraform-docs: automated update action --------- Co-authored-by: adenot <[email protected]>
1 parent 7415034 commit 3cb319c

5 files changed

+95
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,16 @@ module "network" {
8787
| nat | Deploy NAT instance(s) | `bool` | `true` | no |
8888
| network\_firewall | Enable or disable VPC Network Firewall | `bool` | `false` | no |
8989
| newbits | Number of bits to add to the vpc cidr when building subnets | `number` | `5` | no |
90+
| private\_nacl\_allow\_cidrs | CIDRs to allow traffic from private subnet | `list(string)` | `[]` | no |
9091
| private\_netnum\_offset | Start with this subnet for private ones, plus number of AZs | `number` | `5` | no |
92+
| public\_nacl\_allow\_cidrs | CIDRs to allow traffic from public subnet | `list(string)` | `[]` | no |
9193
| public\_nacl\_icmp | Allows ICMP traffic to and from the public subnet | `bool` | `true` | no |
9294
| public\_nacl\_inbound\_tcp\_ports | TCP Ports to allow inbound on public subnet via NACLs (this list cannot be empty) | `list(string)` | <pre>[<br> "80",<br> "443",<br> "22",<br> "1194"<br>]</pre> | no |
9395
| public\_nacl\_inbound\_udp\_ports | UDP Ports to allow inbound on public subnet via NACLs (this list cannot be empty) | `list(string)` | `[]` | no |
9496
| public\_nacl\_outbound\_tcp\_ports | TCP Ports to allow outbound to external services (use [0] to allow all ports) | `list(string)` | <pre>[<br> "0"<br>]</pre> | no |
9597
| public\_nacl\_outbound\_udp\_ports | UDP Ports to allow outbound to external services (use [0] to allow all ports) | `list(string)` | <pre>[<br> "0"<br>]</pre> | no |
9698
| public\_netnum\_offset | Start with this subnet for public ones, plus number of AZs | `number` | `0` | no |
99+
| secure\_nacl\_allow\_cidrs | CIDRs to allow traffic from secure subnet | `list(string)` | `[]` | no |
97100
| secure\_nacl\_allow\_public | Allow traffic between public and secure | `bool` | `false` | no |
98101
| secure\_netnum\_offset | Start with this subnet for secure ones, plus number of AZs | `number` | `10` | no |
99102
| tags | Extra tags to attach to resources | `map(string)` | `{}` | no |

_variables.tf

+18
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,24 @@ variable "secure_nacl_allow_public" {
150150
description = "Allow traffic between public and secure"
151151
}
152152

153+
variable "public_nacl_allow_cidrs" {
154+
type = list(string)
155+
default = []
156+
description = "CIDRs to allow traffic from public subnet"
157+
}
158+
159+
variable "private_nacl_allow_cidrs" {
160+
type = list(string)
161+
default = []
162+
description = "CIDRs to allow traffic from private subnet"
163+
}
164+
165+
variable "secure_nacl_allow_cidrs" {
166+
type = list(string)
167+
default = []
168+
description = "CIDRs to allow traffic from secure subnet"
169+
}
170+
153171
variable "vpc_flow_logs" {
154172
type = bool
155173
default = true

nacl-private.tf

+25
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,28 @@ resource "aws_network_acl_rule" "out_private_from_secure" {
158158
from_port = 0
159159
to_port = 0
160160
}
161+
162+
163+
resource "aws_network_acl_rule" "in_private_from_allowed_cidrs" {
164+
count = length(var.private_nacl_allow_cidrs)
165+
network_acl_id = aws_network_acl.private.id
166+
rule_number = count.index + 601
167+
egress = false
168+
protocol = -1
169+
rule_action = "allow"
170+
cidr_block = var.private_nacl_allow_cidrs[count.index]
171+
from_port = 0
172+
to_port = 0
173+
}
174+
175+
resource "aws_network_acl_rule" "out_private_from_allowed_cidrs" {
176+
count = length(var.private_nacl_allow_cidrs)
177+
network_acl_id = aws_network_acl.private.id
178+
rule_number = count.index + 601
179+
egress = true
180+
protocol = -1
181+
rule_action = "allow"
182+
cidr_block = var.private_nacl_allow_cidrs[count.index]
183+
from_port = 0
184+
to_port = 0
185+
}

nacl-public.tf

+25
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,28 @@ resource "aws_network_acl_rule" "in_public_from_secure" {
179179
from_port = 0
180180
to_port = 0
181181
}
182+
183+
184+
resource "aws_network_acl_rule" "in_public_from_allowed_cidrs" {
185+
count = length(var.public_nacl_allow_cidrs)
186+
network_acl_id = aws_network_acl.public.id
187+
rule_number = count.index + 801
188+
egress = false
189+
protocol = -1
190+
rule_action = "allow"
191+
cidr_block = var.public_nacl_allow_cidrs[count.index]
192+
from_port = 0
193+
to_port = 0
194+
}
195+
196+
resource "aws_network_acl_rule" "out_public_from_allowed_cidrs" {
197+
count = length(var.public_nacl_allow_cidrs)
198+
network_acl_id = aws_network_acl.public.id
199+
rule_number = count.index + 801
200+
egress = true
201+
protocol = -1
202+
rule_action = "allow"
203+
cidr_block = var.public_nacl_allow_cidrs[count.index]
204+
from_port = 0
205+
to_port = 0
206+
}

nacl-secure.tf

+24
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,27 @@ resource "aws_network_acl_rule" "out_secure_to_dynamodb" {
149149
from_port = 0
150150
to_port = 0
151151
}
152+
153+
resource "aws_network_acl_rule" "in_secure_from_allowed_cidrs" {
154+
count = length(var.secure_nacl_allow_cidrs)
155+
network_acl_id = aws_network_acl.secure.id
156+
rule_number = count.index + 801
157+
egress = false
158+
protocol = -1
159+
rule_action = "allow"
160+
cidr_block = var.secure_nacl_allow_cidrs[count.index]
161+
from_port = 0
162+
to_port = 0
163+
}
164+
165+
resource "aws_network_acl_rule" "out_secure_from_allowed_cidrs" {
166+
count = length(var.secure_nacl_allow_cidrs)
167+
network_acl_id = aws_network_acl.secure.id
168+
rule_number = count.index + 801
169+
egress = true
170+
protocol = -1
171+
rule_action = "allow"
172+
cidr_block = var.secure_nacl_allow_cidrs[count.index]
173+
from_port = 0
174+
to_port = 0
175+
}

0 commit comments

Comments
 (0)