Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix lb security groups #53

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions infrastructure/modules/app-cluster/load_balancer.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resource "aws_alb" "application_load_balancer" {
internal = false
load_balancer_type = "application"
subnets = var.public_subnet_ids_list
security_groups = [aws_security_group.load_balancer_security_group.id]
security_groups = [aws_security_group.load_balancer_security_group_http.id, aws_security_group.load_balancer_security_group_https.id]
drop_invalid_header_fields = true
enable_deletion_protection = true

Expand Down Expand Up @@ -64,7 +64,7 @@ POLICY
data "aws_ec2_managed_prefix_list" "cloudwatch" {
name = "com.amazonaws.global.cloudfront.origin-facing"
}
resource "aws_security_group" "load_balancer_security_group" {
resource "aws_security_group" "load_balancer_security_group_http" {
# checkov:skip=CKV_AWS_260: Limits by prefix list ID's
vpc_id = var.vpc_id
description = "ALB Security Group"
Expand All @@ -75,13 +75,6 @@ resource "aws_security_group" "load_balancer_security_group" {
prefix_list_ids = [data.aws_ec2_managed_prefix_list.cloudwatch.id]
description = "Allow HTTP ingress"
}
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
prefix_list_ids = [data.aws_ec2_managed_prefix_list.cloudwatch.id]
description = "Allow HTTPS ingress"
}
egress {
from_port = 0
to_port = 0
Expand All @@ -96,6 +89,23 @@ resource "aws_security_group" "load_balancer_security_group" {
create_before_destroy = true
}
}
resource "aws_security_group" "load_balancer_security_group_https" {
# checkov:skip=CKV_AWS_260: Limits by prefix list ID's
vpc_id = var.vpc_id
description = "ALB Security Group"
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
prefix_list_ids = [data.aws_ec2_managed_prefix_list.cloudwatch.id]
description = "Allow HTTPS ingress"
}
tags = var.tags

lifecycle {
create_before_destroy = true
}
}

resource "aws_lb_target_group" "target_group" {
name = "${var.resource-name-prefix}-tg"
Expand Down
5 changes: 3 additions & 2 deletions infrastructure/modules/app-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ resource "aws_ecs_service" "aws-ecs-service" {
assign_public_ip = false
security_groups = [
aws_security_group.service_security_group.id,
aws_security_group.load_balancer_security_group.id
aws_security_group.load_balancer_security_group_http.id,
aws_security_group.load_balancer_security_group_https.id
]
}

Expand All @@ -376,7 +377,7 @@ resource "aws_security_group" "service_security_group" {
from_port = 0
to_port = 0
protocol = "-1"
security_groups = [aws_security_group.load_balancer_security_group.id]
security_groups = [aws_security_group.load_balancer_security_group_http.id, aws_security_group.load_balancer_security_group_https.id]
description = "Allow traffic from load balancer"
}

Expand Down
Loading