Skip to content

Commit 5dd4fba

Browse files
author
Hector Castro
committed
Merge branch 'release/2.0.0'
2 parents 979ca49 + 713360e commit 5dd4fba

File tree

5 files changed

+123
-70
lines changed

5 files changed

+123
-70
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.0.0
2+
3+
- Break backward compatibility again by swapping out the `aws_elasticache_cluster` resource with `aws_elasticache_replication_group`.
4+
- Remove `aws_elasticache_subnet_group`.
5+
16
## 1.0.0
27

38
- Break backward compatibility by removing the default security group rules

README.md

+45-21
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,63 @@ A Terraform module to create an Amazon Web Services (AWS) Redis ElastiCache clus
44

55
## Usage
66

7-
```javascript
8-
module "redis_elasticache" {
9-
source = "github.com/azavea/terraform-aws-redis-elasticache"
7+
```hcl
8+
resource "aws_sns_topic" "global" {
9+
...
10+
}
11+
12+
resource "aws_elasticache_subnet_group" "redis" {
13+
...
14+
}
1015
11-
vpc_id = "vpc-20f74844"
12-
vpc_cidr_block = "10.0.0.0/16"
16+
resource "aws_elasticache_parameter_group" "redis" {
17+
...
18+
}
19+
20+
module "cache" {
21+
source = "github.com/azavea/terraform-aws-redis-elasticache"
1322
14-
cache_name = "cache"
15-
engine_version = "2.8.22"
16-
instance_type = "cache.t2.micro"
17-
maintenance_window = "sun:05:00-sun:06:00"
23+
vpc_id = "vpc-20f74844"
24+
cache_identifier = "cache"
25+
automatic_failover_enabled = "false"
26+
desired_clusters = "1"
27+
instance_type = "cache.t2.micro"
28+
engine_version = "3.2.4"
29+
parameter_group = "${aws_elasticache_parameter_group.redis.name}"
30+
subnet_group = "${aws_elasticache_subnet_group.redis.name}"
31+
maintenance_window = "sun:02:30-sun:03:30"
32+
notification_topic_arn = "${aws_sns_topic.global.arn}"
1833
19-
private_subnet_ids = "subnet-4a887f3c,subnet-76dae35d"
34+
alarm_cpu_threshold = "75"
35+
alarm_memory_threshold = "10000000"
36+
alarm_actions = ["${aws_sns_topic.global.arn}"]
2037
21-
alarm_actions = "arn:aws:sns..."
38+
project = "Unknown"
39+
environment = "Unknown"
2240
}
2341
```
2442

2543
## Variables
2644

2745
- `vpc_id` - ID of VPC meant to house the cache
28-
- `vpc_cidr_block` - CIDR block of VPC
29-
- `cache_name` - Name used as ElastiCache cluster ID
30-
- `engine_version` - Cache engine version (default: `2.8.22`)
46+
- `project` - Name of the project making use of the cluster (default: `Unknown`)
47+
- `environment` - Name of environment the cluster is targeted for (default: `Unknown`)
48+
- `cache_identifier` - Name used as ElastiCache cluster ID
49+
- `automatic_failover_enabled` - Flag to determine if automatic failover should be enabled
50+
- `desired_clusters` - Number of cache clusters in replication group
3151
- `instance_type` - Instance type for cache instance (default: `cache.t2.micro`)
32-
- `maintenance_window` - 60 minute time window to reserve for maintenance
33-
(default: `sun:05:00-sun:06:00`)
34-
- `private_subnet_ids` - Comma delimited list of private subnet IDs
35-
- `alarm_actions` - Comma delimited list of ARNs to be notified via CloudWatch
52+
- `engine_version` - Cache engine version (default: `3.2.4`)
53+
- `parameter_group` - Cache parameter group name (default: `redis3.2`)
54+
- `subnet_group` - Cache subnet group name
55+
- `maintenance_window` - Time window to reserve for maintenance
56+
- `notification_topic_arn` - ARN to notify when cache events occur
57+
- `alarm_cpu_threshold` - CPU alarm threshold as a percentage (default: `75`)
58+
- `alarm_memory_threshold` - Free memory alarm threshold in bytes (default: `10000000`)
59+
- `alarm_actions` - ARN to be notified via CloudWatch when alarm thresholds are triggered
3660

3761
## Outputs
3862

63+
- `id` - The replication group ID
3964
- `cache_security_group_id` - Security group ID of the cache cluster
40-
- `hostname` - Public DNS name of cache node
41-
- `port` - Port of cache instance
42-
- `endpoint` - Public DNS name and port separated by a `:`
65+
- `port` - Port of replication group leader
66+
- `endpoint` - Public DNS name of replication group leader

main.tf

+35-34
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,81 @@
11
#
22
# Security group resources
33
#
4-
54
resource "aws_security_group" "redis" {
65
vpc_id = "${var.vpc_id}"
76

87
tags {
9-
Name = "sgCacheCluster"
8+
Name = "sgCacheCluster"
9+
Project = "${var.project}"
10+
Environment = "${var.environment}"
1011
}
1112
}
1213

1314
#
1415
# ElastiCache resources
1516
#
16-
17-
resource "aws_elasticache_cluster" "redis" {
18-
cluster_id = "${var.cache_name}"
19-
engine = "redis"
20-
engine_version = "${var.engine_version}"
21-
maintenance_window = "${var.maintenance_window}"
22-
node_type = "${var.instance_type}"
23-
num_cache_nodes = "1"
24-
parameter_group_name = "default.redis2.8"
25-
port = "6379"
26-
subnet_group_name = "${aws_elasticache_subnet_group.default.name}"
27-
security_group_ids = ["${aws_security_group.redis.id}"]
17+
resource "aws_elasticache_replication_group" "redis" {
18+
replication_group_id = "${lower(var.cache_identifier)}"
19+
replication_group_description = "Replication group for Redis"
20+
automatic_failover_enabled = "${var.automatic_failover_enabled}"
21+
number_cache_clusters = "${var.desired_clusters}"
22+
node_type = "${var.instance_type}"
23+
engine_version = "${var.engine_version}"
24+
parameter_group_name = "${var.parameter_group}"
25+
subnet_group_name = "${var.subnet_group}"
26+
security_group_ids = ["${aws_security_group.redis.id}"]
27+
maintenance_window = "${var.maintenance_window}"
28+
notification_topic_arn = "${var.notification_topic_arn}"
29+
port = "6379"
2830

2931
tags {
30-
Name = "CacheCluster"
32+
Name = "CacheReplicationGroup"
33+
Project = "${var.project}"
34+
Environment = "${var.environment}"
3135
}
3236
}
3337

34-
resource "aws_elasticache_subnet_group" "default" {
35-
name = "${var.cache_name}-subnet-group"
36-
description = "Private subnets for the ElastiCache instances"
37-
subnet_ids = ["${split(",", var.private_subnet_ids)}"]
38-
}
39-
4038
#
4139
# CloudWatch resources
4240
#
41+
resource "aws_cloudwatch_metric_alarm" "cache_cpu" {
42+
count = "${var.desired_clusters}"
4343

44-
resource "aws_cloudwatch_metric_alarm" "cpu" {
45-
alarm_name = "alarmCacheClusterCPUUtilization-${var.cache_name}"
46-
alarm_description = "Cache cluster CPU utilization"
44+
alarm_name = "alarm${var.environment}CacheCluster00${count.index + 1}CPUUtilization"
45+
alarm_description = "Redis cluster CPU utilization"
4746
comparison_operator = "GreaterThanThreshold"
4847
evaluation_periods = "1"
4948
metric_name = "CPUUtilization"
5049
namespace = "AWS/ElastiCache"
5150
period = "300"
5251
statistic = "Average"
53-
threshold = "75"
52+
53+
threshold = "${var.alarm_cpu_threshold}"
5454

5555
dimensions {
56-
CacheClusterId = "${aws_elasticache_cluster.redis.id}"
56+
CacheClusterId = "${aws_elasticache_replication_group.redis.id}-00${count.index + 1}"
5757
}
5858

59-
alarm_actions = ["${split(",", var.alarm_actions)}"]
59+
alarm_actions = ["${var.alarm_actions}"]
6060
}
6161

62-
resource "aws_cloudwatch_metric_alarm" "memory_free" {
63-
alarm_name = "alarmCacheClusterFreeableMemory-${var.cache_name}"
64-
alarm_description = "Cache cluster freeable memory"
62+
resource "aws_cloudwatch_metric_alarm" "cache_memory" {
63+
count = "${var.desired_clusters}"
64+
65+
alarm_name = "alarm${var.environment}CacheCluster00${count.index + 1}FreeableMemory"
66+
alarm_description = "Redis cluster freeable memory"
6567
comparison_operator = "LessThanThreshold"
6668
evaluation_periods = "1"
6769
metric_name = "FreeableMemory"
6870
namespace = "AWS/ElastiCache"
6971
period = "60"
7072
statistic = "Average"
7173

72-
# 10MB in bytes
73-
threshold = "10000000"
74+
threshold = "${var.alarm_memory_threshold}"
7475

7576
dimensions {
76-
CacheClusterId = "${aws_elasticache_cluster.redis.id}"
77+
CacheClusterId = "${aws_elasticache_replication_group.redis.id}-00${count.index + 1}"
7778
}
7879

79-
alarm_actions = ["${split(",", var.alarm_actions)}"]
80+
alarm_actions = ["${var.alarm_actions}"]
8081
}

outputs.tf

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
output "cache_security_group_id" {
2-
value = "${aws_security_group.redis.id}"
1+
output "id" {
2+
value = "${aws_elasticache_replication_group.redis.id}"
33
}
44

5-
output "hostname" {
6-
value = "${aws_elasticache_cluster.redis.cache_nodes.0.address}"
5+
output "cache_security_group_id" {
6+
value = "${aws_security_group.redis.id}"
77
}
88

99
output "port" {
10-
value = "${aws_elasticache_cluster.redis.cache_nodes.0.port}"
10+
value = "6379"
1111
}
1212

1313
output "endpoint" {
14-
value = "${join(":", aws_elasticache_cluster.redis.cache_nodes.0.address, aws_elasticache_cluster.redis.cache_nodes.0.port)}"
14+
value = "${aws_elasticache_replication_group.redis.primary_endpoint_address}"
1515
}

variables.tf

+32-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,50 @@
1-
variable "vpc_id" {
1+
variable "project" {
2+
default = "Unknown"
23
}
34

4-
variable "vpc_cidr_block" {
5+
variable "environment" {
6+
default = "Unknown"
57
}
68

7-
variable "cache_name" {
9+
variable "vpc_id" {}
10+
11+
variable "cache_identifier" {}
12+
13+
variable "parameter_group" {
14+
default = "redis3.2"
815
}
916

10-
variable "engine_version" {
11-
default = "2.8.22"
17+
variable "subnet_group" {}
18+
19+
variable "maintenance_window" {}
20+
21+
variable "desired_clusters" {
22+
default = "1"
1223
}
1324

1425
variable "instance_type" {
1526
default = "cache.t2.micro"
1627
}
1728

18-
variable "maintenance_window" {
19-
# SUN 01:00AM-02:00AM ET
20-
default = "sun:05:00-sun:06:00"
29+
variable "engine_version" {
30+
default = "3.2.4"
31+
}
32+
33+
variable "automatic_failover_enabled" {
34+
default = false
35+
}
36+
37+
variable "notification_topic_arn" {}
38+
39+
variable "alarm_cpu_threshold" {
40+
default = "75"
2141
}
2242

23-
variable "private_subnet_ids" {
43+
variable "alarm_memory_threshold" {
44+
# 10MB
45+
default = "10000000"
2446
}
2547

2648
variable "alarm_actions" {
49+
type = "list"
2750
}

0 commit comments

Comments
 (0)