forked from DNXLabs/terraform-aws-network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nacl-secure.tf
131 lines (120 loc) · 5.05 KB
/
nacl-secure.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
locals {
secure_subnet_ip = split("/", element(aws_subnet.secure[*].cidr_block, length(aws_subnet.secure[*].cidr_block) - 1))[0]
secure_subnet_summary = var.vpc_cidr_summ != "/0" ? "${cidrhost("${local.secure_subnet_ip}${var.vpc_cidr_summ}", 0)}${var.vpc_cidr_summ}" : aws_vpc.default.cidr_block
}
resource "aws_network_acl" "secure" {
vpc_id = aws_vpc.default.id
subnet_ids = aws_subnet.secure[*].id
tags = merge(
var.tags,
{
"Name" = format(local.names[var.name_pattern].nacl_secure, var.name, local.name_suffix)
"Scheme" = "secure"
"EnvName" = var.name
}
)
}
resource "aws_network_acl_rule" "in_secure_from_secure" {
count = var.vpc_cidr_summ != "/0" ? 1 : length(aws_subnet.secure[*].cidr_block)
network_acl_id = aws_network_acl.secure.id
rule_number = count.index + 101
egress = false
protocol = -1
rule_action = "allow"
cidr_block = var.vpc_cidr_summ != "/0" ? local.secure_subnet_summary : aws_subnet.secure[count.index].cidr_block
}
resource "aws_network_acl_rule" "out_secure_to_secure" {
count = var.vpc_cidr_summ != "/0" ? 1 : length(aws_subnet.secure[*].cidr_block)
network_acl_id = aws_network_acl.secure.id
rule_number = count.index + 1
egress = true
protocol = -1
rule_action = "allow"
cidr_block = var.vpc_cidr_summ != "/0" ? local.secure_subnet_summary : aws_subnet.secure[count.index].cidr_block
}
resource "aws_network_acl_rule" "in_secure_from_private" {
count = var.vpc_cidr_summ != "/0" ? 1 : length(aws_subnet.private[*].cidr_block)
network_acl_id = aws_network_acl.secure.id
rule_number = count.index + 201
egress = false
protocol = -1
rule_action = "allow"
cidr_block = var.vpc_cidr_summ != "/0" ? local.private_subnet_summary : aws_subnet.private[count.index].cidr_block
}
resource "aws_network_acl_rule" "out_secure_to_private" {
count = var.vpc_cidr_summ != "/0" ? 1 : length(aws_subnet.private[*].cidr_block)
network_acl_id = aws_network_acl.secure.id
rule_number = count.index + 101
egress = true
protocol = -1
rule_action = "allow"
cidr_block = var.vpc_cidr_summ != "/0" ? local.private_subnet_summary : aws_subnet.private[count.index].cidr_block
}
resource "aws_network_acl_rule" "in_secure_from_transit" {
count = var.transit_subnet ? var.vpc_cidr_summ != "/0" ? 1 : length(aws_subnet.transit[*].cidr_block) : 0
network_acl_id = aws_network_acl.secure.id
rule_number = count.index + 301
egress = false
protocol = -1
rule_action = "allow"
cidr_block = var.vpc_cidr_summ != "/0" ? local.transit_subnet_summary : aws_subnet.transit[count.index].cidr_block
}
resource "aws_network_acl_rule" "out_secure_to_transit" {
count = var.transit_subnet ? var.vpc_cidr_summ != "/0" ? 1 : length(aws_subnet.transit[*].cidr_block) : 0
network_acl_id = aws_network_acl.secure.id
rule_number = count.index + 201
egress = true
protocol = -1
rule_action = "allow"
cidr_block = var.vpc_cidr_summ != "/0" ? local.transit_subnet_summary : aws_subnet.transit[count.index].cidr_block
}
#############
# S3 Endpoint
#############
resource "aws_network_acl_rule" "in_secure_from_s3" {
count = var.vpc_endpoint_s3_gateway ? length(data.aws_ec2_managed_prefix_list.s3.entries) : 0
network_acl_id = aws_network_acl.secure.id
rule_number = count.index + 501
egress = false
protocol = -1
rule_action = "allow"
cidr_block = tolist(data.aws_ec2_managed_prefix_list.s3.entries)[count.index].cidr
from_port = 0
to_port = 0
}
resource "aws_network_acl_rule" "out_secure_to_s3" {
count = var.vpc_endpoint_s3_gateway ? length(data.aws_ec2_managed_prefix_list.s3.entries) : 0
network_acl_id = aws_network_acl.secure.id
rule_number = count.index + 501
egress = true
protocol = -1
rule_action = "allow"
cidr_block = tolist(data.aws_ec2_managed_prefix_list.s3.entries)[count.index].cidr
from_port = 0
to_port = 0
}
#############
# Dynamodb Endpoint
#############
resource "aws_network_acl_rule" "in_secure_from_dynamodb" {
count = var.vpc_endpoint_dynamodb_gateway ? length(data.aws_ec2_managed_prefix_list.dynamodb.entries) : 0
network_acl_id = aws_network_acl.secure.id
rule_number = count.index + 601
egress = false
protocol = -1
rule_action = "allow"
cidr_block = tolist(data.aws_ec2_managed_prefix_list.dynamodb.entries)[count.index].cidr
from_port = 0
to_port = 0
}
resource "aws_network_acl_rule" "out_secure_to_dynamodb" {
count = var.vpc_endpoint_dynamodb_gateway ? length(data.aws_ec2_managed_prefix_list.dynamodb.entries) : 0
network_acl_id = aws_network_acl.secure.id
rule_number = count.index + 601
egress = true
protocol = -1
rule_action = "allow"
cidr_block = tolist(data.aws_ec2_managed_prefix_list.dynamodb.entries)[count.index].cidr
from_port = 0
to_port = 0
}