Skip to content

Commit ac107d3

Browse files
committed
added local.create_cluster to not create if engine is valkey and updated REAME
1 parent 8131ae9 commit ac107d3

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,86 @@ module "elasticache" {
268268
}
269269
```
270270

271+
### Serverless Cache
272+
273+
```hcl
274+
module "elasticache" {
275+
source = "terraform-aws-modules/elasticache/aws//modules/serverless-cache"
276+
277+
engine = "redis"
278+
cache_name = "example-serverless-cache"
279+
280+
cache_usage_limits = {
281+
data_storage = {
282+
maximum = 2
283+
}
284+
ecpu_per_second = {
285+
maximum = 1000
286+
}
287+
}
288+
289+
daily_snapshot_time = "22:00"
290+
description = "example-serverless-cache serverless cluster"
291+
kms_key_id = aws_kms_key.this.arn
292+
major_engine_version = "7"
293+
security_group_ids = [module.sg.security_group_id]
294+
295+
snapshot_retention_limit = 7
296+
subnet_ids = module.vpc.private_subnets
297+
298+
user_group_id = module.cache_user_group.group_id
299+
}
300+
```
301+
302+
### Valkey Replication Group
303+
304+
```hcl
305+
module "elasticache" {
306+
source = "terraform-aws-modules/elasticache/aws"
307+
308+
replication_group_id = local.name
309+
310+
engine = "valkey"
311+
engine_version = "7.2"
312+
node_type = "cache.t4g.small"
313+
314+
transit_encryption_enabled = true
315+
auth_token = "PickSomethingMoreSecure123!"
316+
maintenance_window = "sun:05:00-sun:09:00"
317+
apply_immediately = true
318+
319+
# Security Group
320+
vpc_id = module.vpc.vpc_id
321+
security_group_rules = {
322+
ingress_vpc = {
323+
# Default type is `ingress`
324+
# Default port is based on the default engine port
325+
description = "VPC traffic"
326+
cidr_ipv4 = module.vpc.vpc_cidr_block
327+
}
328+
}
329+
330+
# Subnet Group
331+
subnet_group_name = local.name
332+
subnet_group_description = "Valkey replication group subnet group"
333+
subnet_ids = module.vpc.private_subnets
334+
335+
# Parameter Group
336+
create_parameter_group = true
337+
parameter_group_name = local.name
338+
parameter_group_family = "valkey7"
339+
parameter_group_description = "Valkey replication group parameter group"
340+
parameters = [
341+
{
342+
name = "latency-tracking"
343+
value = "yes"
344+
}
345+
]
346+
347+
tags = local.tags
348+
}
349+
```
350+
271351
## Examples
272352

273353
Examples codified under the [`examples`](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples) are intended to give users references for how to use the module(s) as well as testing/validating changes to the source code of the module. If contributing to the project, please be sure to make any appropriate updates to the relevant examples to allow maintainers to test your changes and to keep the examples up to date for users. Thank you!
@@ -277,6 +357,8 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module
277357
- [Redis Cluster Mode](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples/redis-cluster-mode)
278358
- [Redis Global Replication Group](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples/redis-global-replication-group)
279359
- [Redis Replication Group](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples/redis-replication-group)
360+
- [Serverless Cache](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples/serverless-cache)
361+
- [Valkey Replication Group](https://github.com/terraform-aws-modules/terraform-aws-elasticache/tree/master/examples/valkey-replication-group)
280362

281363
<!-- BEGIN_TF_DOCS -->
282364
## Requirements

examples/serverless-cache/main.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,33 @@ module "serverless" {
4545
user_group_id = module.cache_user_group.group_id
4646
}
4747

48+
module "valkey_serverless" {
49+
source = "../../modules/serverless-cache"
50+
51+
engine = "valkey"
52+
cache_name = "${local.name}-valkey"
53+
54+
cache_usage_limits = {
55+
data_storage = {
56+
maximum = 2
57+
}
58+
ecpu_per_second = {
59+
maximum = 1000
60+
}
61+
}
62+
63+
daily_snapshot_time = "22:00"
64+
description = "${local.name} valkey serverless cluster"
65+
kms_key_id = aws_kms_key.this.arn
66+
major_engine_version = "7"
67+
security_group_ids = [module.sg.security_group_id]
68+
69+
snapshot_retention_limit = 7
70+
subnet_ids = module.vpc.private_subnets
71+
72+
user_group_id = module.cache_user_group.group_id
73+
}
74+
4875
module "cache_user_group" {
4976
source = "../../modules/user-group"
5077

main.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ locals {
22
# https://github.com/hashicorp/terraform-provider-aws/blob/3c4cb52c5dc2c09e10e5a717f73d1d8bc4186e87/internal/service/elasticache/cluster.go#L271
33
in_replication_group = var.replication_group_id != null
44

5+
# elasticache clusters currently do not support engine type valkey
6+
# TODO: remove this local `create_cluster` conditional once this bug is addressed:
7+
# https://github.com/hashicorp/terraform-provider-aws/issues/39905
8+
create_cluster = var.create_cluster && var.engine != "valkey" ? true : false
9+
510
security_group_ids = local.create_security_group ? concat(var.security_group_ids, [aws_security_group.this[0].id]) : var.security_group_ids
611
port = var.engine == "memcached" ? 11211 : 6379
712

@@ -13,7 +18,7 @@ locals {
1318
################################################################################
1419

1520
resource "aws_elasticache_cluster" "this" {
16-
count = var.create && var.create_cluster ? 1 : 0
21+
count = var.create && local.create_cluster ? 1 : 0
1722

1823
apply_immediately = var.apply_immediately
1924
auto_minor_version_upgrade = var.auto_minor_version_upgrade

0 commit comments

Comments
 (0)