Skip to content

Commit bf350c3

Browse files
authored
Add support for multi-az and final snapshot (#12)
1 parent a649a5d commit bf350c3

File tree

10 files changed

+76
-50
lines changed

10 files changed

+76
-50
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ errored.tfstate
44
crash.log
55
terraform.tfstate
66
*.tfstate*
7-
terraform.tfvars
7+
terraform.tfvars
8+
*.terraform.lock.hcl

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
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: v3.3.0
3+
rev: v3.4.0
44
hooks:
55
- id: check-added-large-files
66
args: ['--maxkb=500']

CHANGELOG.md

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

8+
- Update README.md
9+
10+
11+
<a name="1.4.0"></a>
12+
## [1.4.0] - 2020-12-08
13+
14+
- Add support for availability_zones parameter ([#11](https://github.com/umotif-public/terraform-aws-elasticache-redis/issues/11))
15+
16+
17+
<a name="1.3.1"></a>
18+
## [1.3.1] - 2020-11-12
19+
20+
- Update outputs + docs ([#9](https://github.com/umotif-public/terraform-aws-elasticache-redis/issues/9))
821

922

1023
<a name="1.3.0"></a>
@@ -59,7 +72,9 @@ All notable changes to this project will be documented in this file.
5972
- Initial commit of docs
6073

6174

62-
[Unreleased]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.3.0...HEAD
75+
[Unreleased]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.4.0...HEAD
76+
[1.4.0]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.3.1...1.4.0
77+
[1.3.1]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.3.0...1.3.1
6378
[1.3.0]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.2.0...1.3.0
6479
[1.2.0]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.1.1...1.2.0
6580
[1.1.1]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.1.0...1.1.1

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Terraform 0.12. Pin module version to `~> v1.0`. Submit pull-requests to `master
1313
```hcl
1414
module "redis" {
1515
source = "umotif-public/elasticache-redis/aws"
16-
version = "~> 1.3.0"
16+
version = "~> 1.5.0"
1717
1818
name_prefix = "core-example"
1919
number_cache_clusters = 2
@@ -72,14 +72,14 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [linkedin](http
7272
| Name | Version |
7373
|------|---------|
7474
| terraform | >= 0.12.6 |
75-
| aws | >= 2.41 |
75+
| aws | >= 3.26 |
7676
| random | >= 3.0 |
7777

7878
## Providers
7979

8080
| Name | Version |
8181
|------|---------|
82-
| aws | >= 2.41 |
82+
| aws | >= 3.26 |
8383
| random | >= 3.0 |
8484

8585
## Inputs
@@ -96,10 +96,12 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [linkedin](http
9696
| description | The description of the all resources. | `string` | `"Managed by Terraform"` | no |
9797
| 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 |
9898
| family | The family of the ElastiCache parameter group. | `string` | `"redis5.0"` | no |
99+
| final\_snapshot\_identifier | The name of your final node group (shard) snapshot. ElastiCache creates the snapshot from the primary node in the cluster. If omitted, no final snapshot will be made. | `string` | `null` | no |
99100
| ingress\_cidr\_blocks | List of Ingress CIDR blocks. | `list(string)` | `[]` | no |
100101
| ingress\_self | Specify whether the security group itself will be added as a source to the ingress rule. | `bool` | `false` | no |
101102
| 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 |
102103
| maintenance\_window | Specifies the weekly time range for when maintenance on the cache cluster is performed. | `string` | `""` | no |
104+
| 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 |
103105
| name\_prefix | The replication group identifier. This parameter is stored as a lowercase string. | `string` | n/a | yes |
104106
| node\_type | The compute and memory capacity of the nodes in the node group. | `string` | n/a | yes |
105107
| 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 |
@@ -123,9 +125,11 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [linkedin](http
123125
| elasticache\_auth\_token | The Redis Auth Token. |
124126
| elasticache\_parameter\_group\_id | The ElastiCache parameter group name. |
125127
| elasticache\_port | The Redis port. |
128+
| elasticache\_replication\_group\_arn | The Amazon Resource Name (ARN) of the created ElastiCache Replication Group. |
126129
| elasticache\_replication\_group\_id | The ID of the ElastiCache Replication Group. |
127130
| elasticache\_replication\_group\_member\_clusters | The identifiers of all the nodes that are part of this replication group. |
128131
| elasticache\_replication\_group\_primary\_endpoint\_address | The address of the endpoint for the primary node in the replication group. |
132+
| elasticache\_replication\_group\_reader\_endpoint\_address | The address of the endpoint for the reader node in the replication group. |
129133
| security\_group\_arn | The ARN of the Redis ElastiCache security group. |
130134
| security\_group\_description | The description of the Redis ElastiCache security group. |
131135
| security\_group\_egress | The egress rules of the Redis ElastiCache security group. |

examples/redis-basic/main.tf

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,19 @@ provider "aws" {
22
region = "eu-west-1"
33
}
44

5+
data "aws_caller_identity" "current" {}
6+
data "aws_region" "current" {}
7+
58
#####
69
# VPC and subnets
710
#####
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-
}
11+
data "aws_vpc" "default" {
12+
default = true
2513
}
2614

15+
data "aws_subnet_ids" "all" {
16+
vpc_id = data.aws_vpc.default.id
17+
}
2718
#####
2819
# Elasticache Redis
2920
#####
@@ -34,24 +25,26 @@ module "redis" {
3425
number_cache_clusters = 2
3526
node_type = "cache.t3.small"
3627

37-
engine_version = "5.0.6"
38-
port = 6379
39-
maintenance_window = "mon:03:00-mon:04:00"
40-
snapshot_window = "04:00-06:00"
41-
snapshot_retention_limit = 7
28+
engine_version = "6.x"
29+
port = 6379
30+
maintenance_window = "mon:03:00-mon:04:00"
31+
snapshot_window = "04:00-06:00"
32+
snapshot_retention_limit = 7
33+
final_snapshot_identifier = "redis-final-snapshot-name"
4234

4335
automatic_failover_enabled = true
36+
multi_az_enabled = true
4437

4538
at_rest_encryption_enabled = true
4639
transit_encryption_enabled = true
4740
auth_token = "1234567890asdfghjkl"
4841

4942
apply_immediately = true
50-
family = "redis5.0"
43+
family = "redis6.x"
5144
description = "Test elasticache redis."
5245

53-
subnet_ids = module.vpc.private_subnets
54-
vpc_id = module.vpc.vpc_id
46+
subnet_ids = data.aws_subnet_ids.all.ids
47+
vpc_id = data.aws_vpc.default.id
5548

5649
ingress_cidr_blocks = ["0.0.0.0/0"]
5750

examples/redis-clustered-mode/main.tf

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,12 @@ provider "aws" {
55
#####
66
# VPC and subnets
77
#####
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
8+
data "aws_vpc" "default" {
9+
default = true
10+
}
2111

22-
tags = {
23-
Environment = "test"
24-
}
12+
data "aws_subnet_ids" "all" {
13+
vpc_id = data.aws_vpc.default.id
2514
}
2615

2716
#####
@@ -54,8 +43,8 @@ module "redis" {
5443
family = "redis6.x"
5544
description = "Test elasticache redis."
5645

57-
subnet_ids = module.vpc.private_subnets
58-
vpc_id = module.vpc.vpc_id
46+
subnet_ids = data.aws_subnet_ids.all.ids
47+
vpc_id = data.aws_vpc.default.id
5948

6049
ingress_cidr_blocks = ["0.0.0.0/0"]
6150

main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ resource "aws_elasticache_replication_group" "redis" {
1616
maintenance_window = var.maintenance_window
1717
snapshot_window = var.snapshot_window
1818
snapshot_retention_limit = var.snapshot_retention_limit
19+
final_snapshot_identifier = var.final_snapshot_identifier
1920
automatic_failover_enabled = var.automatic_failover_enabled && var.number_cache_clusters > 1 ? true : false
2021
auto_minor_version_upgrade = var.auto_minor_version_upgrade
22+
multi_az_enabled = var.multi_az_enabled
2123

2224
at_rest_encryption_enabled = var.at_rest_encryption_enabled
2325
transit_encryption_enabled = var.transit_encryption_enabled

outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
output "elasticache_replication_group_arn" {
2+
value = aws_elasticache_replication_group.redis.arn
3+
description = "The Amazon Resource Name (ARN) of the created ElastiCache Replication Group."
4+
}
5+
16
output "elasticache_replication_group_id" {
27
value = aws_elasticache_replication_group.redis.id
38
description = "The ID of the ElastiCache Replication Group."
@@ -8,6 +13,11 @@ output "elasticache_replication_group_primary_endpoint_address" {
813
description = "The address of the endpoint for the primary node in the replication group."
914
}
1015

16+
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
18+
description = "The address of the endpoint for the reader node in the replication group."
19+
}
20+
1121
output "elasticache_replication_group_member_clusters" {
1222
value = aws_elasticache_replication_group.redis.member_clusters
1323
description = "The identifiers of all the nodes that are part of this replication group."

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,15 @@ variable "availability_zones" {
168168
description = "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."
169169
default = null
170170
}
171+
172+
variable "multi_az_enabled" {
173+
type = string
174+
description = "Specifies whether to enable Multi-AZ Support for the replication group. If true, `automatic_failover_enabled` must also be enabled. Defaults to false."
175+
default = null
176+
}
177+
178+
variable "final_snapshot_identifier" {
179+
type = string
180+
description = "The name of your final node group (shard) snapshot. ElastiCache creates the snapshot from the primary node in the cluster. If omitted, no final snapshot will be made."
181+
default = null
182+
}

versions.tf

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

44
required_providers {
5-
aws = ">= 2.41"
5+
aws = ">= 3.26"
66
random = ">= 3.0"
77
}
88
}

0 commit comments

Comments
 (0)