Skip to content

Commit 67cf19b

Browse files
author
Abdul Wahid
authored
Upgrade module to be compatible with AWS Provider 4.0.0 (#21)
BREAKING CHANGES Removed cluster_mode to use replicas_per_node_group and num_node_groups directly. number_cache_clusters changed to use num_cache_clusters availability_zones changed to use preferred_cache_cluster_azs replication_group_description changed to use description You will still need to set cluster_mode_enabled to true if you want a Redis cluster. These changes are based on the deprecation warnings that are received when trying to use this module with provider >=4.0.0
1 parent 5789921 commit 67cf19b

File tree

10 files changed

+109
-79
lines changed

10 files changed

+109
-79
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.0.1
3+
rev: v4.1.0
44
hooks:
55
- id: check-added-large-files
66
args: ['--maxkb=500']
@@ -18,7 +18,7 @@ repos:
1818
args: ['--allow-missing-credentials']
1919
- id: trailing-whitespace
2020
- repo: git://github.com/antonbabenko/pre-commit-terraform
21-
rev: v1.50.0
21+
rev: v1.64.0
2222
hooks:
2323
- id: terraform_fmt
2424
- id: terraform_docs

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ All notable changes to this project will be documented in this file.
77

88

99

10+
<a name="2.2.0"></a>
11+
## [2.2.0] - 2021-08-11
12+
13+
- Add support for global_replication_group_id ([#19](https://github.com/umotif-public/terraform-aws-elasticache-redis/issues/19))
14+
15+
16+
<a name="2.1.0"></a>
17+
## [2.1.0] - 2021-06-11
18+
19+
- Update docs and use main branch as default ([#18](https://github.com/umotif-public/terraform-aws-elasticache-redis/issues/18))
20+
- Add tags support to all resources ([#17](https://github.com/umotif-public/terraform-aws-elasticache-redis/issues/17))
21+
22+
1023
<a name="2.0.0"></a>
1124
## [2.0.0] - 2021-04-19
1225

@@ -84,7 +97,9 @@ All notable changes to this project will be documented in this file.
8497
- Initial commit of docs
8598

8699

87-
[Unreleased]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/2.0.0...HEAD
100+
[Unreleased]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/2.2.0...HEAD
101+
[2.2.0]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/2.1.0...2.2.0
102+
[2.1.0]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/2.0.0...2.1.0
88103
[2.0.0]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.5.0...2.0.0
89104
[1.5.0]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.4.0...1.5.0
90105
[1.4.0]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.3.1...1.4.0

README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/umotif-public/terraform-aws-elasticache-redis?style=social)
1+
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/umotif-public/terraform-aws-elasticache-redis)](https://github.com/umotif-public/terraform-aws-elasticache-redis/releases/latest)
22

33
# terraform-aws-elasticache-redis
44

55
A Terraform module to create an AWS Redis ElastiCache cluster
66

77
## Terraform versions
88

9-
Terraform 0.14.5 and higher, pin module version to `~> v2.0`.
10-
For Terraform 0.12 to 0.14.4, pin module version to `~> v1.0`.
11-
Submit pull-requests to `main` branch.
9+
- For AWS Provider >= 4.0.0, pin module version to `~> v3.0`.
10+
- For Terraform 0.14.5 and higher *and* AWS Provider < 4.0.0, pin module version to `~> v2.0`.
11+
- For Terraform 0.12 to 0.14.4, pin module version to `~> v1.0`.
12+
- Submit pull-requests to `main` branch.
1213

1314
## Usage
1415

@@ -57,27 +58,28 @@ module "redis" {
5758

5859
## Examples
5960

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)
61+
- [Redis Basic](https://github.com/umotif-public/terraform-aws-elasticache-redis/tree/main/examples/redis-basic)
62+
- [Redis Clustered Mode](https://github.com/umotif-public/terraform-aws-elasticache-redis/tree/main/examples/redis-clustered-mode)
63+
- [Redis Replication Group](https://github.com/umotif-public/terraform-aws-elasticache-redis/tree/main/examples/redis-replication-group)
6264

6365
## Authors
6466

65-
Module managed by [Marcin Cuber](https://github.com/marcincuber) [linkedin](https://www.linkedin.com/in/marcincuber/).
67+
Module managed by [Abdul Wahid](https://github.com/Ohid25) ([LinkedIn](https://www.linkedin.com/in/abdul-wahid/))
6668

6769
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6870
## Requirements
6971

7072
| Name | Version |
7173
|------|---------|
72-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.14.5 |
73-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.43 |
74+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.14.11 |
75+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0.0 |
7476
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.1.0 |
7577

7678
## Providers
7779

7880
| Name | Version |
7981
|------|---------|
80-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.43 |
82+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0.0 |
8183
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.1.0 |
8284

8385
## Modules
@@ -105,8 +107,7 @@ No modules.
105107
| <a name="input_at_rest_encryption_enabled"></a> [at\_rest\_encryption\_enabled](#input\_at\_rest\_encryption\_enabled) | Whether to enable encryption at rest. | `bool` | `true` | no |
106108
| <a name="input_auth_token"></a> [auth\_token](#input\_auth\_token) | The password used to access a password protected server. Can be specified only if `transit_encryption_enabled = true`. | `string` | `""` | no |
107109
| <a name="input_auto_minor_version_upgrade"></a> [auto\_minor\_version\_upgrade](#input\_auto\_minor\_version\_upgrade) | n/a | `string` | `true` | no |
108-
| <a name="input_automatic_failover_enabled"></a> [automatic\_failover\_enabled](#input\_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 |
109-
| <a name="input_availability_zones"></a> [availability\_zones](#input\_availability\_zones) | A list of EC2 availability zones in which the replication group's cache clusters will be created. The order of the availability zones in the list is not important. | `list(string)` | `null` | no |
110+
| <a name="input_automatic_failover_enabled"></a> [automatic\_failover\_enabled](#input\_automatic\_failover\_enabled) | Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. If enabled, number\_cache\_clusters must be greater than 1. Must be enabled for Redis (cluster mode enabled) replication groups. | `bool` | `true` | no |
110111
| <a name="input_cluster_mode_enabled"></a> [cluster\_mode\_enabled](#input\_cluster\_mode\_enabled) | Enable creation of a native redis cluster. | `bool` | `false` | no |
111112
| <a name="input_description"></a> [description](#input\_description) | The description of the all resources. | `string` | `"Managed by Terraform"` | no |
112113
| <a name="input_engine_version"></a> [engine\_version](#input\_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 |
@@ -117,15 +118,16 @@ No modules.
117118
| <a name="input_ingress_self"></a> [ingress\_self](#input\_ingress\_self) | Specify whether the security group itself will be added as a source to the ingress rule. | `bool` | `false` | no |
118119
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_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 |
119120
| <a name="input_maintenance_window"></a> [maintenance\_window](#input\_maintenance\_window) | Specifies the weekly time range for when maintenance on the cache cluster is performed. | `string` | `""` | no |
120-
| <a name="input_multi_az_enabled"></a> [multi\_az\_enabled](#input\_multi\_az\_enabled) | Specifies whether to enable Multi-AZ Support for the replication group. If true, `automatic_failover_enabled` must also be enabled. Defaults to false. | `string` | `null` | no |
121+
| <a name="input_multi_az_enabled"></a> [multi\_az\_enabled](#input\_multi\_az\_enabled) | Specifies whether to enable Multi-AZ Support for the replication group. If true, `automatic_failover_enabled` must also be enabled. Defaults to false. | `string` | `false` | no |
121122
| <a name="input_name_prefix"></a> [name\_prefix](#input\_name\_prefix) | The replication group identifier. This parameter is stored as a lowercase string. | `string` | n/a | yes |
122123
| <a name="input_node_type"></a> [node\_type](#input\_node\_type) | The compute and memory capacity of the nodes in the node group. | `string` | n/a | yes |
123124
| <a name="input_notification_topic_arn"></a> [notification\_topic\_arn](#input\_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 |
124-
| <a name="input_num_node_groups"></a> [num\_node\_groups](#input\_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 |
125-
| <a name="input_number_cache_clusters"></a> [number\_cache\_clusters](#input\_number\_cache\_clusters) | The number of cache clusters (primary and replicas) this replication group will have. | `number` | n/a | yes |
125+
| <a name="input_num_cache_clusters"></a> [num\_cache\_clusters](#input\_num\_cache\_clusters) | The number of cache clusters (primary and replicas) this replication group will have. If Multi-AZ is enabled, the value of this parameter must be at least 2. Updates will occur before other modifications. Conflicts with num\_node\_groups. | `number` | `1` | no |
126+
| <a name="input_num_node_groups"></a> [num\_node\_groups](#input\_num\_node\_groups) | 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 |
126127
| <a name="input_parameter"></a> [parameter](#input\_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 |
127128
| <a name="input_port"></a> [port](#input\_port) | The port number on which each of the cache nodes will accept connections. | `number` | `6379` | no |
128-
| <a name="input_replicas_per_node_group"></a> [replicas\_per\_node\_group](#input\_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 |
129+
| <a name="input_preferred_cache_cluster_azs"></a> [preferred\_cache\_cluster\_azs](#input\_preferred\_cache\_cluster\_azs) | A list of EC2 availability zones in which the replication group's cache clusters will be created. The order of the availability zones in the list is not important. | `list(string)` | `null` | no |
130+
| <a name="input_replicas_per_node_group"></a> [replicas\_per\_node\_group](#input\_replicas\_per\_node\_group) | Specify the number of replica nodes in each node group. Valid values are 0 to 5. Changing this number will trigger an online resizing operation before other settings modifications. | `number` | `0` | no |
129131
| <a name="input_security_group_ids"></a> [security\_group\_ids](#input\_security\_group\_ids) | List of Security Groups. | `list(string)` | `[]` | no |
130132
| <a name="input_snapshot_retention_limit"></a> [snapshot\_retention\_limit](#input\_snapshot\_retention\_limit) | The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. | `number` | `30` | no |
131133
| <a name="input_snapshot_window"></a> [snapshot\_window](#input\_snapshot\_window) | The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. | `string` | `""` | no |
@@ -164,9 +166,9 @@ See LICENSE for full details.
164166

165167
### Install dependencies
166168

167-
* [`pre-commit`](https://pre-commit.com/#install)
168-
* [`terraform-docs`](https://github.com/segmentio/terraform-docs) required for `terraform_docs` hooks.
169-
* [`TFLint`](https://github.com/terraform-linters/tflint) required for `terraform_tflint` hook.
169+
- [`pre-commit`](https://pre-commit.com/#install)
170+
- [`terraform-docs`](https://github.com/segmentio/terraform-docs) required for `terraform_docs` hooks.
171+
- [`TFLint`](https://github.com/terraform-linters/tflint) required for `terraform_tflint` hook.
170172

171173
#### MacOS
172174

examples/redis-basic/main.tf

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@ data "aws_vpc" "default" {
1212
default = true
1313
}
1414

15-
data "aws_subnet_ids" "all" {
16-
vpc_id = data.aws_vpc.default.id
15+
data "aws_subnets" "all" {
16+
filter {
17+
name = "vpc-id"
18+
values = [data.aws_vpc.default.id]
19+
}
1720
}
1821
#####
1922
# Elasticache Redis
2023
#####
2124
module "redis" {
2225
source = "../../"
2326

24-
name_prefix = "redis-basic-example"
25-
number_cache_clusters = 2
26-
node_type = "cache.t3.small"
27+
name_prefix = "redis-basic-example"
28+
num_cache_clusters = 2
29+
node_type = "cache.t3.small"
2730

2831
engine_version = "6.x"
2932
port = 6379
@@ -43,7 +46,7 @@ module "redis" {
4346
family = "redis6.x"
4447
description = "Test elasticache redis."
4548

46-
subnet_ids = data.aws_subnet_ids.all.ids
49+
subnet_ids = data.aws_subnets.all.ids
4750
vpc_id = data.aws_vpc.default.id
4851

4952
ingress_cidr_blocks = ["0.0.0.0/0"]

examples/redis-clustered-mode/main.tf

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ data "aws_vpc" "default" {
99
default = true
1010
}
1111

12-
data "aws_subnet_ids" "all" {
13-
vpc_id = data.aws_vpc.default.id
12+
data "aws_subnets" "all" {
13+
filter {
14+
name = "vpc-id"
15+
values = [data.aws_vpc.default.id]
16+
}
1417
}
1518

1619
#####
@@ -19,9 +22,9 @@ data "aws_subnet_ids" "all" {
1922
module "redis" {
2023
source = "../../"
2124

22-
name_prefix = "redis-clustered-example"
23-
number_cache_clusters = 2
24-
node_type = "cache.t3.small"
25+
name_prefix = "redis-clustered-example"
26+
num_cache_clusters = 2
27+
node_type = "cache.t3.small"
2528

2629
cluster_mode_enabled = true
2730
replicas_per_node_group = 1
@@ -43,7 +46,7 @@ module "redis" {
4346
family = "redis6.x"
4447
description = "Test elasticache redis."
4548

46-
subnet_ids = data.aws_subnet_ids.all.ids
49+
subnet_ids = data.aws_subnets.all.ids
4750
vpc_id = data.aws_vpc.default.id
4851

4952
ingress_cidr_blocks = ["0.0.0.0/0"]

examples/redis-replication-group/main.tf

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ data "aws_vpc" "replica" {
2121
provider = aws.replica
2222
}
2323

24-
data "aws_subnet_ids" "main" {
25-
vpc_id = data.aws_vpc.main.id
24+
data "aws_subnets" "main" {
25+
filter {
26+
name = "vpc-id"
27+
values = [data.aws_vpc.main.id]
28+
}
2629
}
2730

28-
data "aws_subnet_ids" "replica" {
29-
vpc_id = data.aws_vpc.replica.id
31+
data "aws_subnets" "replica" {
32+
filter {
33+
name = "vpc-id"
34+
values = [data.aws_vpc.replica.id]
35+
}
3036

3137
provider = aws.replica
3238
}
@@ -37,12 +43,12 @@ data "aws_subnet_ids" "replica" {
3743
module "redis_main" {
3844
source = "../../"
3945

40-
name_prefix = "redis-replication-example"
41-
number_cache_clusters = 2
42-
node_type = "cache.m5.large"
43-
auth_token = "1234567890asdfghjkl"
46+
name_prefix = "redis-example-main"
47+
num_cache_clusters = 2
48+
node_type = "cache.m5.large"
49+
auth_token = "1234567890asdfghjkl"
4450

45-
subnet_ids = data.aws_subnet_ids.main.ids
51+
subnet_ids = data.aws_subnets.main.ids
4652
vpc_id = data.aws_vpc.main.id
4753
}
4854

@@ -54,12 +60,12 @@ resource "aws_elasticache_global_replication_group" "this" {
5460
module "redis_replica" {
5561
source = "../../"
5662

57-
name_prefix = "redis-replication-example"
58-
number_cache_clusters = 2
59-
node_type = "cache.m5.large"
60-
auth_token = "1234567890asdfghjkl"
63+
name_prefix = "redis-example-replica"
64+
num_cache_clusters = 2
65+
node_type = "cache.m5.large"
66+
auth_token = "1234567890asdfghjkl"
6167

62-
subnet_ids = data.aws_subnet_ids.replica.ids
68+
subnet_ids = data.aws_subnets.replica.ids
6369
vpc_id = data.aws_vpc.replica.id
6470

6571
global_replication_group_id = aws_elasticache_global_replication_group.this.global_replication_group_id

main.tf

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ resource "aws_elasticache_replication_group" "redis" {
55
subnet_group_name = aws_elasticache_subnet_group.redis.name
66
security_group_ids = concat(var.security_group_ids, [aws_security_group.redis.id])
77

8-
availability_zones = var.availability_zones
9-
replication_group_id = var.global_replication_group_id == null ? "${var.name_prefix}-redis" : "${var.name_prefix}-redis-replica"
10-
number_cache_clusters = var.cluster_mode_enabled ? null : var.number_cache_clusters
11-
node_type = var.global_replication_group_id == null ? var.node_type : null
8+
preferred_cache_cluster_azs = var.preferred_cache_cluster_azs
9+
replication_group_id = var.global_replication_group_id == null ? "${var.name_prefix}-redis" : "${var.name_prefix}-redis-replica"
10+
num_cache_clusters = var.cluster_mode_enabled ? null : var.num_cache_clusters
11+
node_type = var.global_replication_group_id == null ? var.node_type : null
1212

1313
engine_version = var.global_replication_group_id == null ? var.engine_version : null
1414
port = var.port
@@ -17,7 +17,7 @@ resource "aws_elasticache_replication_group" "redis" {
1717
snapshot_window = var.snapshot_window
1818
snapshot_retention_limit = var.snapshot_retention_limit
1919
final_snapshot_identifier = var.final_snapshot_identifier
20-
automatic_failover_enabled = var.automatic_failover_enabled && var.number_cache_clusters > 1 ? true : false
20+
automatic_failover_enabled = var.automatic_failover_enabled && var.num_cache_clusters >= 2 ? true : false
2121
auto_minor_version_upgrade = var.auto_minor_version_upgrade
2222
multi_az_enabled = var.multi_az_enabled
2323

@@ -29,17 +29,12 @@ resource "aws_elasticache_replication_group" "redis" {
2929

3030
apply_immediately = var.apply_immediately
3131

32-
replication_group_description = var.description
32+
description = var.description
3333

3434
notification_topic_arn = var.notification_topic_arn
3535

36-
dynamic "cluster_mode" {
37-
for_each = var.cluster_mode_enabled ? [1] : []
38-
content {
39-
replicas_per_node_group = var.replicas_per_node_group
40-
num_node_groups = var.num_node_groups
41-
}
42-
}
36+
replicas_per_node_group = var.cluster_mode_enabled ? var.replicas_per_node_group : null
37+
num_node_groups = var.cluster_mode_enabled ? var.num_node_groups : null
4338

4439
tags = merge(
4540
{
@@ -63,7 +58,7 @@ resource "aws_elasticache_parameter_group" "redis" {
6358
description = var.description
6459

6560
dynamic "parameter" {
66-
for_each = var.cluster_mode_enabled ? concat([{ name = "cluster-enabled", value = "yes" }], var.parameter) : var.parameter
61+
for_each = var.num_node_groups > 0 ? concat([{ name = "cluster-enabled", value = "yes" }], var.parameter) : var.parameter
6762
content {
6863
name = parameter.value.name
6964
value = parameter.value.value

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ output "elasticache_replication_group_id" {
99
}
1010

1111
output "elasticache_replication_group_primary_endpoint_address" {
12-
value = var.cluster_mode_enabled ? aws_elasticache_replication_group.redis.configuration_endpoint_address : aws_elasticache_replication_group.redis.primary_endpoint_address
12+
value = var.num_node_groups > 1 ? aws_elasticache_replication_group.redis.configuration_endpoint_address : aws_elasticache_replication_group.redis.primary_endpoint_address
1313
description = "The address of the endpoint for the primary node in the replication group."
1414
}
1515

1616
output "elasticache_replication_group_reader_endpoint_address" {
17-
value = var.cluster_mode_enabled ? aws_elasticache_replication_group.redis.configuration_endpoint_address : aws_elasticache_replication_group.redis.reader_endpoint_address
17+
value = var.num_node_groups > 1 ? aws_elasticache_replication_group.redis.configuration_endpoint_address : aws_elasticache_replication_group.redis.reader_endpoint_address
1818
description = "The address of the endpoint for the reader node in the replication group."
1919
}
2020

0 commit comments

Comments
 (0)