Skip to content

Commit 269e196

Browse files
committed
feat: introducing valkey elasticache
1 parent e192515 commit 269e196

File tree

6 files changed

+119
-4
lines changed

6 files changed

+119
-4
lines changed

examples/valkey/example.tf

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
####----------------------------------------------------------------------------------
2+
## Provider block added, Use the Amazon Web Services (AWS) provider to interact with the many resources supported by AWS.
3+
####----------------------------------------------------------------------------------
4+
provider "aws" {
5+
region = local.region
6+
}
7+
locals {
8+
name = "valkey"
9+
environment = "test"
10+
region = "us-east-1"
11+
}
12+
####----------------------------------------------------------------------------------
13+
## A VPC is a virtual network that closely resembles a traditional network that you'd operate in your own data center.
14+
####----------------------------------------------------------------------------------
15+
module "vpc" {
16+
source = "clouddrove/vpc/aws"
17+
version = "2.0.0"
18+
19+
name = "${local.name}-vpc"
20+
environment = local.environment
21+
cidr_block = "10.0.0.0/16"
22+
}
23+
24+
####----------------------------------------------------------------------------------
25+
## A subnet is a range of IP addresses in your VPC.
26+
####----------------------------------------------------------------------------------
27+
module "subnets" {
28+
source = "clouddrove/subnet/aws"
29+
version = "2.0.0"
30+
31+
name = "${local.name}-subnets"
32+
environment = local.environment
33+
availability_zones = ["${local.region}a", "${local.region}b", "${local.region}c"]
34+
vpc_id = module.vpc.vpc_id
35+
type = "public"
36+
igw_id = module.vpc.igw_id
37+
cidr_block = module.vpc.vpc_cidr_block
38+
ipv6_cidr_block = module.vpc.ipv6_cidr_block
39+
}
40+
41+
##----------------------------------------------------------------------------------
42+
## VALKEY MODULE CALL
43+
##----------------------------------------------------------------------------------
44+
module "valkey" {
45+
source = "./../../"
46+
47+
name = local.name
48+
environment = local.environment
49+
50+
vpc_id = module.vpc.vpc_id
51+
allowed_ip = [module.vpc.vpc_cidr_block]
52+
allowed_ports = [6379]
53+
54+
# -- valkey configuration
55+
cluster_replication_enabled = true
56+
replication_group = {
57+
engine = "valkey"
58+
engine_version = "8.1"
59+
parameter_group_name = "default.valkey8"
60+
port = 6379
61+
num_cache_clusters = 2
62+
node_type = "cache.t3.medium"
63+
replication_group_description = "${local.environment}-${local.name} replication group."
64+
maintenance_window = "tue:07:00-tue:08:00"
65+
}
66+
67+
az_mode = "single-az"
68+
num_cache_nodes = 2
69+
kms_key_id = null
70+
auth_token = "UseSomethingSecure*1234"
71+
# ---- valkey end -----------------
72+
subnet_ids = concat(module.subnets.private_subnet_id, module.subnets.public_subnet_id)
73+
subnet_group_description = "${local.environment}-${local.name} subnet group."
74+
availability_zones = ["${local.region}a", "${local.region}c"]
75+
}

examples/valkey/outputs.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# output "id" {
2+
# value = module.valkey[*].id
3+
# description = "memcached id."
4+
# }
5+
6+
# output "tags" {
7+
# value = module.memcached.tags
8+
# description = "A mapping of tags to assign to the resource."
9+
# }
10+
11+
# output "memcached_endpoint" {
12+
# value = module.memcached.memcached_endpoint
13+
# description = "Memcached endpoint address."
14+
# }
15+
16+
# output "hostname" {
17+
# value = module.memcached.hostname
18+
# description = "DNS hostname"
19+
# }
20+
21+
# output "redis_ssm_arn" {
22+
# value = module.memcached.Memcached_ssm_name
23+
# description = "A map of the names and ARNs created"
24+
# }

examples/valkey/versions.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Terraform version
2+
terraform {
3+
required_version = ">= 1.6.5"
4+
5+
required_providers {
6+
aws = {
7+
source = "hashicorp/aws"
8+
version = ">= 5.31.0"
9+
}
10+
}
11+
}

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ resource "aws_route53_record" "elasticache" {
241241
## Below resource will create ssm-parameter resource for redis and memcached with auth-token.
242242
##----------------------------------------------------------------------------------
243243
resource "aws_ssm_parameter" "secret" {
244-
count = var.enable && var.auth_token_enable ? 1 : 0
244+
count = var.enable && var.enable_aws_ssm_parameter && var.auth_token_enable ? 1 : 0
245245

246246
name = format("/%s/%s/auth-token", var.environment, var.name)
247247
description = var.ssm_parameter_description
@@ -254,7 +254,7 @@ resource "aws_ssm_parameter" "secret" {
254254
## Below resource will create ssm-parameter resource for redis with endpoint.
255255
##----------------------------------------------------------------------------------
256256
resource "aws_ssm_parameter" "secret-endpoint" {
257-
count = var.enable && var.ssm_parameter_endpoint_enabled ? 1 : 0
257+
count = var.enable && var.enable_aws_ssm_parameter && var.ssm_parameter_endpoint_enabled ? 1 : 0
258258

259259
name = format("/%s/%s/endpoint", var.environment, var.name)
260260
description = var.ssm_parameter_description
@@ -280,7 +280,7 @@ resource "aws_route53_record" "memcached_route_53" {
280280
## Below resource will create ssm-parameter resource for memcached with endpoint.
281281
##----------------------------------------------------------------------------------
282282
resource "aws_ssm_parameter" "memcached_secret-endpoint" {
283-
count = var.enable && var.memcached_ssm_parameter_endpoint_enabled ? 1 : 0
283+
count = var.enable && var.enable_aws_ssm_parameter && var.memcached_ssm_parameter_endpoint_enabled ? 1 : 0
284284

285285
name = format("/%s/%s/memcached-endpoint", var.environment, var.name)
286286
description = var.ssm_parameter_description

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ output "Memcached_ssm_name" {
6161
}
6262

6363
output "auth_token" {
64-
value = var.enable && var.auth_token_enable ? random_password.auth_token[0].result : null
64+
value = var.enable && var.auth_token_enable && var.auth_token == null ? random_password.auth_token[0].result : null
6565
sensitive = true
6666
description = "Auth token generated value"
6767
}

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ variable "route53" {
297297
}
298298

299299
###------------------------------- ssm_parameter----------------------------
300+
variable "enable_aws_ssm_parameter" {
301+
description = "Whether to create the AWS SSM parameter for the auth token"
302+
type = bool
303+
default = false
304+
}
300305

301306
variable "ssm_parameter_endpoint_enabled" {
302307
type = bool

0 commit comments

Comments
 (0)