Skip to content

Commit 94258bb

Browse files
authored
Add support for clustered mode and upgrade fixes (#8)
1 parent 5803b28 commit 94258bb

File tree

8 files changed

+154
-10
lines changed

8 files changed

+154
-10
lines changed

CHANGELOG.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,30 @@ All notable changes to this project will be documented in this file.
55
<a name="unreleased"></a>
66
## [Unreleased]
77

8-
- Update module versions to support v3 provider
8+
9+
10+
<a name="1.2.0"></a>
11+
## [1.2.0] - 2020-11-09
12+
13+
- Add self sg ingress rule option ([#7](https://github.com/umotif-public/terraform-aws-elasticache-redis/issues/7))
14+
15+
16+
<a name="1.1.1"></a>
17+
## [1.1.1] - 2020-11-09
18+
19+
- Update module to remove 0.14 limit ([#6](https://github.com/umotif-public/terraform-aws-elasticache-redis/issues/6))
20+
21+
22+
<a name="1.1.0"></a>
23+
## [1.1.0] - 2020-08-20
24+
25+
- Update main.tf
26+
27+
28+
<a name="1.0.3"></a>
29+
## [1.0.3] - 2020-08-05
30+
31+
- Feature/v3 provider support ([#4](https://github.com/umotif-public/terraform-aws-elasticache-redis/issues/4))
932
- Feature/updates ([#3](https://github.com/umotif-public/terraform-aws-elasticache-redis/issues/3))
1033
- add git hooks and update docs
1134
- Update README.md
@@ -30,6 +53,10 @@ All notable changes to this project will be documented in this file.
3053
- Initial commit of docs
3154

3255

33-
[Unreleased]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.0.2...HEAD
56+
[Unreleased]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.2.0...HEAD
57+
[1.2.0]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.1.1...1.2.0
58+
[1.1.1]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.1.0...1.1.1
59+
[1.1.0]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.0.3...1.1.0
60+
[1.0.3]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.0.2...1.0.3
3461
[1.0.2]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.0.1...1.0.2
3562
[1.0.1]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.0.0...1.0.1

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ Module is to be used with Terraform > 0.12.
5757

5858
## Examples
5959

60-
* [Elasicache Redis](https://github.com/umotif-public/terraform-aws-elasticache-redis/tree/master/examples/core)
60+
* [Redis Basic](https://github.com/umotif-public/terraform-aws-elasticache-redis/tree/master/examples/redis-basic)
61+
* [Redis Clustered Mode](https://github.com/umotif-public/terraform-aws-elasticache-redis/tree/master/examples/redis-clustered-mode)
6162

6263
## Authors
6364

@@ -70,12 +71,14 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [linkedin](http
7071
|------|---------|
7172
| terraform | >= 0.12.6 |
7273
| aws | >= 2.41 |
74+
| random | >= 3.0 |
7375

7476
## Providers
7577

7678
| Name | Version |
7779
|------|---------|
7880
| aws | >= 2.41 |
81+
| random | >= 3.0 |
7982

8083
## Inputs
8184

@@ -86,19 +89,22 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [linkedin](http
8689
| auth\_token | The password used to access a password protected server. Can be specified only if `transit_encryption_enabled = true`. | `string` | `""` | no |
8790
| auto\_minor\_version\_upgrade | n/a | `string` | `true` | no |
8891
| automatic\_failover\_enabled | Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. | `bool` | `true` | no |
92+
| cluster\_mode\_enabled | Enable creation of a native redis cluster. | `bool` | `false` | no |
8993
| description | The description of the all resources. | `string` | `"Managed by Terraform"` | no |
9094
| engine\_version | The version number of the cache engine to be used for the cache clusters in this replication group. | `string` | `"5.0.6"` | no |
9195
| family | The family of the ElastiCache parameter group. | `string` | `"redis5.0"` | no |
92-
| ingress\_self | Specify whether the security group itself will be added as a source to the ingress rule. | `bool` | `false` | no |
9396
| ingress\_cidr\_blocks | List of Ingress CIDR blocks. | `list(string)` | `[]` | no |
97+
| ingress\_self | Specify whether the security group itself will be added as a source to the ingress rule. | `bool` | `false` | no |
9498
| kms\_key\_id | The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if `at_rest_encryption_enabled = true` | `string` | `""` | no |
9599
| maintenance\_window | Specifies the weekly time range for when maintenance on the cache cluster is performed. | `string` | `""` | no |
96100
| name\_prefix | The replication group identifier. This parameter is stored as a lowercase string. | `string` | n/a | yes |
97101
| node\_type | The compute and memory capacity of the nodes in the node group. | `string` | n/a | yes |
98102
| notification\_topic\_arn | An Amazon Resource Name (ARN) of an SNS topic to send ElastiCache notifications to. Example: `arn:aws:sns:us-east-1:012345678999:my_sns_topic` | `string` | `""` | no |
103+
| num\_node\_groups | Required when `cluster_mode_enabled` is set to true. Specify the number of node groups (shards) for this Redis replication group. Changing this number will trigger an online resizing operation before other settings modifications. | `number` | `0` | no |
99104
| number\_cache\_clusters | The number of cache clusters (primary and replicas) this replication group will have. | `number` | n/a | yes |
100105
| parameter | A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |
101106
| port | The port number on which each of the cache nodes will accept connections. | `number` | `6379` | no |
107+
| replicas\_per\_node\_group | Required when `cluster_mode_enabled` is set to true. Specify the number of replica nodes in each node group. Valid values are 0 to 5. Changing this number will force a new resource. | `number` | `0` | no |
102108
| security\_group\_ids | List of Security Groups. | `list(string)` | `[]` | no |
103109
| snapshot\_retention\_limit | The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. | `number` | `30` | no |
104110
| snapshot\_window | The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. | `string` | `""` | no |
File renamed without changes.

examples/core/main.tf renamed to examples/redis-basic/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ provider "aws" {
77
#####
88
module "vpc" {
99
source = "terraform-aws-modules/vpc/aws"
10-
version = "2.21.0"
10+
version = "2.63.0"
1111

1212
name = "simple-vpc"
1313

@@ -30,7 +30,7 @@ module "vpc" {
3030
module "redis" {
3131
source = "../../"
3232

33-
name_prefix = "core-example"
33+
name_prefix = "redis-basic-example"
3434
number_cache_clusters = 2
3535
node_type = "cache.t3.small"
3636

examples/redis-clustered-mode/main.tf

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
provider "aws" {
2+
region = "eu-west-1"
3+
}
4+
5+
#####
6+
# VPC and subnets
7+
#####
8+
module "vpc" {
9+
source = "terraform-aws-modules/vpc/aws"
10+
version = "2.63.0"
11+
12+
name = "simple-vpc"
13+
14+
cidr = "10.0.0.0/16"
15+
16+
azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
17+
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
18+
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
19+
20+
enable_nat_gateway = false
21+
22+
tags = {
23+
Environment = "test"
24+
}
25+
}
26+
27+
#####
28+
# Elasticache Redis
29+
#####
30+
module "redis" {
31+
source = "../../"
32+
33+
name_prefix = "redis-clustered-example"
34+
number_cache_clusters = 2
35+
node_type = "cache.t3.small"
36+
37+
cluster_mode_enabled = true
38+
replicas_per_node_group = 1
39+
num_node_groups = 1
40+
41+
engine_version = "6.x"
42+
port = 6379
43+
maintenance_window = "mon:03:00-mon:04:00"
44+
snapshot_window = "04:00-06:00"
45+
snapshot_retention_limit = 7
46+
47+
automatic_failover_enabled = true
48+
49+
at_rest_encryption_enabled = true
50+
transit_encryption_enabled = true
51+
auth_token = "1234567890asdfghjkl"
52+
53+
apply_immediately = true
54+
family = "redis6.x"
55+
description = "Test elasticache redis."
56+
57+
subnet_ids = module.vpc.private_subnets
58+
vpc_id = module.vpc.vpc_id
59+
60+
ingress_cidr_blocks = ["0.0.0.0/0"]
61+
62+
parameter = [
63+
{
64+
name = "repl-backlog-size"
65+
value = "16384"
66+
}
67+
]
68+
69+
tags = {
70+
Project = "Test"
71+
}
72+
}

main.tf

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ resource "aws_elasticache_replication_group" "redis" {
66
security_group_ids = concat(var.security_group_ids, [aws_security_group.redis.id])
77

88
replication_group_id = "${var.name_prefix}-redis"
9-
number_cache_clusters = var.number_cache_clusters
9+
number_cache_clusters = var.cluster_mode_enabled ? null : var.number_cache_clusters
1010
node_type = var.node_type
1111

1212
engine_version = var.engine_version
@@ -29,6 +29,14 @@ resource "aws_elasticache_replication_group" "redis" {
2929

3030
notification_topic_arn = var.notification_topic_arn
3131

32+
dynamic "cluster_mode" {
33+
for_each = var.cluster_mode_enabled ? [1] : []
34+
content {
35+
replicas_per_node_group = var.replicas_per_node_group
36+
num_node_groups = var.num_node_groups
37+
}
38+
}
39+
3240
tags = merge(
3341
{
3442
"Name" = "${var.name_prefix}-redis"
@@ -37,18 +45,30 @@ resource "aws_elasticache_replication_group" "redis" {
3745
)
3846
}
3947

48+
resource "random_id" "redis_pg" {
49+
keepers = {
50+
family = var.family
51+
}
52+
53+
byte_length = 2
54+
}
55+
4056
resource "aws_elasticache_parameter_group" "redis" {
41-
name = "${var.name_prefix}-redis-pg"
57+
name = "${var.name_prefix}-redis-${random_id.redis_pg.hex}"
4258
family = var.family
4359
description = var.description
4460

4561
dynamic "parameter" {
46-
for_each = var.parameter
62+
for_each = var.cluster_mode_enabled ? concat([{ name = "cluster-enabled", value = "yes" }], var.parameter) : var.parameter
4763
content {
4864
name = parameter.value.name
4965
value = parameter.value.value
5066
}
5167
}
68+
69+
lifecycle {
70+
create_before_destroy = true
71+
}
5272
}
5373

5474
resource "aws_elasticache_subnet_group" "redis" {

variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,21 @@ variable "notification_topic_arn" {
144144
default = ""
145145
description = "An Amazon Resource Name (ARN) of an SNS topic to send ElastiCache notifications to. Example: `arn:aws:sns:us-east-1:012345678999:my_sns_topic`"
146146
}
147+
148+
variable "cluster_mode_enabled" {
149+
type = bool
150+
description = "Enable creation of a native redis cluster."
151+
default = false
152+
}
153+
154+
variable "replicas_per_node_group" {
155+
type = number
156+
default = 0
157+
description = "Required when `cluster_mode_enabled` is set to true. Specify the number of replica nodes in each node group. Valid values are 0 to 5. Changing this number will force a new resource."
158+
}
159+
160+
variable "num_node_groups" {
161+
type = number
162+
default = 0
163+
description = "Required when `cluster_mode_enabled` is set to true. Specify the number of node groups (shards) for this Redis replication group. Changing this number will trigger an online resizing operation before other settings modifications."
164+
}

versions.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ terraform {
22
required_version = ">= 0.12.6"
33

44
required_providers {
5-
aws = ">= 2.41"
5+
aws = ">= 2.41"
6+
random = ">= 3.0"
67
}
78
}

0 commit comments

Comments
 (0)