variable "datacenters" { description = "List of datacenters to deploy to" type = list(string) default = ["dc1"] } variable "redis_version" { description = "Redis Docker image tag" type = string default = "7-alpine" } variable "count" { description = "Number of Redis instances to run" type = number default = 1 } variable "port" { description = "Port to expose Redis on (0 for dynamic)" type = number default = 0 } variable "cpu" { description = "CPU allocation in MHz" type = number default = 500 } variable "memory" { description = "Memory allocation in MB" type = number default = 256 } variable "maxmemory" { description = "Redis maxmemory setting (e.g., 200mb)" type = string default = "200mb" } variable "maxmemory_policy" { description = "Redis eviction policy" type = string default = "allkeys-lru" } variable "service_provider" { description = "Service discovery provider (nomad or consul)" type = string default = "nomad" } job "redis" { type = "service" datacenters = var.datacenters update { max_parallel = 1 min_healthy_time = "10s" healthy_deadline = "3m" auto_revert = true } group "redis" { count = var.count restart { attempts = 10 interval = "5m" delay = "15s" mode = "delay" } network { mode = "bridge" port "redis" { static = var.port > 0 ? var.port : null to = 6379 } } service { name = "redis" port = "redis" provider = var.service_provider tags = [ "cache", "db", ] check { type = "tcp" interval = "10s" timeout = "2s" } } task "redis" { driver = "docker" config { image = "redis:${var.redis_version}" ports = ["redis"] args = [ "redis-server", "--maxmemory", var.maxmemory, "--maxmemory-policy", var.maxmemory_policy, "--appendonly", "yes", ] } resources { cpu = var.cpu memory = var.memory } } } }