-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecuritygroups.tf
More file actions
99 lines (88 loc) · 2.51 KB
/
securitygroups.tf
File metadata and controls
99 lines (88 loc) · 2.51 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
resource "aws_security_group" "AccessToEndpoints" {
name = "AccessToEndpoints"
description = "Allow HTTPs inbound traffic"
vpc_id = module.vpc.vpc_id
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = module.vpc.private_subnets_cidr_blocks
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"] # Allow all outbound traffic
}
tags = {
Name = "AccessToEndpoints"
Environment = "dev"
Name = "task2"
}
}
resource "aws_security_group" "ALBAccess" {
name = "ALBAccess"
description = "Allow ALB inbound traffic"
vpc_id = module.vpc.vpc_id
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"] # Allow all outbound traffic
}
tags = {
Name = "Task2-AccessToALB"
}
}
resource "aws_security_group" "ECSAccess" {
name = "ECSAccess"
description = "Allow ECSA inbound traffic from ALB"
vpc_id = module.vpc.vpc_id
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = module.vpc.public_subnets_cidr_blocks
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"] # Allow all outbound traffic
}
tags = {
Name = "Task2-ECSAccess"
}
}
resource "aws_security_group" "ecs_tasks" {
vpc_id = module.vpc.vpc_id
name = "ecs-tasks-sg"
description = "Allow inbound access to ECS tasks from ALB and other tasks"
# Разрешаем входящий трафик от ALB на порт веб-приложения
ingress {
from_port = var.APP_PORT
to_port = var.APP_PORT
protocol = "tcp"
security_groups = [aws_security_group.ALBAccess.id]
}
# Разрешаем входящий трафик для MongoDB только от ECS задач
# ingress {
# from_port = var.MONGODB_PORT
# to_port = var.MONGODB_PORT
# protocol = "tcp"
# security_groups = [aws_security_group.ecs_tasks.id] # Саморазрешение для общения между контейнерами в одной задаче
# }
# Разрешаем исходящий трафик для ECS задач
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}