This repository has been archived by the owner on Sep 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsecurity_groups.tf
85 lines (75 loc) · 2.19 KB
/
security_groups.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
# Internal load balancer security group
resource "aws_security_group" "alb_internal" {
name = "${var.app}-${var.env}-alb-internal"
description = "Allowed ports in internal load balancer"
vpc_id = local.vpc_id
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["10.0.0.0/8"]
}
egress {
description = "Allow outbound traffic"
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = ["0.0.0.0/0"]
}
}
# Public load balancer security group
resource "aws_security_group" "alb_public" {
name = "${var.app}-${var.env}-alb-public"
description = "Allowed ports to public load balancer"
vpc_id = local.vpc_id
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
description = "Allow outbound traffic"
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = ["0.0.0.0/0"]
}
}
# ECS Service Security Group
resource "aws_security_group" "service" {
name = "${var.app}-${var.env}-service"
description = "Allow traffic to ECS service from load balancers"
vpc_id = local.vpc_id
ingress {
description = "Allow api container port from internal ALB"
from_port = local.api_container_port
to_port = local.api_container_port
protocol = "tcp"
security_groups = [aws_security_group.alb_internal.id]
self = true
}
ingress {
description = "Allow web container port from internal ALB"
from_port = local.web_container_port
to_port = local.web_container_port
protocol = "tcp"
security_groups = [aws_security_group.alb_internal.id]
self = true
}
ingress {
description = "Allow landing container port from public ALB"
from_port = local.landing_container_port
to_port = local.landing_container_port
protocol = "tcp"
security_groups = [aws_security_group.alb_public.id]
self = true
}
egress {
description = "Allow outbound traffic"
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = ["0.0.0.0/0"]
}
}