Skip to content

Commit 54daf93

Browse files
committed
docs: Add examples to README
1 parent 6f9c2d9 commit 54daf93

File tree

7 files changed

+287
-32
lines changed

7 files changed

+287
-32
lines changed

README.md

+254-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,259 @@ Terraform module which creates AWS ElastiCache resources.
88

99
See [`examples`](https://github.com/clowdhaus/terraform-aws-elasticache/tree/main/examples) directory for working examples to reference:
1010

11+
### Memcached Cluster
12+
13+
```hcl
14+
module "elasticache" {
15+
source = "clowdhaus/elasticache/aws"
16+
17+
cluster_id = "example-memcached"
18+
create_cluster = true
19+
create_replication_group = false
20+
21+
engine = "memcached"
22+
engine_version = "1.6.17"
23+
node_type = "cache.t4g.small"
24+
num_cache_nodes = 2
25+
az_mode = "cross-az"
26+
27+
maintenance_window = "sun:05:00-sun:09:00"
28+
apply_immediately = true
29+
30+
# Security group
31+
vpc_id = module.vpc.vpc_id
32+
security_group_rules = {
33+
ingress_vpc = {
34+
# Default type is `ingress`
35+
# Default port is based on the default engine port
36+
description = "VPC traffic"
37+
cidr_ipv4 = module.vpc.vpc_cidr_block
38+
}
39+
}
40+
41+
# Subnet Group
42+
subnet_ids = module.vpc.private_subnets
43+
44+
# Parameter Group
45+
create_parameter_group = true
46+
parameter_group_family = "memcached1.6"
47+
parameters = [
48+
{
49+
name = "idle_timeout"
50+
value = 60
51+
}
52+
]
53+
54+
tags = {
55+
Terraform = "true"
56+
Environment = "dev"
57+
}
58+
}
59+
```
60+
61+
### Redis Cluster
62+
63+
```hcl
64+
module "elasticache" {
65+
source = "clowdhaus/elasticache/aws"
66+
67+
cluster_id = "example-redis"
68+
create_cluster = true
69+
create_replication_group = false
70+
71+
engine_version = "7.1"
72+
node_type = "cache.t4g.small"
73+
74+
maintenance_window = "sun:05:00-sun:09:00"
75+
apply_immediately = true
76+
77+
# Security group
78+
vpc_id = module.vpc.vpc_id
79+
security_group_rules = {
80+
ingress_vpc = {
81+
# Default type is `ingress`
82+
# Default port is based on the default engine port
83+
description = "VPC traffic"
84+
cidr_ipv4 = module.vpc.vpc_cidr_block
85+
}
86+
}
87+
88+
# Subnet Group
89+
subnet_ids = module.vpc.private_subnets
90+
91+
# Parameter Group
92+
create_parameter_group = true
93+
parameter_group_family = "redis7"
94+
parameters = [
95+
{
96+
name = "latency-tracking"
97+
value = "yes"
98+
}
99+
]
100+
101+
tags = {
102+
Terraform = "true"
103+
Environment = "dev"
104+
}
105+
}
106+
```
107+
108+
### Redis Cluster Mode
109+
110+
```hcl
111+
module "elasticache" {
112+
source = "clowdhaus/elasticache/aws"
113+
114+
replication_group_id = "example-redis-cluster"
115+
116+
# Cluster mode
117+
cluster_mode_enabled = true
118+
num_node_groups = 2
119+
replicas_per_node_group = 3
120+
automatic_failover_enabled = true
121+
multi_az_enabled = true
122+
123+
maintenance_window = "sun:05:00-sun:09:00"
124+
apply_immediately = true
125+
126+
# Security group
127+
vpc_id = module.vpc.vpc_id
128+
security_group_rules = {
129+
ingress_vpc = {
130+
# Default type is `ingress`
131+
# Default port is based on the default engine port
132+
description = "VPC traffic"
133+
cidr_ipv4 = module.vpc.vpc_cidr_block
134+
}
135+
}
136+
137+
# Subnet Group
138+
subnet_ids = module.vpc.private_subnets
139+
140+
# Parameter Group
141+
create_parameter_group = true
142+
parameter_group_family = "redis7"
143+
parameters = [
144+
{
145+
name = "latency-tracking"
146+
value = "yes"
147+
}
148+
]
149+
150+
tags = {
151+
Terraform = "true"
152+
Environment = "dev"
153+
}
154+
}
155+
```
156+
157+
### Redis Global Replication Group
158+
159+
```hcl
160+
module "elasticache_primary" {
161+
source = "clowdhaus/elasticache/aws"
162+
163+
replication_group_id = "example-redis-global-replication-group"
164+
create_primary_global_replication_group = true
165+
166+
engine_version = "7.1"
167+
node_type = "cache.r7g.large"
168+
169+
# Security group
170+
vpc_id = module.vpc.vpc_id
171+
security_group_rules = {
172+
ingress_vpc = {
173+
# Default type is `ingress`
174+
# Default port is based on the default engine port
175+
description = "VPC traffic"
176+
cidr_ipv4 = module.vpc.vpc_cidr_block
177+
}
178+
}
179+
180+
# Subnet Group
181+
subnet_ids = module.vpc.private_subnets
182+
183+
# Parameter Group
184+
create_parameter_group = true
185+
parameter_group_family = "redis7"
186+
187+
tags = {
188+
Terraform = "true"
189+
Environment = "dev"
190+
}
191+
}
192+
193+
module "elasticache_secondary" {
194+
source = "clowdhaus/elasticache/aws"
195+
196+
providers = {
197+
aws = aws.other_region
198+
}
199+
200+
replication_group_id = "example-redis-global-replication-group"
201+
global_replication_group_id = module.elasticache_primary.global_replication_group_id
202+
203+
# Security group
204+
vpc_id = module.vpc.vpc_id
205+
security_group_rules = {
206+
ingress_vpc = {
207+
# Default type is `ingress`
208+
# Default port is based on the default engine port
209+
description = "VPC traffic"
210+
cidr_ipv4 = module.vpc.vpc_cidr_block
211+
}
212+
}
213+
214+
# Subnet Group
215+
subnet_ids = module.vpc.private_subnets
216+
217+
tags = {
218+
Terraform = "true"
219+
Environment = "dev"
220+
}
221+
}
222+
```
223+
224+
### Redis Replication Group
225+
11226
```hcl
12227
module "elasticache" {
13228
source = "clowdhaus/elasticache/aws"
14229
230+
replication_group_id = "example-redis-replication-group"
231+
232+
engine_version = "7.1"
233+
node_type = "cache.t4g.small"
234+
235+
transit_encryption_enabled = true
236+
auth_token = "PickSomethingMoreSecure123!"
237+
maintenance_window = "sun:05:00-sun:09:00"
238+
apply_immediately = true
239+
240+
# Security group
241+
vpc_id = module.vpc.vpc_id
242+
security_group_rules = {
243+
ingress_vpc = {
244+
# Default type is `ingress`
245+
# Default port is based on the default engine port
246+
description = "VPC traffic"
247+
cidr_ipv4 = module.vpc.vpc_cidr_block
248+
}
249+
}
250+
251+
# Subnet Group
252+
subnet_ids = module.vpc.private_subnets
253+
254+
# Parameter Group
255+
create_parameter_group = true
256+
parameter_group_family = "redis7"
257+
parameters = [
258+
{
259+
name = "latency-tracking"
260+
value = "yes"
261+
}
262+
]
263+
15264
tags = {
16265
Terraform = "true"
17266
Environment = "dev"
@@ -23,7 +272,11 @@ module "elasticache" {
23272

24273
Examples codified under the [`examples`](https://github.com/clowdhaus/terraform-aws-elasticache/tree/main/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!
25274

26-
- [Complete](https://github.com/clowdhaus/terraform-aws-elasticache/tree/main/examples/complete)
275+
- [Memcached Cluster](https://github.com/clowdhaus/terraform-aws-elasticache/tree/main/examples/memcached-cluster)
276+
- [Redis Cluster](https://github.com/clowdhaus/terraform-aws-elasticache/tree/main/examples/redis-cluster)
277+
- [Redis Cluster Mode](https://github.com/clowdhaus/terraform-aws-elasticache/tree/main/examples/redis-cluster-mode)
278+
- [Redis Global Replication Group](https://github.com/clowdhaus/terraform-aws-elasticache/tree/main/examples/redis-global-replication-group)
279+
- [Redis Replication Group](https://github.com/clowdhaus/terraform-aws-elasticache/tree/main/examples/redis-replication-group)
27280

28281
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
29282
## Requirements

examples/memcached-cluster/main.tf

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ module "elasticache" {
3535
num_cache_nodes = 2
3636
az_mode = "cross-az"
3737

38-
# Security group
38+
maintenance_window = "sun:05:00-sun:09:00"
39+
apply_immediately = true
40+
41+
# Security Group
3942
vpc_id = module.vpc.vpc_id
4043
security_group_rules = {
4144
ingress_vpc = {
@@ -46,15 +49,12 @@ module "elasticache" {
4649
}
4750
}
4851

49-
# subnet group
52+
# Subnet Group
5053
subnet_group_name = local.name
5154
subnet_group_description = "${title(local.name)} subnet group"
5255
subnet_ids = module.vpc.private_subnets
5356

54-
maintenance_window = "sun:05:00-sun:09:00"
55-
apply_immediately = true
56-
57-
# parameter group
57+
# Parameter Group
5858
create_parameter_group = true
5959
parameter_group_name = local.name
6060
parameter_group_family = "memcached1.6"

examples/redis-cluster-mode/main.tf

+7-8
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,18 @@ module "elasticache" {
3030
engine_version = "7.1"
3131
node_type = "cache.t4g.small"
3232

33-
# Cluster mode
33+
# Clustered mode
3434
cluster_mode_enabled = true
3535
num_node_groups = 2
3636
replicas_per_node_group = 3
3737
automatic_failover_enabled = true
3838
multi_az_enabled = true
3939

40-
user_group_ids = [module.elasticache_user_group.group_id]
40+
user_group_ids = [module.elasticache_user_group.group_id]
41+
maintenance_window = "sun:05:00-sun:09:00"
42+
apply_immediately = true
4143

42-
# Security group
44+
# Security Group
4345
vpc_id = module.vpc.vpc_id
4446
security_group_rules = {
4547
ingress_vpc = {
@@ -50,15 +52,12 @@ module "elasticache" {
5052
}
5153
}
5254

53-
# subnet group
55+
# Subnet Group
5456
subnet_group_name = local.name
5557
subnet_group_description = "${title(local.name)} subnet group"
5658
subnet_ids = module.vpc.private_subnets
5759

58-
maintenance_window = "sun:05:00-sun:09:00"
59-
apply_immediately = true
60-
61-
# parameter group
60+
# Parameter Group
6261
create_parameter_group = true
6362
parameter_group_family = "redis7"
6463
parameter_group_description = "${title(local.name)} parameter group"

examples/redis-cluster/main.tf

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ module "elasticache" {
3232
engine_version = "7.1"
3333
node_type = "cache.t4g.small"
3434

35-
# Security group
35+
maintenance_window = "sun:05:00-sun:09:00"
36+
apply_immediately = true
37+
38+
# Security Group
3639
vpc_id = module.vpc.vpc_id
3740
security_group_rules = {
3841
ingress_vpc = {
@@ -43,15 +46,12 @@ module "elasticache" {
4346
}
4447
}
4548

46-
# subnet group
49+
# Subnet Group
4750
subnet_group_name = local.name
4851
subnet_group_description = "${title(local.name)} subnet group"
4952
subnet_ids = module.vpc.private_subnets
5053

51-
maintenance_window = "sun:05:00-sun:09:00"
52-
apply_immediately = true
53-
54-
# parameter group
54+
# Parameter Group
5555
create_parameter_group = true
5656
parameter_group_name = local.name
5757
parameter_group_family = "redis7"

0 commit comments

Comments
 (0)