-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity.tf
48 lines (41 loc) · 1 KB
/
security.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
resource "aws_security_group" "main" {
name = "${var.app_name}-load-balancer-security-group"
description = "Allows ${var.app_port} to ALB"
vpc_id = aws_vpc.main.id
ingress {
protocol = "tcp"
from_port = var.app_port
to_port = var.app_port
cidr_blocks = ["0.0.0.0/0"]
}
egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "${var.app_name}-alb"
}
}
# Traffic to ecs is restricted to alb
resource "aws_security_group" "ecs_tasks" {
name = "${var.app_name}-ecs-tasks-security-group"
description = "Inbound access from ALB only"
vpc_id = aws_vpc.main.id
ingress {
protocol = "tcp"
from_port = var.app_port
to_port = var.app_port
security_groups = [aws_security_group.main.id]
}
egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "${var.app_name}-ecs"
}
}