Skip to content

Commit 923354c

Browse files
committed
Creating security group rules
1 parent d5d8091 commit 923354c

File tree

1 file changed

+18
-63
lines changed

1 file changed

+18
-63
lines changed

main.tf

Lines changed: 18 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,6 @@ resource "aws_security_group" "ecs_tasks_sg" {
106106
name = "${var.name_preffix}-ecs-tasks-sg"
107107
description = "Allow inbound access from the LB only"
108108
vpc_id = var.vpc_id
109-
110-
ingress {
111-
protocol = "-1"
112-
from_port = 0
113-
to_port = 0
114-
cidr_blocks = ["0.0.0.0/0"]
115-
}
116109
egress {
117110
protocol = "-1"
118111
from_port = 0
@@ -124,60 +117,22 @@ resource "aws_security_group" "ecs_tasks_sg" {
124117
}
125118
}
126119

127-
# resource "aws_security_group_rule" "ingress_through_http" {
128-
# for_each = data.aws_lb_target_group.lb_http_target_groups
129-
# security_group_id = aws_security_group.ecs_tasks_sg.id
130-
# type = "ingress"
131-
# from_port = each.value.port
132-
# to_port = each.value.port
133-
# protocol = "tcp"
134-
# source_security_group_id = var.load_balancer_sg_id
135-
# }
136-
137-
# resource "aws_security_group_rule" "ingress_through_https" {
138-
# for_each = data.aws_lb_target_group.lb_https_target_groups
139-
# security_group_id = aws_security_group.ecs_tasks_sg.id
140-
# type = "ingress"
141-
# from_port = each.value.port
142-
# to_port = each.value.port
143-
# protocol = "tcp"
144-
# source_security_group_id = var.load_balancer_sg_id
145-
# }
146-
147-
148-
149-
150-
151-
152-
153-
# variable "http_ports" {
154-
# description = "The list of ports to configure for HTTP access"
155-
# type = list(number)
156-
# default = [ 80 ]
157-
# }
158-
159-
# variable "https_ports" {
160-
# description = "The ports of ports to configure for HTTPS access"
161-
# type = list(number)
162-
# default = [ 443 ]
163-
# }
164-
165-
# resource "aws_security_group_rule" "ingress_through_http" {
166-
# count = var.enable_http ? length(var.http_ports) : 0
167-
# security_group_id = aws_security_group.ecs_tasks_sg.id
168-
# type = "ingress"
169-
# from_port = element(var.http_ports, count.index)
170-
# to_port = element(var.http_ports, count.index)
171-
# protocol = "tcp"
172-
# security_groups = [module.alb.aws_security_group_lb_access_sg_id]
173-
# }
120+
resource "aws_security_group_rule" "ingress_through_http" {
121+
count = length(data.aws_lb_target_group.lb_http_target_groups)
122+
security_group_id = aws_security_group.ecs_tasks_sg.id
123+
type = "ingress"
124+
from_port = element(data.aws_lb_target_group.lb_http_target_groups.*.port, count.index)
125+
to_port = element(data.aws_lb_target_group.lb_http_target_groups.*.port, count.index)
126+
protocol = "tcp"
127+
source_security_group_id = var.load_balancer_sg_id
128+
}
174129

175-
# resource "aws_security_group_rule" "ingress_through_https" {
176-
# count = var.enable_http ? length(var.https_ports) : 0
177-
# security_group_id = aws_security_group.ecs_tasks_sg.id
178-
# type = "ingress"
179-
# from_port = element(var.https_ports, count.index)
180-
# to_port = element(var.https_ports, count.index)
181-
# protocol = "tcp"
182-
# security_groups = [module.alb.aws_security_group_lb_access_sg_id]
183-
# }
130+
resource "aws_security_group_rule" "ingress_through_https" {
131+
count = length(data.aws_lb_target_group.lb_https_target_groups)
132+
security_group_id = aws_security_group.ecs_tasks_sg.id
133+
type = "ingress"
134+
from_port = element(data.aws_lb_target_group.lb_https_target_groups.*.port, count.index)
135+
to_port = element(data.aws_lb_target_group.lb_https_target_groups.*.port, count.index)
136+
protocol = "tcp"
137+
source_security_group_id = var.load_balancer_sg_id
138+
}

0 commit comments

Comments
 (0)