Skip to content
This repository was archived by the owner on Oct 8, 2022. It is now read-only.

Commit f44cee1

Browse files
authored
Merge pull request #8 from myoung34/develop
Add changes to lists and names
2 parents 9904175 + a7a17c0 commit f44cee1

File tree

4 files changed

+30
-35
lines changed

4 files changed

+30
-35
lines changed

README.md

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

55
## Usage
66

7-
```javascript
7+
```hcl
8+
resource "aws_security_group" "redis" {
9+
vpc_id = "${vpc.foo.id}"
10+
11+
tags {
12+
Name = "sgCacheCluster"
13+
}
14+
}
15+
816
module "redis_elasticache" {
917
source = "github.com/azavea/terraform-aws-redis-elasticache"
1018
1119
vpc_id = "vpc-20f74844"
12-
vpc_cidr_block = "10.0.0.0/16"
1320
1421
cache_name = "cache"
1522
engine_version = "2.8.22"
1623
instance_type = "cache.t2.micro"
1724
maintenance_window = "sun:05:00-sun:06:00"
1825
19-
private_subnet_ids = "subnet-4a887f3c,subnet-76dae35d"
26+
private_subnet_ids = ["subnet-4a887f3c","subnet-76dae35d"]
27+
security_group_ids = ["${aws_security_group.redis.id}"]
2028
21-
alarm_actions = "arn:aws:sns..."
29+
alarm_action = "arn:aws:sns..."
2230
}
2331
```
2432

2533
## Variables
2634

2735
- `vpc_id` - ID of VPC meant to house the cache
28-
- `vpc_cidr_block` - CIDR block of VPC
2936
- `cache_name` - Name used as ElastiCache cluster ID
3037
- `engine_version` - Cache engine version (default: `2.8.22`)
3138
- `instance_type` - Instance type for cache instance (default: `cache.t2.micro`)
3239
- `maintenance_window` - 60 minute time window to reserve for maintenance
3340
(default: `sun:05:00-sun:06:00`)
3441
- `private_subnet_ids` - Comma delimited list of private subnet IDs
35-
- `alarm_actions` - Comma delimited list of ARNs to be notified via CloudWatch
42+
- `alarm_action` - ARN to be notified via CloudWatch
3643

3744
## Outputs
3845

39-
- `cache_security_group_id` - Security group ID of the cache cluster
4046
- `hostname` - Public DNS name of cache node
4147
- `port` - Port of cache instance
4248
- `endpoint` - Public DNS name and port separated by a `:`

main.tf

+11-20
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
#
2-
# Security group resources
3-
#
4-
5-
resource "aws_security_group" "redis" {
6-
vpc_id = "${var.vpc_id}"
7-
8-
tags {
9-
Name = "sgCacheCluster"
10-
}
11-
}
12-
131
#
142
# ElastiCache resources
153
#
@@ -24,23 +12,22 @@ resource "aws_elasticache_cluster" "redis" {
2412
parameter_group_name = "default.redis2.8"
2513
port = "6379"
2614
subnet_group_name = "${aws_elasticache_subnet_group.default.name}"
27-
security_group_ids = ["${aws_security_group.redis.id}"]
15+
security_group_ids = "${var.security_group_ids}"
2816

2917
tags {
30-
Name = "CacheCluster"
18+
Name = "${var.cache_name}"
3119
}
3220
}
3321

3422
resource "aws_elasticache_subnet_group" "default" {
3523
name = "${var.cache_name}-subnet-group"
3624
description = "Private subnets for the ElastiCache instances"
37-
subnet_ids = ["${split(",", var.private_subnet_ids)}"]
25+
subnet_ids = "${var.private_subnet_ids}"
3826
}
3927

4028
#
4129
# CloudWatch resources
4230
#
43-
4431
resource "aws_cloudwatch_metric_alarm" "cpu" {
4532
alarm_name = "alarmCacheClusterCPUUtilization-${var.cache_name}"
4633
alarm_description = "Cache cluster CPU utilization"
@@ -53,10 +40,12 @@ resource "aws_cloudwatch_metric_alarm" "cpu" {
5340
threshold = "75"
5441

5542
dimensions {
56-
CacheClusterId = "${aws_elasticache_cluster.redis.id}"
43+
CacheClusterName = "${var.cache_name}"
5744
}
5845

59-
alarm_actions = ["${split(",", var.alarm_actions)}"]
46+
# for some reason trying to pass a list here causes the error ` * aws_cloudwatch_metric_alarm.cpu: alarm_actions: should be a list` in terraform 0.7.5
47+
# passing lists elsewhere works fine
48+
alarm_actions = ["${var.alarm_action}"]
6049
}
6150

6251
resource "aws_cloudwatch_metric_alarm" "memory_free" {
@@ -73,8 +62,10 @@ resource "aws_cloudwatch_metric_alarm" "memory_free" {
7362
threshold = "10000000"
7463

7564
dimensions {
76-
CacheClusterId = "${aws_elasticache_cluster.redis.id}"
65+
CacheClusterName = "${var.cache_name}"
7766
}
7867

79-
alarm_actions = ["${split(",", var.alarm_actions)}"]
68+
# for some reason trying to pass a list here causes the error ` * aws_cloudwatch_metric_alarm.cpu: alarm_actions: should be a list` in terraform 0.7.5
69+
# passing lists elsewhere works fine
70+
alarm_actions = ["${var.alarm_action}"]
8071
}

outputs.tf

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
output "cache_security_group_id" {
2-
value = "${aws_security_group.redis.id}"
3-
}
4-
51
output "hostname" {
62
value = "${aws_elasticache_cluster.redis.cache_nodes.0.address}"
73
}

variables.tf

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
variable "vpc_id" {
22
}
33

4-
variable "vpc_cidr_block" {
5-
}
6-
74
variable "cache_name" {
85
}
96

@@ -21,7 +18,12 @@ variable "maintenance_window" {
2118
}
2219

2320
variable "private_subnet_ids" {
21+
type = "list"
22+
}
23+
24+
variable "alarm_action" {
2425
}
2526

26-
variable "alarm_actions" {
27+
variable "security_group_ids" {
28+
type = "list"
2729
}

0 commit comments

Comments
 (0)