Skip to content

Commit 92afa66

Browse files
Add support for valkey (#3763)
1 parent bb36080 commit 92afa66

File tree

5 files changed

+257
-5
lines changed

5 files changed

+257
-5
lines changed

provider/aws/formation/resource/redis.json.tmpl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
"MinLength": "1",
3737
"Type": "String"
3838
},
39+
"Engine": {
40+
"Type": "String",
41+
"Default": "redis",
42+
"AllowedValues": [ "redis", "valkey" ],
43+
"Description": "The cache engine to use (redis or valkey)"
44+
},
3945
"Version": {
4046
"Type": "String",
4147
"Default": "7.0"
@@ -111,7 +117,7 @@
111117
"AutoMinorVersionUpgrade": { "Ref": "AutoMinorVersionUpgrade" },
112118
"CacheNodeType": { "Ref": "Class" },
113119
"CacheSubnetGroupName": { "Ref": "SubnetGroup" },
114-
"Engine": "redis",
120+
"Engine": { "Ref": "Engine" },
115121
"EngineVersion": { "Ref": "Version" },
116122
"NumCacheClusters": { "Ref": "Nodes" },
117123
"Port": "6379",
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"AWSTemplateFormatVersion": "2010-09-09",
3+
"Conditions": {
4+
"Encrypted": { "Fn::Equals": [{ "Ref": "Encrypted" }, "true"] }
5+
},
6+
"Parameters": {
7+
"AutoMinorVersionUpgrade": {
8+
"Type" : "String",
9+
"Default": "true",
10+
"AllowedValues" : [ "true", "false" ]
11+
},
12+
"Class": {
13+
"Type": "String",
14+
"Default": "cache.t2.micro"
15+
},
16+
"Durable": {
17+
"Type": "String",
18+
"Default": "false",
19+
"AllowedValues": [ "true", "false" ]
20+
},
21+
"Encrypted": {
22+
"Type": "String",
23+
"Default": "false",
24+
"AllowedValues": [ "true", "false" ]
25+
},
26+
"Nodes": {
27+
"Type": "Number",
28+
"Default": "1"
29+
},
30+
"Password": {
31+
"MinLength": "8",
32+
"NoEcho": true,
33+
"Type": "String"
34+
},
35+
"Rack": {
36+
"MinLength": "1",
37+
"Type": "String"
38+
},
39+
"Version": {
40+
"Type": "String",
41+
"Default": "8.1"
42+
}
43+
},
44+
"Outputs": {
45+
"Url": {
46+
"Value": {
47+
"Fn::Sub": [
48+
"${Protocol}${Auth}${ReplicationGroup.PrimaryEndPoint.Address}:${ReplicationGroup.PrimaryEndPoint.Port}/0",
49+
{
50+
"Protocol": {
51+
"Fn::If": ["Encrypted", "rediss://", "redis://"]
52+
},
53+
"Auth": {
54+
"Fn::If": ["Encrypted", { "Fn::Sub": ":${Password}@" }, ""]
55+
}
56+
}
57+
]
58+
}
59+
},
60+
"User": { "Value": "" },
61+
"Pass": { "Value": { "Fn::If": ["Encrypted", { "Fn::Sub": ":${Password}@" }, ""] } },
62+
"Host": { "Value": { "Fn::GetAtt": [ "ReplicationGroup", "PrimaryEndPoint.Address" ] } },
63+
"Port": { "Value": { "Fn::Sub": "${ReplicationGroup.PrimaryEndPoint.Port}/0" } },
64+
"Name": { "Value": "" }
65+
},
66+
"Resources": {
67+
"SecurityGroup": {
68+
"Type": "AWS::EC2::SecurityGroup",
69+
"Properties": {
70+
"GroupDescription": { "Fn::Sub": "${AWS::StackName} security group" },
71+
"SecurityGroupIngress": [
72+
{ "IpProtocol": "tcp", "FromPort": "6379", "ToPort": "6379", "CidrIp": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:VpcCidr" } } }
73+
],
74+
"VpcId": { "Fn::ImportValue": { "Fn::Sub": "${Rack}:Vpc" } },
75+
"Tags": [
76+
{{ range $key, $value := .Tags }}
77+
{ "Key": "{{ $key }}", "Value": "{{ $value }}" },
78+
{{ end }}
79+
{ "Key": "Name", "Value": "{{.Name}}" }
80+
]
81+
}
82+
},
83+
"SubnetGroup": {
84+
"Type": "AWS::ElastiCache::SubnetGroup",
85+
"Properties": {
86+
"Description": { "Fn::Sub": "${AWS::StackName} subnets" },
87+
"SubnetIds": [
88+
{ "Fn::ImportValue": { "Fn::Sub": "${Rack}:Subnet0" } },
89+
{ "Fn::ImportValue": { "Fn::Sub": "${Rack}:Subnet1" } }
90+
],
91+
"Tags": [
92+
{{ range $key, $value := .Tags }}
93+
{ "Key": "{{ $key }}", "Value": "{{ $value }}" },
94+
{{ end }}
95+
{ "Key": "Name", "Value": "{{.Name}}" }
96+
]
97+
}
98+
},
99+
"ReplicationGroup": {
100+
"Type": "AWS::ElastiCache::ReplicationGroup",
101+
"Properties": {
102+
"AtRestEncryptionEnabled": { "Ref": "Encrypted" },
103+
"AuthToken": {
104+
"Fn::If": [
105+
"Encrypted",
106+
{ "Ref": "Password" },
107+
{ "Ref": "AWS::NoValue" }
108+
]
109+
},
110+
"AutomaticFailoverEnabled": { "Ref": "Durable" },
111+
"AutoMinorVersionUpgrade": { "Ref": "AutoMinorVersionUpgrade" },
112+
"CacheNodeType": { "Ref": "Class" },
113+
"CacheSubnetGroupName": { "Ref": "SubnetGroup" },
114+
"Engine": "valkey",
115+
"EngineVersion": { "Ref": "Version" },
116+
"NumCacheClusters": { "Ref": "Nodes" },
117+
"Port": "6379",
118+
"ReplicationGroupDescription": { "Ref": "AWS::StackName" },
119+
"SecurityGroupIds": [ { "Ref": "SecurityGroup" } ],
120+
"TransitEncryptionEnabled": { "Ref": "Encrypted" },
121+
"Tags": [
122+
{{ range $key, $value := .Tags }}
123+
{ "Key": "{{ $key }}", "Value": "{{ $value }}" },
124+
{{ end }}
125+
{ "Key": "Name", "Value": "{{.Name}}" }
126+
]
127+
}
128+
}
129+
}
130+
}

provider/aws/resource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (p *Provider) SystemResourceCreate(kind string, opts structs.ResourceCreate
160160
var req *cloudformation.CreateStackInput
161161

162162
switch s.Type {
163-
case "memcached", "mysql", "postgres", "redis", "sqs":
163+
case "memcached", "mysql", "postgres", "redis", "valkey", "sqs":
164164
req, err = p.createResource(s)
165165
case "s3":
166166
if s.Parameters["Topic"] != "" {
@@ -300,7 +300,7 @@ func (p *Provider) SystemResourceGet(name string) (*structs.Resource, error) {
300300
s.Url = fmt.Sprintf("mysql://%s:%s@%s:%s/%s", outputs["EnvMysqlUsername"], outputs["EnvMysqlPassword"], outputs["Port3306TcpAddr"], outputs["Port3306TcpPort"], outputs["EnvMysqlDatabase"])
301301
case "postgres":
302302
s.Url = fmt.Sprintf("postgres://%s:%s@%s:%s/%s", outputs["EnvPostgresUsername"], outputs["EnvPostgresPassword"], outputs["Port5432TcpAddr"], outputs["Port5432TcpPort"], outputs["EnvPostgresDatabase"])
303-
case "redis":
303+
case "redis", "valkey":
304304
s.Url = fmt.Sprintf("redis://%s:%s/%s", outputs["Port6379TcpAddr"], outputs["Port6379TcpPort"], outputs["EnvRedisDatabase"])
305305
case "s3":
306306
s.Url = fmt.Sprintf("s3://%s:%s@%s", outputs["AccessKey"], outputs["SecretAccessKey"], outputs["Bucket"])

provider/aws/templates/resource/redis.tmpl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@
2222
"Default": "false",
2323
"AllowedValues": [ "true", "false" ]
2424
},
25+
"Engine": {
26+
"Type": "String",
27+
"Default": "redis",
28+
"AllowedValues": [ "redis", "valkey" ],
29+
"Description": "The cache engine to use (redis or valkey)"
30+
},
2531
"EngineVersion": {
2632
"Type": "String",
27-
"Default": "7.0"
33+
"Default": "7.0",
34+
"Description": "The version of the cache engine"
2835
},
2936
"InstanceType": {
3037
"Type": "String",
@@ -94,7 +101,7 @@
94101
"AutoMinorVersionUpgrade": true,
95102
"CacheNodeType": { "Ref": "InstanceType" },
96103
"CacheSubnetGroupName": { "Ref": "CacheSubnetGroup" },
97-
"Engine": "redis",
104+
"Engine": { "Ref": "Engine" },
98105
"EngineVersion": { "Ref": "EngineVersion" },
99106
"NumCacheClusters": { "Ref": "NumCacheClusters" },
100107
"Port": "6379",
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{{ define "resource" }}
2+
{
3+
"AWSTemplateFormatVersion" : "2010-09-09",
4+
"Conditions": {
5+
"Encrypted": { "Fn::Equals": [ { "Ref": "Encrypted" }, "true" ] },
6+
"Private": { "Fn::Equals": [ { "Ref": "Private" }, "true" ] }
7+
},
8+
"Parameters": {
9+
"AutomaticFailoverEnabled": {
10+
"Type": "String",
11+
"Default": "false",
12+
"Description": "Indicates whether Multi-AZ is enabled. Must be accompanied with NumCacheClusters=2 or higher."
13+
},
14+
"Database": {
15+
"Type" : "String",
16+
"Default" : "0",
17+
"Description" : "Default database index"
18+
},
19+
"Encrypted": {
20+
"Type": "String",
21+
"Description": "Encrypt at rest and in transit",
22+
"Default": "false",
23+
"AllowedValues": [ "true", "false" ]
24+
},
25+
"EngineVersion": {
26+
"Type": "String",
27+
"Default": "8.1",
28+
"Description": "The version of the cache engine"
29+
},
30+
"InstanceType": {
31+
"Type": "String",
32+
"Default": "cache.t2.micro",
33+
"Description": "The type of instance to use"
34+
},
35+
"Private": {
36+
"Type": "String",
37+
"Description": "Create in private subnets",
38+
"Default": "false",
39+
"AllowedValues": [ "true", "false" ]
40+
},
41+
"NumCacheClusters": {
42+
"Type": "String",
43+
"Default": "1",
44+
"Description": "The number of cache clusters for this replication group"
45+
},
46+
"Subnets": {
47+
"Type": "List<AWS::EC2::Subnet::Id>",
48+
"Description": "VPC subnets"
49+
},
50+
"SubnetsPrivate": {
51+
"Type" : "List<AWS::EC2::Subnet::Id>",
52+
"Default" : "",
53+
"Description" : "VPC private subnets"
54+
},
55+
"Vpc": {
56+
"Type": "AWS::EC2::VPC::Id",
57+
"Description": "VPC"
58+
},
59+
"VpcCidr": {
60+
"Description": "VPC CIDR Block",
61+
"Type": "String"
62+
}
63+
},
64+
"Outputs": {
65+
"Port6379TcpAddr": { "Value": { "Fn::GetAtt": [ "ReplicationGroup", "PrimaryEndPoint.Address" ] } },
66+
"Port6379TcpPort": { "Value": { "Fn::GetAtt": [ "ReplicationGroup", "PrimaryEndPoint.Port" ] } },
67+
"EnvRedisDatabase": { "Value": { "Ref": "Database" } }
68+
},
69+
"Resources": {
70+
"SecurityGroup": {
71+
"Type": "AWS::EC2::SecurityGroup",
72+
"Properties": {
73+
"GroupDescription": "redis resource",
74+
"SecurityGroupIngress": [
75+
{ "IpProtocol": "tcp", "FromPort": "6379", "ToPort": "6379", "CidrIp": { "Ref": "VpcCidr" } }
76+
],
77+
"VpcId": { "Ref": "Vpc" }
78+
}
79+
},
80+
"CacheSubnetGroup": {
81+
"Type": "AWS::ElastiCache::SubnetGroup",
82+
"Properties": {
83+
"Description": "Redis subnet group",
84+
"SubnetIds": { "Fn::If": [ "Private",
85+
{ "Ref": "SubnetsPrivate" },
86+
{ "Ref": "Subnets" }
87+
] }
88+
}
89+
},
90+
"ReplicationGroup": {
91+
"Type": "AWS::ElastiCache::ReplicationGroup",
92+
"Properties": {
93+
"AtRestEncryptionEnabled": { "Fn::If": [ "Encrypted", "true", { "Ref": "AWS::NoValue" } ] },
94+
"AutomaticFailoverEnabled": { "Ref": "AutomaticFailoverEnabled" },
95+
"AutoMinorVersionUpgrade": true,
96+
"CacheNodeType": { "Ref": "InstanceType" },
97+
"CacheSubnetGroupName": { "Ref": "CacheSubnetGroup" },
98+
"Engine": "valkey",
99+
"EngineVersion": { "Ref": "EngineVersion" },
100+
"NumCacheClusters": { "Ref": "NumCacheClusters" },
101+
"Port": "6379",
102+
"ReplicationGroupDescription": { "Ref": "AWS::StackName" },
103+
"SecurityGroupIds": [ { "Ref": "SecurityGroup" } ],
104+
"TransitEncryptionEnabled": { "Fn::If": [ "Encrypted", "true", { "Ref": "AWS::NoValue" } ] }
105+
}
106+
}
107+
}
108+
}
109+
{{ end }}

0 commit comments

Comments
 (0)