Skip to content
This repository was archived by the owner on Mar 20, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module "vpc" {
enable_nat_gateway = true
enable_per_az_nat_gateway = true

nacl_public_custom = [
{
nacl_public_custom = {
allow_https = {
rule_number = 1000
egress = false
protocol = 6
Expand All @@ -23,7 +23,25 @@ module "vpc" {
from_port = 443
to_port = 443
}
]
allow_http = {
rule_number = 1001
egress = false
protocol = 6
rule_action = "allow"
cidr_block = "0.0.0.0/0"
from_port = 80
to_port = 80
}
allow_ssh = {
rule_number = 1002
egress = false
protocol = 6
rule_action = "allow"
cidr_block = "0.0.0.0/0"
from_port = 22
to_port = 22
}
}

tags = {
Owner = "Foo"
Expand Down
28 changes: 14 additions & 14 deletions nacls-private.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,6 @@ resource "aws_network_acl_rule" "private_all_ephemeral_udp_egress" {
to_port = 65535
}

resource "aws_network_acl_rule" "private_custom" {
count = var.nacl_private_custom != null ? length(var.nacl_private_custom) : 0

network_acl_id = aws_network_acl.private.id

rule_number = var.nacl_private_custom[count.index].rule_number
egress = var.nacl_private_custom[count.index].egress
protocol = var.nacl_private_custom[count.index].protocol
rule_action = var.nacl_private_custom[count.index].rule_action
cidr_block = var.nacl_private_custom[count.index].cidr_block
from_port = var.nacl_private_custom[count.index].from_port
to_port = var.nacl_private_custom[count.index].to_port
}

resource "aws_network_acl_rule" "private_allow_http_egress" {
count = var.nacl_allow_all_http ? 1 : 0

Expand Down Expand Up @@ -130,3 +116,17 @@ resource "aws_network_acl_rule" "private_allow_https_egress" {
from_port = 443
to_port = 443
}

resource "aws_network_acl_rule" "private_custom" {
for_each = var.nacl_private_custom

network_acl_id = aws_network_acl.private.id

rule_number = each.value.rule_number
egress = each.value.egress
protocol = each.value.protocol
rule_action = each.value.rule_action
cidr_block = each.value.cidr_block
from_port = each.value.from_port
to_port = each.value.to_port
}
28 changes: 14 additions & 14 deletions nacls-public.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,6 @@ resource "aws_network_acl_rule" "public_all_ephemeral_udp_egress" {
to_port = 65535
}

resource "aws_network_acl_rule" "public_custom" {
count = var.nacl_public_custom != null ? length(var.nacl_public_custom) : 0

network_acl_id = aws_network_acl.public.id

rule_number = var.nacl_public_custom[count.index].rule_number
egress = var.nacl_public_custom[count.index].egress
protocol = var.nacl_public_custom[count.index].protocol
rule_action = var.nacl_public_custom[count.index].rule_action
cidr_block = var.nacl_public_custom[count.index].cidr_block
from_port = var.nacl_public_custom[count.index].from_port
to_port = var.nacl_public_custom[count.index].to_port
}

resource "aws_network_acl_rule" "public_allow_http_egress" {
count = var.nacl_allow_all_http ? 1 : 0

Expand Down Expand Up @@ -130,3 +116,17 @@ resource "aws_network_acl_rule" "public_allow_https_egress" {
from_port = 443
to_port = 443
}

resource "aws_network_acl_rule" "public_custom" {
for_each = var.nacl_public_custom

network_acl_id = aws_network_acl.public.id

rule_number = each.value.rule_number
egress = each.value.egress
protocol = each.value.protocol
rule_action = each.value.rule_action
cidr_block = each.value.cidr_block
from_port = each.value.from_port
to_port = each.value.to_port
}
28 changes: 14 additions & 14 deletions nacls-secure.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,6 @@ resource "aws_network_acl_rule" "secure_block_public_egress" {
cidr_block = local.public_tier_subnet
}

resource "aws_network_acl_rule" "secure_custom" {
count = var.nacl_secure_custom != null ? length(var.nacl_secure_custom) : 0

network_acl_id = aws_network_acl.secure.id

rule_number = var.nacl_secure_custom[count.index].rule_number
egress = var.nacl_secure_custom[count.index].egress
protocol = var.nacl_secure_custom[count.index].protocol
rule_action = var.nacl_secure_custom[count.index].rule_action
cidr_block = var.nacl_secure_custom[count.index].cidr_block
from_port = var.nacl_secure_custom[count.index].from_port
to_port = var.nacl_secure_custom[count.index].to_port
}

resource "aws_network_acl_rule" "secure_allow_http_egress" {
count = var.nacl_allow_all_http ? 1 : 0

Expand Down Expand Up @@ -154,3 +140,17 @@ resource "aws_network_acl_rule" "secure_allow_https_egress" {
from_port = 443
to_port = 443
}

resource "aws_network_acl_rule" "secure_custom" {
for_each = var.nacl_secure_custom

network_acl_id = aws_network_acl.secure.id

rule_number = each.value.rule_number
egress = each.value.egress
protocol = each.value.protocol
rule_action = each.value.rule_action
cidr_block = each.value.cidr_block
from_port = each.value.from_port
to_port = each.value.to_port
}
37 changes: 6 additions & 31 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -146,48 +146,23 @@ variable "nacl_block_public_to_secure" {
}

variable "nacl_public_custom" {
type = list(object({
rule_number = number,
egress = bool,
protocol = number,
rule_action = string,
cidr_block = string,
from_port = string,
to_port = string
}))
type = map
description = "List of custom nacls to apply to the public tier"
default = null
default = {}
}

variable "nacl_private_custom" {
type = list(object({
rule_number = number,
egress = bool,
protocol = number,
rule_action = string,
cidr_block = string,
from_port = string,
to_port = string
}))
type = map
description = "List of custom nacls to apply to the private tier"
default = null
default = {}
}

variable "nacl_secure_custom" {
type = list(object({
rule_number = number,
egress = bool,
protocol = number,
rule_action = string,
cidr_block = string,
from_port = string,
to_port = string
}))
type = map
description = "List of custom nacls to apply to the secure tier"
default = null
default = {}
}


variable "tags" {
type = map(string)
description = "Tags applied to all resources"
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 0.12.0"
required_version = ">= 0.12.6"

required_providers {
aws = ">= 2.7.0"
Expand Down