Skip to content

Commit

Permalink
Fix: Allowing Port 443 to load balancer (Prod)
Browse files Browse the repository at this point in the history
Fix: Allowing Port 443 to load balancer
  • Loading branch information
IrezD authored Dec 28, 2023
2 parents 0072fba + bde4bda commit 6ce7821
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
6 changes: 6 additions & 0 deletions terraform/acm.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "aws_acm_certificate" "cert" {

domain_name = var.fqdn
validation_method = "EMAIL"

}
16 changes: 10 additions & 6 deletions terraform/alb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@ resource "aws_lb" "alb" {
subnets = var.subnets_for_ecs
}

resource "aws_lb_listener" "front_end" {
resource "aws_lb_listener" "listerner" {
load_balancer_arn = aws_lb.alb.arn
port = "80"
protocol = "HTTP"
port = "443"
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-TLS13-1-2-2021-06"
certificate_arn = aws_acm_certificate.cert.arn

default_action {
type = "forward"
target_group_arn = aws_lb_target_group.target_group_P-5000.arn
target_group_arn = aws_lb_target_group.target_group.arn
}
}

resource "aws_lb_target_group" "target_group_P-5000" {
resource "aws_lb_target_group" "target_group" {
name = "alb-target-group-${var.env}"
port = 5000
protocol = "HTTP"
target_type = "ip"
vpc_id = var.vpc_id
}
}


2 changes: 1 addition & 1 deletion terraform/ecr.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_ecrpublic_repository" "fastapi-ecr-public" {
provider = aws.ecr_region
provider = aws.secondary_region

repository_name = var.repo_name

Expand Down
4 changes: 2 additions & 2 deletions terraform/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ resource "aws_ecs_service" "fastapi-service" {
}

load_balancer {
target_group_arn = aws_lb_target_group.target_group_P-5000.arn
target_group_arn = aws_lb_target_group.target_group.arn
container_name = "${var.env}_FastAPI_image"
container_port = 5000
}



}

Expand Down
2 changes: 1 addition & 1 deletion terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ provider "aws" {
}

provider "aws" {
alias = "ecr_region"
alias = "secondary_region"
region = var.secondary_region

default_tags {
Expand Down
11 changes: 10 additions & 1 deletion terraform/networking.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ resource "aws_security_group" "internet_to_ALB" {
description = "Inbound traffic from the internet into ALB for ${var.env} FastAPI environment"

ingress {
description = "Inbound from Internet to ALB"
description = "Allowing https traffic to ALB from the internet"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}

ingress {
description = "Allowing http traffic to ALB from the internet"
from_port = 80
to_port = 80
protocol = "tcp"
Expand Down
2 changes: 1 addition & 1 deletion terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ variable "fqdn" {
}

variable "hosted_zone_id" {

description = "Hosted zone ID for Route53"
}

0 comments on commit 6ce7821

Please sign in to comment.