Skip to content

Commit b6c37ce

Browse files
committed
Cleanup formatting and add SG ingress rule to EC2 from ALB
1 parent 919f810 commit b6c37ce

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

comet-infrastructure/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ module "comet_ec2" {
3636
comet_ec2_volume_size = var.comet_ec2_volume_size
3737
comet_ec2_key = var.comet_ec2_key
3838

39-
alb_enabled = var.enable_ec2_alb
39+
alb_enabled = var.enable_ec2_alb
40+
comet_ec2_alb_sg = var.enable_ec2_alb ? module.comet_ec2_alb[0].comet_alb_sg : null
4041

4142
s3_enabled = var.enable_s3
4243
comet_ml_s3_bucket = var.s3_bucket_name

comet-infrastructure/modules/comet_ec2/main.tf

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ resource "aws_vpc_security_group_ingress_rule" "comet_ec2_ingress_ssh" {
173173
from_port = local.ssh_port
174174
to_port = local.ssh_port
175175
ip_protocol = "tcp"
176-
# make more restrictive
177176
cidr_ipv4 = local.cidr_anywhere
178177
}
179178

@@ -183,7 +182,6 @@ resource "aws_vpc_security_group_ingress_rule" "comet_ec2_ingress_http" {
183182
from_port = local.http_port
184183
to_port = local.http_port
185184
ip_protocol = "tcp"
186-
# make more restrictive
187185
cidr_ipv4 = local.cidr_anywhere
188186
}
189187

@@ -193,20 +191,18 @@ resource "aws_vpc_security_group_ingress_rule" "comet_ec2_ingress_https" {
193191
from_port = local.https_port
194192
to_port = local.https_port
195193
ip_protocol = "tcp"
196-
# make more restrictive
197194
cidr_ipv4 = local.cidr_anywhere
198195
}
199196

200-
/*
201197
resource "aws_vpc_security_group_ingress_rule" "comet_ec2_alb_http" {
198+
count = var.alb_enabled ? 1 : 0
202199
security_group_id = aws_security_group.comet_ec2_sg.id
203200

204-
from_port = local.http_port
205-
to_port = local.http_port
206-
ip_protocol = "tcp"
207-
security_groups = [var.comet_ec2_alb_sg.id]
201+
from_port = local.http_port
202+
to_port = local.http_port
203+
ip_protocol = "tcp"
204+
referenced_security_group_id = var.comet_ec2_alb_sg
208205
}
209-
*/
210206

211207
resource "aws_vpc_security_group_egress_rule" "comet_ec2_egress_any" {
212208
security_group_id = aws_security_group.comet_ec2_sg.id

comet-infrastructure/modules/comet_ec2/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,9 @@ variable "comet_ml_s3_bucket" {
6565
variable "comet_ec2_s3_iam_policy" {
6666
description = "Policy granting access to Comet S3 bucket"
6767
type = string
68+
}
69+
70+
variable "comet_ec2_alb_sg" {
71+
description = "ID of the security group attached to an associated application load balancer, for creating ingress EC2 SG rule"
72+
type = string
6873
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
output "alb_dns_name" {
22
description = "DNS name of the ALB"
33
value = module.alb.lb_dns_name
4+
}
5+
6+
output "comet_alb_sg" {
7+
description = "ID of the security group created for the ALB"
8+
value = aws_security_group.comet_alb_sg.id
49
}

0 commit comments

Comments
 (0)