Skip to content

Commit

Permalink
Add support for clustered mode and upgrade fixes (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcincuber authored Nov 10, 2020
1 parent 5803b28 commit 94258bb
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 10 deletions.
31 changes: 29 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,30 @@ All notable changes to this project will be documented in this file.
<a name="unreleased"></a>
## [Unreleased]

- Update module versions to support v3 provider


<a name="1.2.0"></a>
## [1.2.0] - 2020-11-09

- Add self sg ingress rule option ([#7](https://github.com/umotif-public/terraform-aws-elasticache-redis/issues/7))


<a name="1.1.1"></a>
## [1.1.1] - 2020-11-09

- Update module to remove 0.14 limit ([#6](https://github.com/umotif-public/terraform-aws-elasticache-redis/issues/6))


<a name="1.1.0"></a>
## [1.1.0] - 2020-08-20

- Update main.tf


<a name="1.0.3"></a>
## [1.0.3] - 2020-08-05

- Feature/v3 provider support ([#4](https://github.com/umotif-public/terraform-aws-elasticache-redis/issues/4))
- Feature/updates ([#3](https://github.com/umotif-public/terraform-aws-elasticache-redis/issues/3))
- add git hooks and update docs
- Update README.md
Expand All @@ -30,6 +53,10 @@ All notable changes to this project will be documented in this file.
- Initial commit of docs


[Unreleased]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.0.2...HEAD
[Unreleased]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.2.0...HEAD
[1.2.0]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.1.1...1.2.0
[1.1.1]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.1.0...1.1.1
[1.1.0]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.0.3...1.1.0
[1.0.3]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.0.2...1.0.3
[1.0.2]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/umotif-public/terraform-aws-elasticache-redis/compare/1.0.0...1.0.1
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ Module is to be used with Terraform > 0.12.

## Examples

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

## Authors

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

## Providers

| Name | Version |
|------|---------|
| aws | >= 2.41 |
| random | >= 3.0 |

## Inputs

Expand All @@ -86,19 +89,22 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [linkedin](http
| auth\_token | The password used to access a password protected server. Can be specified only if `transit_encryption_enabled = true`. | `string` | `""` | no |
| auto\_minor\_version\_upgrade | n/a | `string` | `true` | no |
| 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 |
| cluster\_mode\_enabled | Enable creation of a native redis cluster. | `bool` | `false` | no |
| description | The description of the all resources. | `string` | `"Managed by Terraform"` | no |
| 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 |
| family | The family of the ElastiCache parameter group. | `string` | `"redis5.0"` | no |
| ingress\_self | Specify whether the security group itself will be added as a source to the ingress rule. | `bool` | `false` | no |
| ingress\_cidr\_blocks | List of Ingress CIDR blocks. | `list(string)` | `[]` | no |
| ingress\_self | Specify whether the security group itself will be added as a source to the ingress rule. | `bool` | `false` | no |
| 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 |
| maintenance\_window | Specifies the weekly time range for when maintenance on the cache cluster is performed. | `string` | `""` | no |
| name\_prefix | The replication group identifier. This parameter is stored as a lowercase string. | `string` | n/a | yes |
| node\_type | The compute and memory capacity of the nodes in the node group. | `string` | n/a | yes |
| 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 |
| 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 |
| number\_cache\_clusters | The number of cache clusters (primary and replicas) this replication group will have. | `number` | n/a | yes |
| 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 |
| port | The port number on which each of the cache nodes will accept connections. | `number` | `6379` | no |
| 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 |
| security\_group\_ids | List of Security Groups. | `list(string)` | `[]` | no |
| snapshot\_retention\_limit | The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. | `number` | `30` | no |
| snapshot\_window | The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. | `string` | `""` | no |
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions examples/core/main.tf → examples/redis-basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ provider "aws" {
#####
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.21.0"
version = "2.63.0"

name = "simple-vpc"

Expand All @@ -30,7 +30,7 @@ module "vpc" {
module "redis" {
source = "../../"

name_prefix = "core-example"
name_prefix = "redis-basic-example"
number_cache_clusters = 2
node_type = "cache.t3.small"

Expand Down
72 changes: 72 additions & 0 deletions examples/redis-clustered-mode/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
provider "aws" {
region = "eu-west-1"
}

#####
# VPC and subnets
#####
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.63.0"

name = "simple-vpc"

cidr = "10.0.0.0/16"

azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]

enable_nat_gateway = false

tags = {
Environment = "test"
}
}

#####
# Elasticache Redis
#####
module "redis" {
source = "../../"

name_prefix = "redis-clustered-example"
number_cache_clusters = 2
node_type = "cache.t3.small"

cluster_mode_enabled = true
replicas_per_node_group = 1
num_node_groups = 1

engine_version = "6.x"
port = 6379
maintenance_window = "mon:03:00-mon:04:00"
snapshot_window = "04:00-06:00"
snapshot_retention_limit = 7

automatic_failover_enabled = true

at_rest_encryption_enabled = true
transit_encryption_enabled = true
auth_token = "1234567890asdfghjkl"

apply_immediately = true
family = "redis6.x"
description = "Test elasticache redis."

subnet_ids = module.vpc.private_subnets
vpc_id = module.vpc.vpc_id

ingress_cidr_blocks = ["0.0.0.0/0"]

parameter = [
{
name = "repl-backlog-size"
value = "16384"
}
]

tags = {
Project = "Test"
}
}
26 changes: 23 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "aws_elasticache_replication_group" "redis" {
security_group_ids = concat(var.security_group_ids, [aws_security_group.redis.id])

replication_group_id = "${var.name_prefix}-redis"
number_cache_clusters = var.number_cache_clusters
number_cache_clusters = var.cluster_mode_enabled ? null : var.number_cache_clusters
node_type = var.node_type

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

notification_topic_arn = var.notification_topic_arn

dynamic "cluster_mode" {
for_each = var.cluster_mode_enabled ? [1] : []
content {
replicas_per_node_group = var.replicas_per_node_group
num_node_groups = var.num_node_groups
}
}

tags = merge(
{
"Name" = "${var.name_prefix}-redis"
Expand All @@ -37,18 +45,30 @@ resource "aws_elasticache_replication_group" "redis" {
)
}

resource "random_id" "redis_pg" {
keepers = {
family = var.family
}

byte_length = 2
}

resource "aws_elasticache_parameter_group" "redis" {
name = "${var.name_prefix}-redis-pg"
name = "${var.name_prefix}-redis-${random_id.redis_pg.hex}"
family = var.family
description = var.description

dynamic "parameter" {
for_each = var.parameter
for_each = var.cluster_mode_enabled ? concat([{ name = "cluster-enabled", value = "yes" }], var.parameter) : var.parameter
content {
name = parameter.value.name
value = parameter.value.value
}
}

lifecycle {
create_before_destroy = true
}
}

resource "aws_elasticache_subnet_group" "redis" {
Expand Down
18 changes: 18 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,21 @@ variable "notification_topic_arn" {
default = ""
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`"
}

variable "cluster_mode_enabled" {
type = bool
description = "Enable creation of a native redis cluster."
default = false
}

variable "replicas_per_node_group" {
type = number
default = 0
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."
}

variable "num_node_groups" {
type = number
default = 0
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."
}
3 changes: 2 additions & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ terraform {
required_version = ">= 0.12.6"

required_providers {
aws = ">= 2.41"
aws = ">= 2.41"
random = ">= 3.0"
}
}

0 comments on commit 94258bb

Please sign in to comment.