Add Valkey support for ElastiCache (#158)

## Summary

This PR adds support for AWS ElastiCache Valkey as an alternative to
Redis, addressing #44.

## Changes

- **Upgrade cloudposse module**: Updated
`cloudposse/elasticache-redis/aws` from v0.53.0 to >= 1.9.1
- **Add engine parameter**: New `engine` field in `redis_config`
supports both `redis` (default) and `valkey`
- **AWS provider constraint**: Added requirement for AWS provider >=
5.73.0 in `byo-vpc/versions.tf`
- **Documentation**: Added Valkey configuration examples to README

## Valkey Benefits

Valkey is an open-source, Redis-compatible in-memory data store. AWS
recommends using Valkey for cost savings.

## Usage

To use Valkey instead of Redis:

```hcl
redis_config = {
  engine         = "valkey"
  engine_version = "7.2"
  family         = "valkey7"
}
```

## Backwards Compatibility

- Default engine remains `redis` - existing deployments continue to work
unchanged
- Users can opt-in to Valkey by setting `engine = "valkey"

Note that this was mostly AI-generated.

Closes #44

---------

Co-authored-by: Robert Fairburn <8029478+rfairburn@users.noreply.github.com>
This commit is contained in:
Michal HrubyandRobert Fairburn authored and GitHub committed 2026-01-09 02:49:14 -06:00
1 parent e7408fb07a
commit 07fdf37d4b
6 files changed
+117 -7

No files matched your search

+47
View File
@@ -35,6 +35,53 @@ moved {
This focuses on the resources that are "heavy" or store data. Note that the ALB cannot be moved like this because Dogfood uses the `aws_alb` resource and the module uses the `aws_lb` resource. The resources are aliases of eachother, but Terraform can't recognize that.
# Cache Engine: Redis vs Valkey
This module supports both Redis and [Valkey](https://valkey.io/) as the ElastiCache engine. Valkey is an open-source, Redis-compatible in-memory data store.
## Provider Requirements
When using this module, ensure your AWS provider version is >= 5.73.0:
```hcl
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.73.0"
}
}
}
```
## Using Valkey (Recommended for Cost Savings)
To use Valkey instead of Redis, configure the `redis_config` variable:
```hcl
redis_config = {
engine = "valkey"
engine_version = "7.2"
family = "valkey7"
instance_type = "cache.m5.large"
cluster_size = 3
}
```
## Using Redis (Default)
Redis remains the default engine for backwards compatibility:
```hcl
redis_config = {
engine = "redis" # Default
engine_version = "7.1"
family = "redis7"
instance_type = "cache.m5.large"
cluster_size = 3
}
```
# How to improve this module
If this module somehow doesn't fit your needs, feel free to contact us by
opening a ticket, or contacting your contact at Fleet. Our goal is to make this module
+48 -1
View File
@@ -35,6 +35,53 @@ moved {
This focuses on the resources that are "heavy" or store data. Note that the ALB cannot be moved like this because Dogfood uses the `aws_alb` resource and the module uses the `aws_lb` resource. The resources are aliases of eachother, but Terraform can't recognize that.
# Cache Engine: Redis vs Valkey
This module supports both Redis and [Valkey](https://valkey.io/) as the ElastiCache engine. Valkey is an open-source, Redis-compatible in-memory data store.
## Provider Requirements
When using this module, ensure your AWS provider version is >= 5.73.0:
```hcl
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.73.0"
}
}
}
```
## Using Valkey (Recommended for Cost Savings)
To use Valkey instead of Redis, configure the `redis_config` variable:
```hcl
redis_config = {
engine = "valkey"
engine_version = "7.2"
family = "valkey7"
instance_type = "cache.m5.large"
cluster_size = 3
}
```
## Using Redis (Default)
Redis remains the default engine for backwards compatibility:
```hcl
redis_config = {
engine = "redis" # Default
engine_version = "7.1"
family = "redis7"
instance_type = "cache.m5.large"
cluster_size = 3
}
```
# How to improve this module
If this module somehow doesn't fit your needs, feel free to contact us by
opening a ticket, or contacting your contact at Fleet. Our goal is to make this module
@@ -78,7 +125,7 @@ No resources.
| <a name="input_fleet_config"></a> [fleet\_config](#input\_fleet\_config) | The configuration object for Fleet itself. Fields that default to null will have their respective resources created if not specified. | <pre>object({<br/> task_mem = optional(number, null)<br/> task_cpu = optional(number, null)<br/> mem = optional(number, 4096)<br/> cpu = optional(number, 512)<br/> pid_mode = optional(string, null)<br/> image = optional(string, "fleetdm/fleet:v4.78.0")<br/> family = optional(string, "fleet")<br/> sidecars = optional(list(any), [])<br/> depends_on = optional(list(any), [])<br/> mount_points = optional(list(any), [])<br/> volumes = optional(list(any), [])<br/> extra_environment_variables = optional(map(string), {})<br/> extra_iam_policies = optional(list(string), [])<br/> extra_execution_iam_policies = optional(list(string), [])<br/> extra_secrets = optional(map(string), {})<br/> security_group_name = optional(string, "fleet")<br/> iam_role_arn = optional(string, null)<br/> repository_credentials = optional(string, "")<br/> private_key_secret_name = optional(string, "fleet-server-private-key")<br/> service = optional(object({<br/> name = optional(string, "fleet")<br/> }), {<br/> name = "fleet"<br/> })<br/> database = optional(object({<br/> password_secret_arn = string<br/> user = string<br/> database = string<br/> address = string<br/> rr_address = optional(string, null)<br/> }), {<br/> password_secret_arn = null<br/> user = null<br/> database = null<br/> address = null<br/> rr_address = null<br/> })<br/> redis = optional(object({<br/> address = string<br/> use_tls = optional(bool, true)<br/> }), {<br/> address = null<br/> use_tls = true<br/> })<br/> awslogs = optional(object({<br/> name = optional(string, null)<br/> region = optional(string, null)<br/> create = optional(bool, true)<br/> prefix = optional(string, "fleet")<br/> retention = optional(number, 5)<br/> }), {<br/> name = null<br/> region = null<br/> prefix = "fleet"<br/> retention = 5<br/> })<br/> loadbalancer = optional(object({<br/> arn = string<br/> }), {<br/> arn = null<br/> })<br/> extra_load_balancers = optional(list(any), [])<br/> networking = optional(object({<br/> subnets = optional(list(string), null)<br/> security_groups = optional(list(string), null)<br/> ingress_sources = optional(object({<br/> cidr_blocks = optional(list(string), [])<br/> ipv6_cidr_blocks = optional(list(string), [])<br/> security_groups = optional(list(string), [])<br/> prefix_list_ids = optional(list(string), [])<br/> }), {<br/> cidr_blocks = []<br/> ipv6_cidr_blocks = []<br/> security_groups = []<br/> prefix_list_ids = []<br/> })<br/> }), {<br/> subnets = null<br/> security_groups = null<br/> ingress_sources = {<br/> cidr_blocks = []<br/> ipv6_cidr_blocks = []<br/> security_groups = []<br/> prefix_list_ids = []<br/> }<br/> })<br/> autoscaling = optional(object({<br/> max_capacity = optional(number, 5)<br/> min_capacity = optional(number, 1)<br/> memory_tracking_target_value = optional(number, 80)<br/> cpu_tracking_target_value = optional(number, 80)<br/> }), {<br/> max_capacity = 5<br/> min_capacity = 1<br/> memory_tracking_target_value = 80<br/> cpu_tracking_target_value = 80<br/> })<br/> iam = optional(object({<br/> role = optional(object({<br/> name = optional(string, "fleet-role")<br/> policy_name = optional(string, "fleet-iam-policy")<br/> }), {<br/> name = "fleet-role"<br/> policy_name = "fleet-iam-policy"<br/> })<br/> execution = optional(object({<br/> name = optional(string, "fleet-execution-role")<br/> policy_name = optional(string, "fleet-execution-role")<br/> }), {<br/> name = "fleet-execution-role"<br/> policy_name = "fleet-iam-policy-execution"<br/> })<br/> }), {<br/> name = "fleetdm-execution-role"<br/> })<br/> software_installers = optional(object({<br/> create_bucket = optional(bool, true)<br/> bucket_name = opLine truncated
| <a name="input_migration_config"></a> [migration\_config](#input\_migration\_config) | The configuration object for Fleet's migration task. | <pre>object({<br/> mem = number<br/> cpu = number<br/> })</pre> | <pre>{<br/> "cpu": 1024,<br/> "mem": 2048<br/>}</pre> | no |
| <a name="input_rds_config"></a> [rds\_config](#input\_rds\_config) | The config for the terraform-aws-modules/rds-aurora/aws module | <pre>object({<br/> name = optional(string, "fleet")<br/> engine_version = optional(string, "8.0.mysql_aurora.3.08.2")<br/> instance_class = optional(string, "db.t4g.large")<br/> subnets = optional(list(string), [])<br/> allowed_security_groups = optional(list(string), [])<br/> allowed_cidr_blocks = optional(list(string), [])<br/> apply_immediately = optional(bool, true)<br/> monitoring_interval = optional(number, 10)<br/> db_parameter_group_name = optional(string)<br/> db_parameters = optional(map(string), {})<br/> db_cluster_parameter_group_name = optional(string)<br/> db_cluster_parameters = optional(map(string), {})<br/> enabled_cloudwatch_logs_exports = optional(list(string), [])<br/> master_username = optional(string, "fleet")<br/> snapshot_identifier = optional(string)<br/> cluster_tags = optional(map(string), {})<br/> skip_final_snapshot = optional(bool, true)<br/> backup_retention_period = optional(number, 7)<br/> replicas = optional(number, 2)<br/> serverless = optional(bool, false)<br/> serverless_min_capacity = optional(number, 2)<br/> serverless_max_capacity = optional(number, 10)<br/> restore_to_point_in_time = optional(map(string), {})<br/> })</pre> | <pre>{<br/> "allowed_cidr_blocks": [],<br/> "allowed_security_groups": [],<br/> "apply_immediately": true,<br/> "backup_retention_period": 7,<br/> "cluster_tags": {},<br/> "db_cluster_parameter_group_name": null,<br/> "db_cluster_parameters": {},<br/> "db_parameter_group_name": null,<br/> "db_parameters": {},<br/> "enabled_cloudwatch_logs_exports": [],<br/> "engine_version": "8.0.mysql_aurora.3.08.2",<br/> "instance_class": "db.t4g.large",<br/> "master_username": "fleet",<br/> "monitoring_interval": 10,<br/> "name": "fleet",<br/> "replicas": 2,<br/> "restore_to_point_in_time": {},<br/> "serverless": false,<br/> "serverless_max_capacity": 10,<br/> "serverless_min_capacity": 2,<br/> "skip_final_snapshot": true,<br/> "snapshot_identifier": null,<br/> "subnets": []<br/>}</pre> | no |
| <a name="input_redis_config"></a> [redis\_config](#input\_redis\_config) | n/a | <pre>object({<br/> name = optional(string, "fleet")<br/> replication_group_id = optional(string)<br/> elasticache_subnet_group_name = optional(string)<br/> allowed_security_group_ids = optional(list(string), [])<br/> subnets = optional(list(string))<br/> availability_zones = optional(list(string))<br/> cluster_size = optional(number, 3)<br/> instance_type = optional(string, "cache.m5.large")<br/> apply_immediately = optional(bool, true)<br/> automatic_failover_enabled = optional(bool, false)<br/> engine_version = optional(string, "6.x")<br/> family = optional(string, "redis6.x")<br/> at_rest_encryption_enabled = optional(bool, true)<br/> transit_encryption_enabled = optional(bool, true)<br/> parameter = optional(list(object({<br/> name = string<br/> value = string<br/> })), [])<br/> log_delivery_configuration = optional(list(map(any)), [])<br/> tags = optional(map(string), {})<br/> })</pre> | <pre>{<br/> "allowed_security_group_ids": [],<br/> "apply_immediately": true,<br/> "at_rest_encryption_enabled": true,<br/> "automatic_failover_enabled": false,<br/> "availability_zones": null,<br/> "cluster_size": 3,<br/> "elasticache_subnet_group_name": null,<br/> "engine_version": "6.x",<br/> "family": "redis6.x",<br/> "instance_type": "cache.m5.large",<br/> "log_delivery_configuration": [],<br/> "name": "fleet",<br/> "parameter": [],<br/> "replication_group_id": null,<br/> "subnets": null,<br/> "tags": {},<br/> "transit_encryption_enabled": true<br/>}</pre> | no |
| <a name="input_redis_config"></a> [redis\_config](#input\_redis\_config) | n/a | <pre>object({<br/> name = optional(string, "fleet")<br/> replication_group_id = optional(string)<br/> elasticache_subnet_group_name = optional(string)<br/> allowed_security_group_ids = optional(list(string), [])<br/> subnets = optional(list(string))<br/> availability_zones = optional(list(string))<br/> cluster_size = optional(number, 3)<br/> instance_type = optional(string, "cache.m5.large")<br/> apply_immediately = optional(bool, true)<br/> automatic_failover_enabled = optional(bool, false)<br/> engine = optional(string, "redis")<br/> engine_version = optional(string, "7.1")<br/> family = optional(string, "redis7")<br/> at_rest_encryption_enabled = optional(bool, true)<br/> transit_encryption_enabled = optional(bool, true)<br/> parameter = optional(list(object({<br/> name = string<br/> value = string<br/> })), [])<br/> log_delivery_configuration = optional(list(map(any)), [])<br/> tags = optional(map(string), {})<br/> })</pre> | <pre>{<br/> "allowed_security_group_ids": [],<br/> "apply_immediately": true,<br/> "at_rest_encryption_enabled": true,<br/> "automatic_failover_enabled": false,<br/> "availability_zones": null,<br/> "cluster_size": 3,<br/> "elasticache_subnet_group_name": null,<br/> "engine": "redis",<br/> "engine_version": "7.1",<br/> "family": "redis7",<br/> "instance_type": "cache.m5.large",<br/> "log_delivery_configuration": [],<br/> "name": "fleet",<br/> "parameter": [],<br/> "replication_group_id": null,<br/> "subnets": null,<br/> "tags": {},<br/> "transit_encryption_enabled": true<br/>}</pre> | no |
| <a name="input_vpc"></a> [vpc](#input\_vpc) | n/a | <pre>object({<br/> name = optional(string, "fleet")<br/> cidr = optional(string, "10.10.0.0/16")<br/> azs = optional(list(string), ["us-east-2a", "us-east-2b", "us-east-2c"])<br/> private_subnets = optional(list(string), ["10.10.1.0/24", "10.10.2.0/24", "10.10.3.0/24"])<br/> public_subnets = optional(list(string), ["10.10.11.0/24", "10.10.12.0/24", "10.10.13.0/24"])<br/> database_subnets = optional(list(string), ["10.10.21.0/24", "10.10.22.0/24", "10.10.23.0/24"])<br/> elasticache_subnets = optional(list(string), ["10.10.31.0/24", "10.10.32.0/24", "10.10.33.0/24"])<br/><br/> create_database_subnet_group = optional(bool, false)<br/> create_database_subnet_route_table = optional(bool, true)<br/> create_elasticache_subnet_group = optional(bool, true)<br/> create_elasticache_subnet_route_table = optional(bool, true)<br/> enable_vpn_gateway = optional(bool, false)<br/> one_nat_gateway_per_az = optional(bool, false)<br/> single_nat_gateway = optional(bool, true)<br/> enable_nat_gateway = optional(bool, true)<br/> enable_dns_hostnames = optional(bool, false)<br/> enable_dns_support = optional(bool, true)<br/> enable_flow_log = optional(bool, false)<br/> create_flow_log_cloudwatch_log_group = optional(bool, false)<br/> create_flow_log_cloudwatch_iam_role = optional(bool, false)<br/> flow_log_max_aggregation_interval = optional(number, 600)<br/> flow_log_cloudwatch_log_group_name_prefix = optional(string, "/aws/vpc-flow-log/")<br/> flow_log_cloudwatch_log_group_name_suffix = optional(string, "")<br/> vpc_flow_log_tags = optional(map(string), {})<br/> })</pre> | <pre>{<br/> "azs": [<br/> "us-east-2a",<br/> "us-east-2b",<br/> "us-east-2c"<br/> ],<br/> "cidr": "10.10.0.0/16",<br/> "create_database_subnet_group": false,<br/> "create_database_subnet_route_table": true,<br/> "create_elasticache_subnet_group": true,<br/> "create_elasticache_subnet_route_table": true,<br/> "create_flow_log_cloudwatch_iam_role": false,<br/> "create_flow_log_cloudwatch_log_group": false,<br/> "database_subnets": [<br/> "10.10.21.0/24",<br/> "10.10.22.0/24",<br/> "10.10.23.0/24"<br/> ],<br/> "elasticache_subnets": [<br/> "10.10.31.0/24",<br/> "10.10.32.0/24",<br/> "10.10.33.0/24"<br/> ],<br/> "enable_dns_hostnames": false,<br/> "enable_dns_support": true,<br/> "enable_flow_log": false,<br/> "enable_nat_gateway": true,<br/> "enable_vpn_gateway": false,<br/> "flow_log_cloudwatch_log_group_name_prefix": "/aws/vpc-flow-log/",<br/> "flow_log_cloudwatch_log_group_name_suffix": "",<br/> "flow_log_max_aggregation_interval": 600,<br/> "name": "fleet",<br/> "one_nat_gateway_per_az": false,<br/> "private_subnets": [<br/> "10.10.1.0/24",<br/> "10.10.2.0/24",<br/> "10.10.3.0/24"<br/> ],<br/> "public_subnets": [<br/> "10.10.11.0/24",<br/> "10.10.12.0/24",<br/> "10.10.13.0/24"<br/> ],<br/> "single_nat_gateway": true,<br/> "vpc_flow_log_tags": {}<br/>}</pre> | no |
## Outputs
+3 -2
View File
@@ -89,20 +89,21 @@ module "rds" {
module "redis" {
source = "cloudposse/elasticache-redis/aws"
version = "0.53.0"
version = ">= 1.9.1"
name = var.redis_config.name
replication_group_id = var.redis_config.replication_group_id == null ? var.redis_config.name : var.redis_config.replication_group_id
elasticache_subnet_group_name = var.redis_config.elasticache_subnet_group_name == null ? var.redis_config.name : var.redis_config.elasticache_subnet_group_name
availability_zones = var.redis_config.availability_zones
vpc_id = var.vpc_config.vpc_id
description = "Fleet Redis"
description = "Fleet cache"
#allowed_security_group_ids = concat(var.redis_config.allowed_security_group_ids, module.byo-db.ecs.security_group)
subnets = var.redis_config.subnets
cluster_size = var.redis_config.cluster_size
instance_type = var.redis_config.instance_type
apply_immediately = var.redis_config.apply_immediately
automatic_failover_enabled = var.redis_config.automatic_failover_enabled
engine = var.redis_config.engine
engine_version = var.redis_config.engine_version
family = var.redis_config.family
at_rest_encryption_enabled = var.redis_config.at_rest_encryption_enabled
+4 -2
View File
@@ -77,8 +77,9 @@ variable "redis_config" {
instance_type = optional(string, "cache.m5.large")
apply_immediately = optional(bool, true)
automatic_failover_enabled = optional(bool, false)
engine_version = optional(string, "6.x")
family = optional(string, "redis6.x")
engine = optional(string, "redis")
engine_version = optional(string, "7.1")
family = optional(string, "redis7")
at_rest_encryption_enabled = optional(bool, true)
transit_encryption_enabled = optional(bool, true)
parameter = optional(list(object({
@@ -100,6 +101,7 @@ variable "redis_config" {
instance_type = "cache.m5.large"
apply_immediately = true
automatic_failover_enabled = false
engine = "redis"
engine_version = "6.x"
family = "redis6.x"
at_rest_encryption_enabled = true
+11
View File
@@ -0,0 +1,11 @@
terraform {
required_version = ">= 1.3.8"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.73.0"
}
}
}
+4 -2
View File
@@ -126,8 +126,9 @@ variable "redis_config" {
instance_type = optional(string, "cache.m5.large")
apply_immediately = optional(bool, true)
automatic_failover_enabled = optional(bool, false)
engine_version = optional(string, "6.x")
family = optional(string, "redis6.x")
engine = optional(string, "redis")
engine_version = optional(string, "7.1")
family = optional(string, "redis7")
at_rest_encryption_enabled = optional(bool, true)
transit_encryption_enabled = optional(bool, true)
parameter = optional(list(object({
@@ -148,6 +149,7 @@ variable "redis_config" {
instance_type = "cache.m5.large"
apply_immediately = true
automatic_failover_enabled = false
engine = "redis"
engine_version = "6.x"
family = "redis6.x"
at_rest_encryption_enabled = true