-
Notifications
You must be signed in to change notification settings - Fork 0
/
security.tf
46 lines (40 loc) · 1.21 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
# ALB Security Group: Will only open to VPN Dev.
resource "aws_security_group" "alb" {
name = "${local.name_prefix}-alb-sg"
description = "controls access to the ALB to allow HTTP traffic only from the dev vpn."
vpc_id = var.create_vpc == true ? aws_vpc.main[0].id : var.vpc_id
ingress {
description = "TCP traffic from allowed blocks."
protocol = "tcp"
from_port = var.host_port
to_port = var.host_port
cidr_blocks = var.allowed_cidr_blocks
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
lifecycle {
create_before_destroy = true
}
}
# Traffic to the ECS cluster should only come from the ALB
resource "aws_security_group" "ecs" {
name = "${local.name_prefix}-ecs-tasks-sg"
description = "allow inbound access from the ALB only"
vpc_id = var.create_vpc == true ? aws_vpc.main[0].id : var.vpc_id
ingress {
protocol = "tcp"
from_port = var.container_port
to_port = var.container_port
security_groups = [aws_security_group.alb.id]
}
egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
}