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
67 changes: 42 additions & 25 deletions cache/elasticache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ Creates an ElastiCache cluster with support for Redis, Valkey, Memcached, and El
module "redis" {
source = "git::https://github.com/user/ravion-modules.git//cache/elasticache?ref=v1.0.0"

name = "my-redis"
engine = "redis"
node_type = "cache.t4g.micro"
name = "my-redis"
engine = "redis"
engine_major_version = "7"
engine_minor_version = "1"
node_type = "cache.t4g.micro"

vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnet_ids
Expand All @@ -41,10 +43,11 @@ module "redis" {
module "valkey" {
source = "git::https://github.com/user/ravion-modules.git//cache/elasticache?ref=v1.0.0"

name = "my-valkey"
engine = "valkey"
engine_version = "8.0"
node_type = "cache.r7g.large"
name = "my-valkey"
engine = "valkey"
engine_major_version = "8"
engine_minor_version = "0"
node_type = "cache.r7g.large"

replicas_per_node_group = 2
automatic_failover_enabled = true
Expand All @@ -68,6 +71,8 @@ module "redis_cluster" {

name = "my-redis-cluster"
engine = "redis"
engine_major_version = "7"
engine_minor_version = "1"
node_type = "cache.r7g.large"
cluster_mode_enabled = true
num_node_groups = 3
Expand All @@ -94,10 +99,12 @@ module "redis_cluster" {
module "memcached" {
source = "git::https://github.com/user/ravion-modules.git//cache/elasticache?ref=v1.0.0"

name = "my-memcached"
engine = "memcached"
node_type = "cache.t4g.micro"
num_cache_nodes = 3
name = "my-memcached"
engine = "memcached"
engine_major_version = "1.6"
engine_minor_version = "22"
node_type = "cache.t4g.micro"
num_cache_nodes = 3

vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnet_ids
Expand All @@ -112,9 +119,11 @@ module "memcached" {
module "redis_serverless" {
source = "git::https://github.com/user/ravion-modules.git//cache/elasticache?ref=v1.0.0"

name = "my-serverless-redis"
engine = "redis"
serverless_enabled = true
name = "my-serverless-redis"
engine = "redis"
engine_major_version = "7"
engine_minor_version = "1"
serverless_enabled = true

serverless_cache_usage_limits = {
data_storage_maximum = 10 # GB
Expand All @@ -134,9 +143,11 @@ module "redis_serverless" {
module "redis" {
source = "git::https://github.com/user/ravion-modules.git//cache/elasticache?ref=v1.0.0"

name = "my-redis"
engine = "redis"
node_type = "cache.t4g.small"
name = "my-redis"
engine = "redis"
engine_major_version = "7"
engine_minor_version = "1"
node_type = "cache.t4g.small"

vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnet_ids
Expand All @@ -159,9 +170,11 @@ module "redis" {
module "redis" {
source = "git::https://github.com/user/ravion-modules.git//cache/elasticache?ref=v1.0.0"

name = "my-redis"
engine = "redis"
node_type = "cache.t4g.micro"
name = "my-redis"
engine = "redis"
engine_major_version = "7"
engine_minor_version = "1"
node_type = "cache.t4g.micro"

vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnet_ids
Expand All @@ -178,9 +191,11 @@ module "redis" {
module "redis" {
source = "git::https://github.com/user/ravion-modules.git//cache/elasticache?ref=v1.0.0"

name = "my-redis"
engine = "redis"
node_type = "cache.r7g.large"
name = "my-redis"
engine = "redis"
engine_major_version = "7"
engine_minor_version = "1"
node_type = "cache.r7g.large"

vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnet_ids
Expand Down Expand Up @@ -217,8 +232,9 @@ module "redis" {
| vpc_id | The ID of the VPC where the ElastiCache cluster will be created. | `string` | n/a | yes |
| subnet_ids | A list of subnet IDs for the ElastiCache subnet group. | `list(string)` | n/a | yes |
| tags | A map of tags to assign to all resources. | `map(string)` | `{}` | no |
| engine | The cache engine to use: redis, valkey, or memcached. | `string` | `"redis"` | no |
| engine_version | The version number of the cache engine. | `string` | `null` | no |
| engine | The cache engine to use: redis, valkey, or memcached. | `string` | `"valkey"` | no |
| engine_major_version | The major version number of the cache engine. Current latest major versions include Valkey 9, Redis OSS 7, and Memcached 1.6. | `string` | n/a | yes |
| engine_minor_version | Minor or patch version appended to the major version. | `string` | n/a | yes |
| node_type | The compute and memory capacity of the nodes. | `string` | `"cache.t4g.micro"` | no |
| num_cache_nodes | The number of cache nodes (Memcached only). | `number` | `1` | no |
| num_node_groups | The number of node groups (shards) for Redis cluster mode. | `number` | `1` | no |
Expand Down Expand Up @@ -265,6 +281,7 @@ module "redis" {
|------|-------------|
| replication_group_id | The ID of the ElastiCache replication group (Redis/Valkey). |
| replication_group_arn | The ARN of the ElastiCache replication group. |
| replication_group_member_cluster_id | The ID of the first member cache cluster in the replication group. |
| primary_endpoint_address | The address of the primary endpoint (non-cluster mode). |
| reader_endpoint_address | The address of the reader endpoint (non-cluster mode). |
| configuration_endpoint_address | The address of the configuration endpoint (cluster mode). |
Expand Down
4 changes: 2 additions & 2 deletions cache/elasticache/elasticache.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resource "aws_elasticache_replication_group" "this" {

# Engine
engine = var.engine
engine_version = var.engine_version
engine_version = local.engine_version
parameter_group_name = aws_elasticache_parameter_group.this[0].name

# Node configuration
Expand Down Expand Up @@ -101,7 +101,7 @@ resource "aws_elasticache_cluster" "this" {

# Engine
engine = var.engine
engine_version = var.engine_version
engine_version = local.engine_version
parameter_group_name = aws_elasticache_parameter_group.this[0].name

# Node configuration
Expand Down
11 changes: 7 additions & 4 deletions cache/elasticache/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ locals {
# Redis and Valkey share the same resource types
is_redis_compatible = local.is_redis || local.is_valkey

# Engine version
engine_version = var.engine_minor_version != null && var.engine_minor_version != "" ? "${var.engine_major_version}.${var.engine_minor_version}" : var.engine_major_version

# Resource creation flags
is_serverless = var.serverless_enabled && local.is_redis_compatible
create_replication_group = local.is_redis_compatible && !local.is_serverless
Expand All @@ -39,11 +42,11 @@ locals {
# Parameter group family detection
# If not provided, derive from engine and version
default_parameter_group_family = local.is_redis ? (
var.engine_version != null ? "redis${split(".", var.engine_version)[0]}" : "redis7"
"redis${var.engine_major_version}"
) : local.is_valkey ? (
var.engine_version != null ? "valkey${split(".", var.engine_version)[0]}" : "valkey8"
"valkey${var.engine_major_version}"
) : (
var.engine_version != null ? "memcached${replace(var.engine_version, "/\\.[0-9]+$/", "")}" : "memcached1.6"
"memcached${var.engine_major_version}"
)
parameter_group_family = coalesce(var.parameter_group_family, local.default_parameter_group_family)

Expand All @@ -69,7 +72,7 @@ locals {
create_cloudwatch_alarms = var.cloudwatch_alarms_creation_enabled && !local.is_serverless

# Resource identifier for CloudWatch (used in dimensions)
cloudwatch_dimension_value = local.create_replication_group ? aws_elasticache_replication_group.this[0].id : (
cloudwatch_dimension_value = local.create_replication_group ? tolist(aws_elasticache_replication_group.this[0].member_clusters)[0] : (
local.create_cluster ? aws_elasticache_cluster.this[0].cluster_id : null
)

Expand Down
7 changes: 6 additions & 1 deletion cache/elasticache/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ output "replication_group_arn" {
value = local.create_replication_group ? aws_elasticache_replication_group.this[0].arn : null
}

output "replication_group_member_cluster_id" {
description = "The ID of the first member cache cluster in the replication group."
value = local.create_replication_group ? tolist(aws_elasticache_replication_group.this[0].member_clusters)[0] : null
}

output "primary_endpoint_address" {
description = "The address of the primary endpoint for the replication group (non-cluster mode)."
value = local.create_replication_group && !local.cluster_mode_enabled ? aws_elasticache_replication_group.this[0].primary_endpoint_address : null
Expand Down Expand Up @@ -92,7 +97,7 @@ output "engine" {
output "engine_version" {
description = "The version of the cache engine."
value = local.create_replication_group ? aws_elasticache_replication_group.this[0].engine_version_actual : (
local.create_cluster ? aws_elasticache_cluster.this[0].engine_version_actual : var.engine_version
local.create_cluster ? aws_elasticache_cluster.this[0].engine_version_actual : local.engine_version
)
}

Expand Down
Loading
Loading