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
10 changes: 9 additions & 1 deletion terraform/app/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ resource "aws_ecs_cluster" "cluster" {
module "web_service" {
source = "./modules/ecs_service"
task_config = {
environment = local.task_envs
environment = concat(
local.task_envs,
[
{
name = "REDIS_CACHE_URL"
value = aws_elasticache_serverless_cache.rails_cache.endpoint[0].address
}
]
)
secrets = local.task_secrets
cpu = 1024
memory = 3072
Expand Down
66 changes: 65 additions & 1 deletion terraform/app/valkey.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
################ SIDEKIQ CACHE FOR JOB PROCESSING #####################

resource "aws_security_group" "valkey" {
name = "mavis-cache-${var.environment}"
description = "Security group for Valkey ElastiCache (self-designed cluster)"
Expand Down Expand Up @@ -109,4 +111,66 @@ resource "aws_cloudwatch_log_group" "valkey_engine_log" {
tags = {
Name = "mavis-cache-engine-log-${var.environment}"
}
}
}


################ REDIS CACHE FOR CACHING DB QUERIES #####################

resource "aws_security_group" "rails_valkey" {
name = "mavis-cache-rails-${var.environment}"
description = "Security group for Valkey ElastiCache for the rails service"
vpc_id = aws_vpc.application_vpc.id

tags = {
Name = "mavis-cache-rails-${var.environment}"
}

lifecycle {
ignore_changes = [description]
}
}

resource "aws_security_group_rule" "rails_valkey_ingress" {
type = "ingress"
from_port = aws_elasticache_serverless_cache.rails_cache.endpoint[0].port
to_port = aws_elasticache_serverless_cache.rails_cache.endpoint[0].port
protocol = "tcp"
security_group_id = aws_security_group.rails_valkey.id
source_security_group_id = module.web_service.security_group_id

lifecycle {
create_before_destroy = true
}
}

resource "aws_elasticache_parameter_group" "rails" {
family = "valkey8"
name = "mavis-cache-rails-params-${var.environment}"

parameter {
name = "maxmemory-policy"
value = "allkeys-lfu"
}

tags = {
Name = "mavis-cache-rails-params-${var.environment}"
}
}

resource "aws_elasticache_serverless_cache" "rails_cache" {
engine = "valkey"
name = "mavis-cache-rails-${var.environment}"
description = "Rails cache for web servers"
cache_usage_limits {
data_storage {
maximum = 1
unit = "GB"
}
ecpu_per_second {
maximum = 1000
}
}
major_engine_version = "8"
security_group_ids = [aws_security_group.rails_valkey.id]
subnet_ids = [aws_subnet.private_subnet_a.id, aws_subnet.private_subnet_b.id]
}