Skip to content
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
4 changes: 4 additions & 0 deletions infrastructure/environments/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ module "alb" {
frontend_container_port = var.frontend_container_port
frontend_health_check_path = var.frontend_health_check_path

# Sticky sessions required: backend uses SQLite (local file DB) so all
# requests from a client must route to the same task to preserve sessions.
enable_stickiness = true

enable_deletion_protection = true # Protect production ALB
}

Expand Down
9 changes: 9 additions & 0 deletions infrastructure/modules/alb/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# =============================================================================

Check warning on line 1 in infrastructure/modules/alb/main.tf

View workflow job for this annotation

GitHub Actions / TFLint Analysis

terraform "required_version" attribute is required
# ALB Module
# Creates Application Load Balancer with optional HTTPS
# =============================================================================
Expand All @@ -8,7 +8,7 @@
# -----------------------------------------------------------------------------

data "aws_caller_identity" "current" {}
data "aws_region" "current" {}

Check warning on line 11 in infrastructure/modules/alb/main.tf

View workflow job for this annotation

GitHub Actions / TFLint Analysis

data "aws_region" "current" is declared but not used

# ELB service account for access logs (varies by region)
data "aws_elb_service_account" "main" {}
Expand Down Expand Up @@ -342,6 +342,15 @@
matcher = "200"
}

dynamic "stickiness" {
for_each = var.enable_stickiness ? [1] : []
content {
type = "lb_cookie"
cookie_duration = var.stickiness_duration
enabled = true
}
}

tags = merge(var.tags, {
Name = "${var.project_name}-${var.environment}-tg"
})
Expand Down Expand Up @@ -496,7 +505,7 @@
# Route53 Record (optional)
# -----------------------------------------------------------------------------

data "aws_route53_zone" "main" {

Check warning on line 508 in infrastructure/modules/alb/main.tf

View workflow job for this annotation

GitHub Actions / TFLint Analysis

data "aws_route53_zone" "main" is declared but not used
count = var.domain_name != "" && var.route53_zone_id != "" ? 1 : 0

zone_id = var.route53_zone_id
Expand Down Expand Up @@ -533,7 +542,7 @@
ttl = 60
}

resource "aws_acm_certificate_validation" "main" {

Check warning on line 545 in infrastructure/modules/alb/main.tf

View workflow job for this annotation

GitHub Actions / TFLint Analysis

Missing version constraint for provider "aws" in `required_providers`
count = var.domain_name != "" && var.certificate_arn == "" && var.route53_zone_id != "" ? 1 : 0

certificate_arn = aws_acm_certificate.main[0].arn
Expand Down
12 changes: 12 additions & 0 deletions infrastructure/modules/alb/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ variable "access_logs_prefix" {
# Frontend Configuration (Optional)
# -----------------------------------------------------------------------------

variable "enable_stickiness" {
description = "Enable sticky sessions on backend target group (required when using SQLite with multiple backend tasks)"
type = bool
default = false
}

variable "stickiness_duration" {
description = "Duration (in seconds) for sticky session cookies"
type = number
default = 86400
}

variable "frontend_container_port" {
description = "Port the frontend container listens on (set > 0 to enable frontend routing)"
type = number
Expand Down
Loading