Skip to content

Commit 59c8bc7

Browse files
committed
feat: Update Redis cluster example
1 parent 399c7f4 commit 59c8bc7

File tree

12 files changed

+202
-71
lines changed

12 files changed

+202
-71
lines changed

examples/.DS_Store

-6 KB
Binary file not shown.

examples/complete-redis-cluster/cluster.tf

Lines changed: 0 additions & 45 deletions
This file was deleted.

examples/complete-redis-cluster/main.tf

Lines changed: 0 additions & 15 deletions
This file was deleted.

examples/complete-redis-cluster/outputs.tf

Whitespace-only changes.

examples/memcached-cluster/README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Note that this example may create resources which will incur monetary charges on
3232

3333
| Name | Source | Version |
3434
|------|--------|---------|
35-
| <a name="module_elasticache"></a> [elasticache](#module\_elasticache) | ../.. | n/a |
35+
| <a name="module_elasticache"></a> [elasticache](#module\_elasticache) | ../../ | n/a |
3636
| <a name="module_elasticache_disabled"></a> [elasticache\_disabled](#module\_elasticache\_disabled) | ../.. | n/a |
3737
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
3838

@@ -48,7 +48,23 @@ No inputs.
4848

4949
## Outputs
5050

51-
No outputs.
51+
| Name | Description |
52+
|------|-------------|
53+
| <a name="output_cluster_address"></a> [cluster\_address](#output\_cluster\_address) | (Memcached only) DNS name of the cache cluster without the port appended |
54+
| <a name="output_cluster_arn"></a> [cluster\_arn](#output\_cluster\_arn) | The ARN of the ElastiCache Cluster |
55+
| <a name="output_cluster_cache_nodes"></a> [cluster\_cache\_nodes](#output\_cluster\_cache\_nodes) | List of node objects including `id`, `address`, `port` and `availability_zone` |
56+
| <a name="output_cluster_configuration_endpoint"></a> [cluster\_configuration\_endpoint](#output\_cluster\_configuration\_endpoint) | (Memcached only) Configuration endpoint to allow host discovery |
57+
| <a name="output_cluster_engine_version_actual"></a> [cluster\_engine\_version\_actual](#output\_cluster\_engine\_version\_actual) | Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine |
58+
| <a name="output_parameter_group_arn"></a> [parameter\_group\_arn](#output\_parameter\_group\_arn) | The AWS ARN associated with the parameter group |
59+
| <a name="output_parameter_group_id"></a> [parameter\_group\_id](#output\_parameter\_group\_id) | The ElastiCache parameter group name |
60+
| <a name="output_rep_group_arn"></a> [rep\_group\_arn](#output\_rep\_group\_arn) | ARN of the created ElastiCache Replication Group |
61+
| <a name="output_rep_group_coniguration_endpoint_address"></a> [rep\_group\_coniguration\_endpoint\_address](#output\_rep\_group\_coniguration\_endpoint\_address) | Address of the replication group configuration endpoint when cluster mode is enabled |
62+
| <a name="output_rep_group_engine_version_actual"></a> [rep\_group\_engine\_version\_actual](#output\_rep\_group\_engine\_version\_actual) | Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine |
63+
| <a name="output_rep_group_id"></a> [rep\_group\_id](#output\_rep\_group\_id) | ID of the ElastiCache Replication Group |
64+
| <a name="output_rep_group_member_clusters"></a> [rep\_group\_member\_clusters](#output\_rep\_group\_member\_clusters) | Identifiers of all the nodes that are part of this replication group |
65+
| <a name="output_rep_group_primary_endpoint_address"></a> [rep\_group\_primary\_endpoint\_address](#output\_rep\_group\_primary\_endpoint\_address) | Address of the endpoint for the primary node in the replication group, if the cluster mode is disabled |
66+
| <a name="output_rep_group_reader_endpoint_address"></a> [rep\_group\_reader\_endpoint\_address](#output\_rep\_group\_reader\_endpoint\_address) | Address of the endpoint for the reader node in the replication group, if the cluster mode is disabled |
67+
| <a name="output_subnet_group_name"></a> [subnet\_group\_name](#output\_subnet\_group\_name) | The ElastiCache subnet group name |
5268
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
5369

5470
Apache-2.0 Licensed. See [LICENSE](https://github.com/clowdhaus/terraform-aws-elasticache/blob/main/LICENSE).

examples/memcached-cluster/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ locals {
2222
# ElastiCache Module
2323
################################################################################
2424

25-
module "elasticache_cluster" {
25+
module "elasticache" {
2626
source = "../../"
2727

2828
cluster_id = local.name

examples/complete-redis-cluster/README.md renamed to examples/redis-cluster/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# Complete ElastiCache example for Redis cluster
1+
# ElastiCache example for Redis cluster
22

33
Configuration in this directory creates set of ElastiCaChe resources including cluster, subnet group and parameter group.
44

5-
Data sources are used to discover existing VPC resources (VPC, subnet and security group).
6-
75
## Usage
86

97
To run this example you need to execute:
@@ -14,7 +12,7 @@ $ terraform plan
1412
$ terraform apply
1513
```
1614

17-
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
15+
Note that this example may create resources which will incur monetary charges on your AWS bill. Run `terraform destroy` when you no longer need these resources.
1816

1917
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2018
## Requirements
@@ -34,14 +32,15 @@ Note that this example may create resources which cost money. Run `terraform des
3432

3533
| Name | Source | Version |
3634
|------|--------|---------|
37-
| <a name="module_redis_cluster"></a> [redis\_cluster](#module\_redis\_cluster) | ../../ | n/a |
35+
| <a name="module_elasticache"></a> [elasticache](#module\_elasticache) | ../.. | n/a |
36+
| <a name="module_elasticache_disabled"></a> [elasticache\_disabled](#module\_elasticache\_disabled) | ../.. | n/a |
37+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
3838

3939
## Resources
4040

4141
| Name | Type |
4242
|------|------|
43-
| [aws_subnet_ids.all](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids) | data source |
44-
| [aws_vpc.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |
43+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
4544

4645
## Inputs
4746

@@ -51,3 +50,5 @@ No inputs.
5150

5251
No outputs.
5352
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
53+
54+
Apache-2.0 Licensed. See [LICENSE](https://github.com/clowdhaus/terraform-aws-elasticache/blob/main/LICENSE).

examples/redis-cluster/main.tf

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
provider "aws" {
2+
region = local.region
3+
}
4+
5+
data "aws_availability_zones" "available" {}
6+
7+
locals {
8+
region = "us-east-1"
9+
name = "ex-${basename(path.cwd)}"
10+
11+
vpc_cidr = "10.0.0.0/16"
12+
azs = slice(data.aws_availability_zones.available.names, 0, 3)
13+
14+
tags = {
15+
Name = local.name
16+
Example = local.name
17+
Repository = "https://github.com/clowdhaus/terraform-aws-elasticache"
18+
}
19+
}
20+
21+
################################################################################
22+
# ElastiCache Module
23+
################################################################################
24+
25+
module "elasticache" {
26+
source = "../../"
27+
28+
cluster_id = local.name
29+
30+
engine_version = "7.1"
31+
node_type = "cache.t4g.small"
32+
33+
security_group_ids = []
34+
35+
# subnet group
36+
subnet_group_name = local.name
37+
subnet_group_description = "${title(local.name)} subnet group"
38+
subnet_ids = module.vpc.private_subnets
39+
40+
maintenance_window = "sun:05:00-sun:09:00"
41+
apply_immediately = true
42+
43+
# parameter group
44+
create_parameter_group = true
45+
parameter_group_name = local.name
46+
parameter_group_family = "redis7.1"
47+
parameter_group_description = "${title(local.name)} parameter group"
48+
parameters = [
49+
{
50+
name = "activerehashing"
51+
value = "yes"
52+
},
53+
{
54+
name = "min-slaves-to-write"
55+
value = "2"
56+
}
57+
]
58+
59+
tags = local.tags
60+
}
61+
62+
63+
module "elasticache_disabled" {
64+
source = "../.."
65+
66+
create = false
67+
}
68+
69+
################################################################################
70+
# Supporting Resources
71+
################################################################################
72+
73+
module "vpc" {
74+
source = "terraform-aws-modules/vpc/aws"
75+
version = "~> 5.0"
76+
77+
name = local.name
78+
cidr = local.vpc_cidr
79+
80+
azs = local.azs
81+
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)]
82+
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 10)]
83+
84+
tags = local.tags
85+
}

examples/redis-cluster/outputs.tf

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
################################################################################
2+
# Cluster
3+
################################################################################
4+
5+
output "cluster_arn" {
6+
description = "The ARN of the ElastiCache Cluster"
7+
value = module.elasticache.cluster_arn
8+
}
9+
10+
output "cluster_engine_version_actual" {
11+
description = "Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine"
12+
value = module.elasticache.cluster_engine_version_actual
13+
}
14+
15+
output "cluster_cache_nodes" {
16+
description = "List of node objects including `id`, `address`, `port` and `availability_zone`"
17+
value = module.elasticache.cluster_cache_nodes
18+
}
19+
20+
output "cluster_address" {
21+
description = "(Memcached only) DNS name of the cache cluster without the port appended"
22+
value = module.elasticache.cluster_address
23+
}
24+
25+
output "cluster_configuration_endpoint" {
26+
description = "(Memcached only) Configuration endpoint to allow host discovery"
27+
value = module.elasticache.cluster_configuration_endpoint
28+
}
29+
30+
################################################################################
31+
# Replication Group
32+
################################################################################
33+
34+
output "rep_group_arn" {
35+
description = "ARN of the created ElastiCache Replication Group"
36+
value = module.elasticache.rep_group_arn
37+
}
38+
39+
output "rep_group_engine_version_actual" {
40+
description = "Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine"
41+
value = module.elasticache.rep_group_engine_version_actual
42+
}
43+
44+
output "rep_group_coniguration_endpoint_address" {
45+
description = "Address of the replication group configuration endpoint when cluster mode is enabled"
46+
value = module.elasticache.rep_group_coniguration_endpoint_address
47+
}
48+
49+
output "rep_group_id" {
50+
description = "ID of the ElastiCache Replication Group"
51+
value = module.elasticache.rep_group_id
52+
}
53+
54+
output "rep_group_member_clusters" {
55+
description = "Identifiers of all the nodes that are part of this replication group"
56+
value = module.elasticache.rep_group_member_clusters
57+
}
58+
59+
output "rep_group_primary_endpoint_address" {
60+
description = "Address of the endpoint for the primary node in the replication group, if the cluster mode is disabled"
61+
value = module.elasticache.rep_group_primary_endpoint_address
62+
}
63+
64+
output "rep_group_reader_endpoint_address" {
65+
description = "Address of the endpoint for the reader node in the replication group, if the cluster mode is disabled"
66+
value = module.elasticache.rep_group_reader_endpoint_address
67+
}
68+
69+
################################################################################
70+
# Parameter Group
71+
################################################################################
72+
73+
output "parameter_group_arn" {
74+
description = "The AWS ARN associated with the parameter group"
75+
value = module.elasticache.parameter_group_arn
76+
}
77+
78+
output "parameter_group_id" {
79+
description = "The ElastiCache parameter group name"
80+
value = module.elasticache.parameter_group_id
81+
}
82+
83+
################################################################################
84+
# Subnet Group
85+
################################################################################
86+
87+
output "subnet_group_name" {
88+
description = "The ElastiCache subnet group name"
89+
value = module.elasticache.subnet_group_name
90+
}
File renamed without changes.

0 commit comments

Comments
 (0)