11# Create an Application Load Balancer (ALB)
22resource "aws_lb" "httpd_alb" {
33 name = " ${ var . project } -${ var . venue } -httpd-alb"
4- internal = false
4+ internal = true
55 load_balancer_type = " application"
66 security_groups = [aws_security_group . ecs_alb_sg . id ]
7- subnets = local. public_subnet_ids
7+ subnets = local. subnet_ids
88 enable_deletion_protection = false
99 preserve_host_header = true
1010 tags = {
@@ -110,16 +110,6 @@ resource "aws_vpc_security_group_ingress_rule" "ecs_alb_ingress_sg_rule" {
110110 referenced_security_group_id = aws_security_group. ecs_alb_sg . id
111111}
112112
113- # Add a new ingress rule to the ECS ALB's security group, opening it up to other connections
114- # tfsec:ignore:AVD-AWS-0107
115- resource "aws_vpc_security_group_ingress_rule" "alb_all_ingress_sg_rule" {
116- security_group_id = aws_security_group. ecs_alb_sg . id
117- to_port = 8080
118- from_port = 8080
119- ip_protocol = " tcp"
120- cidr_ipv4 = " 0.0.0.0/0"
121- }
122-
123113# Add a new egress rule to the ECS's security group, allowing ECS to fetch the container images/proxy
124114resource "aws_vpc_security_group_egress_rule" "ecs_egress_sg_rule" {
125115 security_group_id = aws_security_group. ecs_sg . id
@@ -137,3 +127,23 @@ resource "aws_vpc_security_group_egress_rule" "ecs_alb_egress_sg_rule" {
137127 ip_protocol = " tcp"
138128 cidr_ipv4 = " 0.0.0.0/0"
139129}
130+
131+ data "aws_ssm_parameter" "shared-services_security_group" {
132+ name = " arn:aws:ssm:${ data . aws_ssm_parameter . shared_service_region . value } :${ data . aws_ssm_parameter . shared_service_account_id . value } :parameter/unity/shared-services/network/httpd_security_group"
133+ }
134+
135+ resource "aws_vpc_security_group_ingress_rule" "ecs_alb_sg_ingress_rule" {
136+ security_group_id = aws_security_group. ecs_alb_sg . id
137+ from_port = 8080
138+ to_port = 8080
139+ ip_protocol = " tcp"
140+ referenced_security_group_id = data. aws_ssm_parameter . shared-services_security_group . value
141+ }
142+
143+ resource "aws_vpc_security_group_egress_rule" "ecs_sg_egress_rule" {
144+ security_group_id = aws_security_group. ecs_sg . id
145+ from_port = 0
146+ to_port = 65535
147+ ip_protocol = " tcp"
148+ referenced_security_group_id = data. aws_security_group . mc_alb_sg . id
149+ }
0 commit comments