@@ -35,42 +35,47 @@ resource "aws_elasticache_subnet_group" "valkey" {
35
35
}
36
36
}
37
37
38
- # ElastiCache Replication Group (cluster mode disabled for Sidekiq compatibility)
39
38
resource "aws_elasticache_replication_group" "valkey" {
40
39
replication_group_id = " mavis-cache-${ var . environment } "
41
- description = " Valkey cluster for Sidekiq (cluster mode disabled) "
40
+ description = " Valkey cluster for Sidekiq"
42
41
43
42
engine = " valkey"
44
43
engine_version = var. valkey_engine_version
45
44
node_type = var. valkey_node_type
46
45
port = var. valkey_port
47
46
parameter_group_name = aws_elasticache_parameter_group. valkey . name
48
47
49
- # Cluster configuration (disabled for Sidekiq compatibility)
50
- automatic_failover_enabled = true
51
- num_cache_clusters = 2
48
+ automatic_failover_enabled = var. valkey_failover_enabled
49
+ num_cache_clusters = length (local. valkey_cache_availability_zones )
52
50
subnet_group_name = aws_elasticache_subnet_group. valkey . name
53
51
security_group_ids = [aws_security_group . valkey . id ]
54
- preferred_cache_cluster_azs = [ aws_subnet . private_subnet_a . availability_zone , aws_subnet . private_subnet_b . availability_zone ]
52
+ preferred_cache_cluster_azs = local . valkey_cache_availability_zones
55
53
snapshot_retention_limit = var. valkey_snapshot_retention_limit
56
54
snapshot_window = var. valkey_snapshot_window
57
55
maintenance_window = var. valkey_maintenance_window
58
56
59
57
at_rest_encryption_enabled = true
60
58
transit_encryption_enabled = true
61
59
62
- # Logging
63
60
log_delivery_configuration {
64
61
destination = aws_cloudwatch_log_group. valkey_slow_log . name
65
62
destination_type = " cloudwatch-logs"
66
- log_format = " text "
63
+ log_format = " json "
67
64
log_type = " slow-log"
68
65
}
69
66
67
+ log_delivery_configuration {
68
+ destination = aws_cloudwatch_log_group. valkey_engine_log . name
69
+ destination_type = " cloudwatch-logs"
70
+ log_format = " json"
71
+ log_type = " engine-log"
72
+ }
73
+
70
74
tags = {
71
75
Name = " mavis-cache-${ var . environment } "
72
76
Purpose = " sidekiq-job-processing"
73
77
}
78
+ apply_immediately = true
74
79
}
75
80
76
81
resource "aws_elasticache_parameter_group" "valkey" {
@@ -80,7 +85,7 @@ resource "aws_elasticache_parameter_group" "valkey" {
80
85
# Optimize for Sidekiq workload
81
86
parameter {
82
87
name = " maxmemory-policy"
83
- value = " noeviction" # TODO: Optimize for sidekiq
88
+ value = " noeviction"
84
89
}
85
90
86
91
tags = {
@@ -96,3 +101,12 @@ resource "aws_cloudwatch_log_group" "valkey_slow_log" {
96
101
Name = " mavis-cache-slow-log-${ var . environment } "
97
102
}
98
103
}
104
+
105
+ resource "aws_cloudwatch_log_group" "valkey_engine_log" {
106
+ name = " /aws/elasticache/valkey/${ var . environment } /engine-log"
107
+ retention_in_days = var. valkey_log_retention_days
108
+
109
+ tags = {
110
+ Name = " mavis-cache-engine-log-${ var . environment } "
111
+ }
112
+ }
0 commit comments