-
Notifications
You must be signed in to change notification settings - Fork 0
/
security_group.tf
34 lines (31 loc) · 1.07 KB
/
security_group.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
resource "aws_security_group" "access_via_nat" {
count = local.nat_instance ? 1 : 0
name = "Access to NAT instance"
description = "Access to Internet via NAT instance for private nodes"
vpc_id = aws_vpc.project.id
# outbound internet access
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group_rule" "allow_inbound_traffic_app" {
count = local.nat_instance ? 1 : 0
type = "ingress"
from_port = 0
to_port = 65535
protocol = "all"
cidr_blocks = [aws_subnet.private_app.cidr_block]
security_group_id = aws_security_group.access_via_nat[count.index].id
}
resource "aws_security_group_rule" "allow_inbound_traffic_db" {
count = local.nat_instance ? 1 : 0
type = "ingress"
from_port = 0
to_port = 65535
protocol = "all"
cidr_blocks = [aws_subnet.private_db.cidr_block]
security_group_id = aws_security_group.access_via_nat[count.index].id
}