Skip to content

Commit cf14416

Browse files
Merge pull request #4 from akae/master
SREFTP-4733 - Update code from upstream changes, include fix for parameter group versioning bug
2 parents efa42de + a0020e9 commit cf14416

File tree

9 files changed

+209
-79
lines changed

9 files changed

+209
-79
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.tfstate
33
*.tfstate.backup
44
.terraform
5+
.terraform.lock.hcl

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
repos:
22
- repo: git://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.21.0
3+
rev: v1.30.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_docs
77
- repo: git://github.com/pre-commit/pre-commit-hooks
8-
rev: v2.4.0
8+
rev: v3.1.0
99
hooks:
1010
- id: check-merge-conflict

README.md

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A terraform module providing a Redis ElastiCache cluster in AWS.
44

5-
This module
5+
This module is forked from [tf_aws_elasticache_redis Communitiy module](https://github.com/terraform-community-modules/tf_aws_elasticache_redis) and performs the following tasks:
66

77
- Creates Redis ElastiCache clusters
88
- Creates, manages, and exports a security group
@@ -11,14 +11,13 @@ This module
1111

1212
Terraform 0.12. Pin module version to `~> v2.0`. Submit pull-requests to `master` branch.
1313

14-
Terraform 0.11. Pin module version to `~> v1.0`.
14+
Terraform 0.11. Pin module version to `~> v1.0`. Submit pull-requests to `terraform011` branch.
1515

1616
## Usage
1717

1818
```hcl
1919
module "redis" {
20-
source = "github.com/terraform-community-modules/tf_aws_elasticache_redis.git"
21-
version = "~> 2.0"
20+
source = "github.com/flywirecorp/tf_aws_elasticache_redis.git?ref=v2.2.0"
2221
2322
env = "dev"
2423
name = "thtest"
@@ -41,48 +40,92 @@ module "redis" {
4140
```
4241

4342
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
43+
## Requirements
44+
45+
| Name | Version |
46+
|------|---------|
47+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12 |
48+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.12 |
49+
| <a name="requirement_random"></a> [random](#requirement\_random) | ~> 3.1 |
50+
51+
## Providers
52+
53+
| Name | Version |
54+
|------|---------|
55+
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 4.12 |
56+
| <a name="provider_random"></a> [random](#provider\_random) | ~> 3.1 |
57+
58+
## Modules
59+
60+
No modules.
61+
62+
## Resources
63+
64+
| Name | Type |
65+
|------|------|
66+
| [aws_elasticache_parameter_group.redis_parameter_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_parameter_group) | resource |
67+
| [aws_elasticache_replication_group.redis](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_replication_group) | resource |
68+
| [aws_elasticache_subnet_group.redis_subnet_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_subnet_group) | resource |
69+
| [aws_security_group.redis_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
70+
| [aws_security_group_rule.redis_ingress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
71+
| [aws_security_group_rule.redis_networks_ingress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
72+
| [aws_security_group_rule.redis_replication_egress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
73+
| [random_id.salt](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource |
74+
| [aws_vpc.vpc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |
75+
4476
## Inputs
4577

4678
| Name | Description | Type | Default | Required |
47-
|------|-------------|:----:|:-----:|:-----:|
48-
| alarm\_actions | | list | n/a | yes |
49-
| alarm\_cpu\_threshold | These vars would be used by cloudwatch.tf and should be uncommented if we decide to use them. | string | `"75"` | no |
50-
| alarm\_memory\_threshold | | string | `"10000000"` | no |
51-
| allowed\_cidr | A list of Security Group ID's to allow access to. | list(string) | `[ "127.0.0.1/32" ]` | no |
52-
| allowed\_security\_groups | A list of Security Group ID's to allow access to. | list(string) | `[]` | no |
53-
| apply\_immediately | Specifies whether any modifications are applied immediately, or during the next maintenance window. Default is false. | bool | `"false"` | no |
54-
| env | env to deploy into, should typically dev/staging/prod | string | n/a | yes |
55-
| name | Name for the Redis replication group i.e. UserObject | string | n/a | yes |
56-
| redis\_clusters | Number of Redis cache clusters (nodes) to create | string | n/a | yes |
57-
| redis\_failover | | bool | `"false"` | no |
58-
| redis\_maintenance\_window | Specifies the weekly time range for when maintenance on the cache cluster is performed. The format is ddd:hh24:mi-ddd:hh24:mi (24H Clock UTC). The minimum maintenance window is a 60 minute period | string | `"fri:08:00-fri:09:00"` | no |
59-
| redis\_node\_type | Instance type to use for creating the Redis cache clusters | string | `"cache.m3.medium"` | no |
60-
| redis\_parameters | additional parameters modifyed in parameter group | list(map(any)) | `[]` | no |
61-
| redis\_port | | number | `"6379"` | no |
62-
| redis\_snapshot\_retention\_limit | The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. For example, if you set SnapshotRetentionLimit to 5, then a snapshot that was taken today will be retained for 5 days before being deleted. If the value of SnapshotRetentionLimit is set to zero (0), backups are turned off. Please note that setting a snapshot_retention_limit is not supported on cache.t1.micro or cache.t2.* cache nodes | number | `"0"` | no |
63-
| redis\_snapshot\_window | The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. The minimum snapshot window is a 60 minute period | string | `"06:30-07:30"` | no |
64-
| redis\_version | Redis version to use, defaults to 3.2.10 | string | `"3.2.10"` | no |
65-
| subnets | List of VPC Subnet IDs for the cache subnet group | list(string) | n/a | yes |
66-
| tags | Tags for redis nodes | map(string) | `{}` | no |
67-
| vpc\_id | VPC ID | string | n/a | yes |
79+
|------|-------------|------|---------|:--------:|
80+
| <a name="input_env"></a> [env](#input\_env) | env to deploy into, should typically dev/staging/prod | `string` | n/a | yes |
81+
| <a name="input_name"></a> [name](#input\_name) | Name for the Redis replication group i.e. UserObject | `string` | n/a | yes |
82+
| <a name="input_redis_clusters"></a> [redis\_clusters](#input\_redis\_clusters) | Number of Redis cache clusters (nodes) to create | `string` | n/a | yes |
83+
| <a name="input_subnets"></a> [subnets](#input\_subnets) | List of VPC Subnet IDs for the cache subnet group | `list(string)` | n/a | yes |
84+
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC ID | `string` | n/a | yes |
85+
| <a name="input_allowed_cidr"></a> [allowed\_cidr](#input\_allowed\_cidr) | A list of Security Group ID's to allow access to. | `list(string)` | <pre>[<br> "127.0.0.1/32"<br>]</pre> | no |
86+
| <a name="input_allowed_security_groups"></a> [allowed\_security\_groups](#input\_allowed\_security\_groups) | A list of Security Group ID's to allow access to. | `list(string)` | `[]` | no |
87+
| <a name="input_apply_immediately"></a> [apply\_immediately](#input\_apply\_immediately) | Specifies whether any modifications are applied immediately, or during the next maintenance window. Default is false. | `bool` | `false` | no |
88+
| <a name="input_at_rest_encryption_enabled"></a> [at\_rest\_encryption\_enabled](#input\_at\_rest\_encryption\_enabled) | Whether to enable encryption at rest | `bool` | `false` | no |
89+
| <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. If specified must contain from 16 to 128 alphanumeric characters or symbols | `string` | `null` | no |
90+
| <a name="input_auto_minor_version_upgrade"></a> [auto\_minor\_version\_upgrade](#input\_auto\_minor\_version\_upgrade) | Specifies whether a minor engine upgrades will be applied automatically to the underlying Cache Cluster instances during the maintenance window | `bool` | `true` | no |
91+
| <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)` | `[]` | no |
92+
| <a name="input_is_migration_cluster"></a> [is\_migration\_cluster](#input\_is\_migration\_cluster) | Specifies whether this is a cluster for replicating other EC2 redis. Useful for migrations. | `bool` | `false` | no |
93+
| <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 |
94+
| <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 | `bool` | `false` | no |
95+
| <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 |
96+
| <a name="input_redis_failover"></a> [redis\_failover](#input\_redis\_failover) | Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails | `bool` | `false` | no |
97+
| <a name="input_redis_maintenance_window"></a> [redis\_maintenance\_window](#input\_redis\_maintenance\_window) | Specifies the weekly time range for when maintenance on the cache cluster is performed. The format is ddd:hh24:mi-ddd:hh24:mi (24H Clock UTC). The minimum maintenance window is a 60 minute period | `string` | `"fri:08:00-fri:09:00"` | no |
98+
| <a name="input_redis_node_type"></a> [redis\_node\_type](#input\_redis\_node\_type) | Instance type to use for creating the Redis cache clusters | `string` | `"cache.m3.medium"` | no |
99+
| <a name="input_redis_parameters"></a> [redis\_parameters](#input\_redis\_parameters) | additional parameters modifyed in parameter group | `list(map(any))` | `[]` | no |
100+
| <a name="input_redis_port"></a> [redis\_port](#input\_redis\_port) | n/a | `number` | `6379` | no |
101+
| <a name="input_redis_snapshot_retention_limit"></a> [redis\_snapshot\_retention\_limit](#input\_redis\_snapshot\_retention\_limit) | The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. For example, if you set SnapshotRetentionLimit to 5, then a snapshot that was taken today will be retained for 5 days before being deleted. If the value of SnapshotRetentionLimit is set to zero (0), backups are turned off. Please note that setting a snapshot\_retention\_limit is not supported on cache.t1.micro or cache.t2.* cache nodes | `number` | `0` | no |
102+
| <a name="input_redis_snapshot_window"></a> [redis\_snapshot\_window](#input\_redis\_snapshot\_window) | The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. The minimum snapshot window is a 60 minute period | `string` | `"06:30-07:30"` | no |
103+
| <a name="input_redis_version"></a> [redis\_version](#input\_redis\_version) | Redis version to use, defaults to 3.2.10 | `string` | `"3.2.10"` | no |
104+
| <a name="input_security_group_names"></a> [security\_group\_names](#input\_security\_group\_names) | A list of cache security group names to associate with this replication group | `list(string)` | `[]` | no |
105+
| <a name="input_snapshot_arns"></a> [snapshot\_arns](#input\_snapshot\_arns) | A single-element string list containing an Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3. Example: arn:aws:s3:::my\_bucket/snapshot1.rdb | `list(string)` | `[]` | no |
106+
| <a name="input_snapshot_name"></a> [snapshot\_name](#input\_snapshot\_name) | The name of a snapshot from which to restore data into the new node group. Changing the snapshot\_name forces a new resource | `string` | `""` | no |
107+
| <a name="input_tags"></a> [tags](#input\_tags) | Tags for redis nodes | `map(string)` | `{}` | no |
108+
| <a name="input_transit_encryption_enabled"></a> [transit\_encryption\_enabled](#input\_transit\_encryption\_enabled) | Whether to enable encryption in transit. Requires 3.2.6 or >=4.0 redis\_version | `bool` | `false` | no |
68109

69110
## Outputs
70111

71112
| Name | Description |
72113
|------|-------------|
73-
| endpoint | |
74-
| id | |
75-
| parameter\_group | |
76-
| port | |
77-
| redis\_security\_group\_id | |
78-
| redis\_subnet\_group\_name | |
114+
| <a name="output_endpoint"></a> [endpoint](#output\_endpoint) | Redis endpoint address |
115+
| <a name="output_id"></a> [id](#output\_id) | ID of the Redis replication group |
116+
| <a name="output_parameter_group"></a> [parameter\_group](#output\_parameter\_group) | ID of the Parameter Group to control the runtime properties of Redis nodes and clusters |
117+
| <a name="output_port"></a> [port](#output\_port) | Redis port (default is 6379) |
118+
| <a name="output_redis_security_group_id"></a> [redis\_security\_group\_id](#output\_redis\_security\_group\_id) | ID of the managed Security Group generated for Redis |
119+
| <a name="output_redis_subnet_group_name"></a> [redis\_subnet\_group\_name](#output\_redis\_subnet\_group\_name) | Name of the Redis subnet |
79120

80121
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
81122

82123
## Authors
83124

84125
Created by [Tim Hartmann](https://github.com/tfhartmann). Maintained by [Anton Babenko](https://github.com/antonbabenko) and [these awesome contributors](https://github.com/terraform-community-modules/tf_aws_elasticache_redis/graphs/contributors).
85126

127+
This fork is possible thanks to [these contributors](https://github.com/flywirecorp/tf_aws_elasticache_redis/graphs/contributors)
128+
86129
## License
87130

88131
[MIT License](LICENSE)

cloudwatch.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
resource "aws_cloudwatch_metric_alarm" "cache_cpu" {
77
count = "${var.redis_clusters}"
88
9-
alarm_name = "alarm-${var.name}-${data.aws_vpc.vpc.tags["Name"]}-CacheCluster00${count.index + 1}CPUUtilization"
9+
alarm_name = "alarm-${var.name}-${local.vpc_name}-CacheCluster00${count.index + 1}CPUUtilization"
1010
alarm_description = "Redis cluster CPU utilization"
1111
comparison_operator = "GreaterThanThreshold"
1212
evaluation_periods = "1"
@@ -27,7 +27,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_cpu" {
2727
resource "aws_cloudwatch_metric_alarm" "cache_memory" {
2828
count = "${var.redis_clusters}"
2929
30-
alarm_name = "alarm-${var.name}-${data.aws_vpc.vpc.tags["Name"]}-CacheCluster00${count.index + 1}FreeableMemory"
30+
alarm_name = "alarm-${var.name}-${local.vpc_name}-CacheCluster00${count.index + 1}FreeableMemory"
3131
alarm_description = "Redis cluster freeable memory"
3232
comparison_operator = "LessThanThreshold"
3333
evaluation_periods = "1"

main.tf

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ data "aws_vpc" "vpc" {
22
id = var.vpc_id
33
}
44

5+
locals {
6+
vpc_name = lookup(data.aws_vpc.vpc.tags, "Name", var.vpc_id)
7+
major_redis_version = parseint(substr(var.redis_version, 0, 1), 10)
8+
parameter_group_family = local.major_redis_version < 6 ? "redis${replace(var.redis_version, "/\\.[\\d]+$/", "")}" : local.major_redis_version == 6 ? "redis${replace(var.redis_version, "/\\.[\\d|x]+$/", "")}.x" : "redis${local.major_redis_version}"
9+
}
10+
511
resource "random_id" "salt" {
612
keepers = {
713
redis_version = "${var.redis_version}"
@@ -10,31 +16,42 @@ resource "random_id" "salt" {
1016
}
1117

1218
resource "aws_elasticache_replication_group" "redis" {
13-
replication_group_id = format("%.20s", "${var.name}-${var.env}")
14-
replication_group_description = "Terraform-managed ElastiCache replication group for ${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}"
15-
number_cache_clusters = var.redis_clusters
16-
node_type = var.redis_node_type
17-
automatic_failover_enabled = var.redis_failover
18-
multi_az_enabled = var.multi_az_enabled
19-
engine_version = var.redis_version
20-
port = var.redis_port
21-
parameter_group_name = aws_elasticache_parameter_group.redis_parameter_group.id
22-
subnet_group_name = aws_elasticache_subnet_group.redis_subnet_group.id
23-
security_group_ids = [aws_security_group.redis_security_group.id]
24-
apply_immediately = var.apply_immediately
25-
maintenance_window = var.redis_maintenance_window
26-
snapshot_window = var.redis_snapshot_window
27-
snapshot_retention_limit = var.redis_snapshot_retention_limit
28-
tags = merge(map("Name", format("tf-elasticache-%s-%s", var.name, lookup(data.aws_vpc.vpc.tags, "Name", ""))), var.tags)
19+
replication_group_id = format("%.20s", "${var.name}-${var.env}")
20+
description = "Terraform-managed ElastiCache replication group for ${var.name}-${var.env}-${local.vpc_name}"
21+
num_cache_clusters = var.redis_clusters
22+
node_type = var.redis_node_type
23+
automatic_failover_enabled = var.redis_failover
24+
auto_minor_version_upgrade = var.auto_minor_version_upgrade
25+
preferred_cache_cluster_azs = var.availability_zones
26+
multi_az_enabled = var.multi_az_enabled
27+
engine = "redis"
28+
at_rest_encryption_enabled = var.at_rest_encryption_enabled
29+
kms_key_id = var.kms_key_id
30+
transit_encryption_enabled = var.transit_encryption_enabled
31+
auth_token = var.transit_encryption_enabled ? var.auth_token : null
32+
engine_version = var.redis_version
33+
port = var.redis_port
34+
parameter_group_name = aws_elasticache_parameter_group.redis_parameter_group.id
35+
subnet_group_name = aws_elasticache_subnet_group.redis_subnet_group.id
36+
security_group_names = var.security_group_names
37+
security_group_ids = [aws_security_group.redis_security_group.id]
38+
snapshot_arns = var.snapshot_arns
39+
snapshot_name = var.snapshot_name
40+
apply_immediately = var.apply_immediately
41+
maintenance_window = var.redis_maintenance_window
42+
notification_topic_arn = var.notification_topic_arn
43+
snapshot_window = var.redis_snapshot_window
44+
snapshot_retention_limit = var.redis_snapshot_retention_limit
45+
tags = merge(tomap({ "Name" = format("tf-elasticache-%s-%s", var.name, local.vpc_name) }), var.tags)
2946
}
3047

3148
resource "aws_elasticache_parameter_group" "redis_parameter_group" {
32-
name = replace(format("%.255s", lower(replace("tf-redis-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}-${random_id.salt.hex}", "_", "-"))), "/\\s/", "-")
49+
name = replace(format("%.255s", lower(replace("tf-redis-${var.name}-${var.env}-${local.vpc_name}-${random_id.salt.hex}", "_", "-"))), "/\\s/", "-")
3350

34-
description = "Terraform-managed ElastiCache parameter group for ${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}"
51+
description = "Terraform-managed ElastiCache parameter group for ${var.name}-${var.env}-${local.vpc_name}"
3552

3653
# Strip the patch version from redis_version var
37-
family = "redis${replace(var.redis_version, "/\\.[\\d]+$/", "")}"
54+
family = local.parameter_group_family
3855
dynamic "parameter" {
3956
for_each = var.redis_parameters
4057
content {
@@ -49,6 +66,6 @@ resource "aws_elasticache_parameter_group" "redis_parameter_group" {
4966
}
5067

5168
resource "aws_elasticache_subnet_group" "redis_subnet_group" {
52-
name = replace(format("%.255s", lower(replace("tf-redis-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}", "_", "-"))), "/\\s/", "-")
69+
name = replace(format("%.255s", lower(replace("tf-redis-${var.name}-${var.env}-${local.vpc_name}", "_", "-"))), "/\\s/", "-")
5370
subnet_ids = var.subnets
5471
}

0 commit comments

Comments
 (0)