generated from dxw/terraform-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Creates a network ACL with ocnfigurable rules * If egress/ingress lockdown is enabled, all traffic will be blocked by default * The ACL is applied to all the subnets created in the infrastructure * Custom rules can be added to the egress / ingress rules. These will be evaluated before the allow all rule (if lockdown is not set). The allow all rule is set to rule number 100, because an ACL can only have maximum 80 rules, and all of the custom rules will have there rule numbers managed automatically by using their index in the list as the rule number.
- Loading branch information
Showing
4 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
resource "aws_default_network_acl" "infrastructure" { | ||
count = local.infrastructure_vpc ? 1 : 0 | ||
|
||
default_network_acl_id = aws_vpc.infrastructure[0].default_network_acl_id | ||
} | ||
|
||
resource "aws_network_acl" "infrastructure" { | ||
count = local.infrastructure_vpc ? 1 : 0 | ||
|
||
vpc_id = aws_vpc.infrastructure[0].id | ||
|
||
tags = { | ||
Name = "${local.resource_prefix}-infrastructure" | ||
} | ||
} | ||
|
||
resource "aws_network_acl_association" "infrastructure_public_subnets" { | ||
for_each = local.infrastructure_vpc && local.infrastructure_vpc_network_enable_public ? aws_subnet.infrastructure_public : {} | ||
|
||
network_acl_id = aws_network_acl.infrastructure[0].id | ||
subnet_id = each.value.id | ||
} | ||
|
||
resource "aws_network_acl_association" "infrastructure_private_subnets" { | ||
for_each = local.infrastructure_vpc && local.infrastructure_vpc_network_enable_private ? aws_subnet.infrastructure_private : {} | ||
|
||
network_acl_id = aws_network_acl.infrastructure[0].id | ||
subnet_id = each.value.id | ||
} | ||
|
||
#This will only be used if `infrastructure_vpc_network_acl_egress_lockdown` isn't set | ||
#We would want to allow all traffic for debugging purposes | ||
#tfsec:ignore:aws-ec2-no-excessive-port-access | ||
resource "aws_network_acl_rule" "egress_allow_all" { | ||
count = local.infrastructure_vpc && !local.infrastructure_vpc_network_acl_egress_lockdown ? 1 : 0 | ||
|
||
network_acl_id = aws_network_acl.infrastructure[0].id | ||
egress = true | ||
rule_number = 100 | ||
|
||
rule_action = "allow" | ||
protocol = "-1" | ||
from_port = 0 | ||
to_port = 0 | ||
cidr_block = "0.0.0.0/0" | ||
} | ||
|
||
resource "aws_network_acl_rule" "egress" { | ||
count = local.infrastructure_vpc ? length(local.infrastructure_vpc_network_acl_egress_custom_rules) : 0 | ||
|
||
network_acl_id = aws_network_acl.infrastructure[0].id | ||
rule_number = count.index + 1 | ||
egress = true | ||
protocol = local.infrastructure_vpc_network_acl_egress_custom_rules[count.index]["protocol"] | ||
rule_action = local.infrastructure_vpc_network_acl_egress_custom_rules[count.index]["action"] | ||
cidr_block = local.infrastructure_vpc_network_acl_egress_custom_rules[count.index]["cidr_block"] | ||
from_port = local.infrastructure_vpc_network_acl_egress_custom_rules[count.index]["from_port"] | ||
to_port = local.infrastructure_vpc_network_acl_egress_custom_rules[count.index]["to_port"] | ||
} | ||
|
||
#This will only be used if `infrastructure_vpc_network_acl_ingress_lockdown` isn't set | ||
#We would want to allow all traffic for debugging purposes | ||
#tfsec:ignore:aws-ec2-no-excessive-port-access tfsec:ignore:aws-ec2-no-public-ingress-acl | ||
resource "aws_network_acl_rule" "ingress_allow_all" { | ||
count = local.infrastructure_vpc && !local.infrastructure_vpc_network_acl_ingress_lockdown ? 1 : 0 | ||
|
||
network_acl_id = aws_network_acl.infrastructure[0].id | ||
egress = false | ||
rule_number = 100 | ||
|
||
rule_action = "allow" | ||
protocol = "-1" | ||
from_port = 0 | ||
to_port = 0 | ||
cidr_block = "0.0.0.0/0" | ||
} | ||
|
||
resource "aws_network_acl_rule" "ingress" { | ||
count = local.infrastructure_vpc ? length(local.infrastructure_vpc_network_acl_ingress_custom_rules) : 0 | ||
|
||
network_acl_id = aws_network_acl.infrastructure[0].id | ||
rule_number = count.index + 1 | ||
egress = false | ||
protocol = local.infrastructure_vpc_network_acl_ingress_custom_rules[count.index]["protocol"] | ||
rule_action = local.infrastructure_vpc_network_acl_ingress_custom_rules[count.index]["action"] | ||
cidr_block = local.infrastructure_vpc_network_acl_ingress_custom_rules[count.index]["cidr_block"] | ||
from_port = local.infrastructure_vpc_network_acl_ingress_custom_rules[count.index]["from_port"] | ||
to_port = local.infrastructure_vpc_network_acl_ingress_custom_rules[count.index]["to_port"] | ||
} |