Skip to content

Commit 5c3c1af

Browse files
committed
Some simplification of security groups. We don't need to ssh into the frontend and backend; instead we can use AWS ECS Exec to run commands inside running containers.
1 parent d086afc commit 5c3c1af

File tree

4 files changed

+24
-48
lines changed

4 files changed

+24
-48
lines changed

terraform/environments/development/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ module "ecs" {
6767
frontend_sg_id = module.security_groups.frontend_sg_id
6868
backend_sg_id = module.security_groups.backend_sg_id
6969
alb_sg_id = module.security_groups.alb_sg_id
70+
bastion_sg_id = module.security_groups.bastion_sg_id
7071
ecs_task_execution_role = module.iam.ecs_task_execution_role_arn
7172
ecs_task_role_arn = module.iam.ecs_task_role_arn
7273
service_discovery_namespace_id = module.service_discovery.namespace_id

terraform/modules/ecs/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ resource "aws_ecs_service" "frontend" {
100100
network_configuration {
101101
subnets = var.private_subnet_ids
102102
security_groups = [var.frontend_sg_id, var.alb_sg_id]
103-
assign_public_ip = true
103+
assign_public_ip = false
104104
}
105105

106106
load_balancer {

terraform/modules/ecs/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ variable "alb_sg_id" {
4848
type = string
4949
}
5050

51+
variable "bastion_sg_id" {
52+
description = "The ID of the security group to attach to the bastion host"
53+
type = string
54+
}
55+
5156
variable "ecs_task_execution_role" {
5257
description = "The ARN of the ECS task execution role"
5358
type = string

terraform/modules/security_groups/main.tf

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,25 @@ resource "aws_security_group" "alb_sg" {
44
vpc_id = var.vpc_id
55

66
ingress {
7-
from_port = 0
8-
to_port = 65535
7+
from_port = 80
8+
to_port = 80
99
protocol = "tcp"
1010
cidr_blocks = ["0.0.0.0/0"]
1111
}
1212

13-
# ingress {
14-
# from_port = 80
15-
# to_port = 80
16-
# protocol = "tcp"
17-
# cidr_blocks = ["0.0.0.0/0"]
18-
# }
19-
20-
# ingress {
21-
# from_port = 443
22-
# to_port = 443
23-
# protocol = "tcp"
24-
# cidr_blocks = ["0.0.0.0/0"]
25-
# }
13+
ingress {
14+
from_port = 443
15+
to_port = 443
16+
protocol = "tcp"
17+
cidr_blocks = ["0.0.0.0/0"]
18+
}
2619

27-
# ingress {
28-
# from_port = 3000
29-
# to_port = 3000
30-
# protocol = "tcp"
31-
# cidr_blocks = ["0.0.0.0/0"]
32-
# }
20+
ingress {
21+
from_port = 3000
22+
to_port = 3000
23+
protocol = "tcp"
24+
cidr_blocks = ["0.0.0.0/0"]
25+
}
3326

3427
egress {
3528
from_port = 0
@@ -53,25 +46,14 @@ resource "aws_security_group" "frontend_sg" {
5346
from_port = 80
5447
to_port = 80
5548
protocol = "tcp"
56-
cidr_blocks = ["0.0.0.0/0"]
57-
# security_groups = [aws_security_group.alb_sg.id]
49+
security_groups = [aws_security_group.alb_sg.id]
5850
}
5951

60-
# need to set up load balancer for ssh
6152
ingress {
6253
from_port = 443
6354
to_port = 443
6455
protocol = "tcp"
65-
cidr_blocks = ["0.0.0.0/0"]
66-
# security_groups = [aws_security_group.alb_sg.id]
67-
}
68-
69-
ingress {
70-
from_port = 22
71-
to_port = 22
72-
protocol = "tcp"
73-
cidr_blocks = ["0.0.0.0/0"]
74-
# security_groups = [aws_security_group.bastion_sg.id]
56+
security_groups = [aws_security_group.alb_sg.id]
7557
}
7658

7759
egress {
@@ -96,19 +78,7 @@ resource "aws_security_group" "backend_sg" {
9678
from_port = 3000
9779
to_port = 3000
9880
protocol = "tcp"
99-
cidr_blocks = ["0.0.0.0/0"]
100-
security_groups = [
101-
aws_security_group.bastion_sg.id,
102-
aws_security_group.frontend_sg.id
103-
]
104-
}
105-
106-
ingress {
107-
from_port = 22
108-
to_port = 22
109-
protocol = "tcp"
110-
cidr_blocks = ["0.0.0.0/0"]
111-
security_groups = [aws_security_group.bastion_sg.id]
81+
security_groups = [aws_security_group.alb_sg.id]
11282
}
11383

11484
egress {

0 commit comments

Comments
 (0)