-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsg.tf
50 lines (45 loc) · 1.75 KB
/
sg.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
resource "aws_security_group" "ecs_sg" {
#checkov:skip=CKV2_AWS_5:Security group is attached to another resource
#checkov:skip=CKV_AWS_382: "Ensure no security groups allow egress from 0.0.0.0:0 to port -1"
name = "ecs-sg-${var.name}"
description = "Allow inbound traffic"
vpc_id = data.aws_vpc.default.id
ingress {
description = "Allow inbound traffic from the load balancer"
from_port = 80
to_port = 80
protocol = "tcp"
security_groups = [aws_security_group.lb_public_sg.id]
}
egress {
description = "Allow outbound traffic from ECS"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"] #tfsec:ignore:aws-ec2-no-public-egress-sgr
}
}
resource "aws_security_group" "lb_public_sg" {
#checkov:skip=CKV_AWS_260:Load balancer security group requires ingress from all on port 80
#checkov:skip=CKV2_AWS_5:Security group is attached to another resource
name = "lb-public-sg-${var.name}"
description = "Allow inbound traffic"
vpc_id = data.aws_vpc.default.id
ingress {
description = "Allow HTTP inbound traffic on the load balancer listener port"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] #tfsec:ignore:aws-ec2-no-public-ingress-sgr
}
}
resource "aws_security_group_rule" "lb_sg_allow_all" {
#checkov:skip=CKV_AWS_382: "Ensure no security groups allow egress from 0.0.0.0:0 to port -1"
description = "Allow all outbound traffic"
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
security_group_id = aws_security_group.lb_public_sg.id
cidr_blocks = ["0.0.0.0/0"] #tfsec:ignore:aws-ec2-no-public-egress-sgr
}