@@ -6,16 +6,16 @@ resource "aws_security_group" "redis" {
6
6
vpc_id = " ${ var . vpc_id } "
7
7
8
8
ingress {
9
- from_port = 6379
10
- to_port = 6379
11
- protocol = " tcp"
9
+ from_port = 6379
10
+ to_port = 6379
11
+ protocol = " tcp"
12
12
cidr_blocks = [" ${ var . vpc_cidr_block } " ]
13
13
}
14
14
15
15
egress {
16
- from_port = 6379
17
- to_port = 6379
18
- protocol = " tcp"
16
+ from_port = 6379
17
+ to_port = 6379
18
+ protocol = " tcp"
19
19
cidr_blocks = [" ${ var . vpc_cidr_block } " ]
20
20
}
21
21
@@ -29,61 +29,66 @@ resource "aws_security_group" "redis" {
29
29
#
30
30
31
31
resource "aws_elasticache_cluster" "redis" {
32
- cluster_id = " ${ var . cache_name } "
33
- engine = " redis"
34
- engine_version = " ${ var . engine_version } "
35
- maintenance_window = " ${ var . maintenance_window } "
36
- node_type = " ${ var . instance_type } "
37
- num_cache_nodes = " 1"
32
+ cluster_id = " ${ var . cache_name } "
33
+ engine = " redis"
34
+ engine_version = " ${ var . engine_version } "
35
+ maintenance_window = " ${ var . maintenance_window } "
36
+ node_type = " ${ var . instance_type } "
37
+ num_cache_nodes = " 1"
38
38
parameter_group_name = " default.redis2.8"
39
- port = " 6379"
40
- subnet_group_name = " ${ aws_elasticache_subnet_group . default . name } "
41
- security_group_ids = [" ${ aws_security_group . redis . id } " ]
39
+ port = " 6379"
40
+ subnet_group_name = " ${ aws_elasticache_subnet_group . default . name } "
41
+ security_group_ids = [" ${ aws_security_group . redis . id } " ]
42
42
43
43
tags {
44
44
Name = " CacheCluster"
45
45
}
46
46
}
47
47
48
48
resource "aws_elasticache_subnet_group" "default" {
49
- name = " ${ var . cache_name } -subnet-group"
49
+ name = " ${ var . cache_name } -subnet-group"
50
50
description = " Private subnets for the ElastiCache instances"
51
- subnet_ids = [" ${ split (" ," , var. private_subnet_ids )} " ]
51
+ subnet_ids = [" ${ split (" ," , var. private_subnet_ids )} " ]
52
52
}
53
53
54
54
#
55
55
# CloudWatch resources
56
56
#
57
57
58
58
resource "aws_cloudwatch_metric_alarm" "cpu" {
59
- alarm_name = " alarmCacheClusterCPUUtilization"
60
- alarm_description = " Cache cluster CPU utilization"
59
+ alarm_name = " alarmCacheClusterCPUUtilization- ${ var . cache_name } "
60
+ alarm_description = " Cache cluster CPU utilization"
61
61
comparison_operator = " GreaterThanThreshold"
62
- evaluation_periods = " 1"
63
- metric_name = " CPUUtilization"
64
- namespace = " AWS/ElastiCache"
65
- period = " 300"
66
- statistic = " Average"
67
- threshold = " 75"
62
+ evaluation_periods = " 1"
63
+ metric_name = " CPUUtilization"
64
+ namespace = " AWS/ElastiCache"
65
+ period = " 300"
66
+ statistic = " Average"
67
+ threshold = " 75"
68
+
68
69
dimensions {
69
70
CacheClusterId = " ${ aws_elasticache_cluster . redis . id } "
70
71
}
72
+
71
73
alarm_actions = [" ${ split (" ," , var. alarm_actions )} " ]
72
74
}
73
75
74
76
resource "aws_cloudwatch_metric_alarm" "memory_free" {
75
- alarm_name = " alarmCacheClusterFreeableMemory"
76
- alarm_description = " Cache cluster freeable memory"
77
+ alarm_name = " alarmCacheClusterFreeableMemory- ${ var . cache_name } "
78
+ alarm_description = " Cache cluster freeable memory"
77
79
comparison_operator = " LessThanThreshold"
78
- evaluation_periods = " 1"
79
- metric_name = " FreeableMemory"
80
- namespace = " AWS/ElastiCache"
81
- period = " 60"
82
- statistic = " Average"
80
+ evaluation_periods = " 1"
81
+ metric_name = " FreeableMemory"
82
+ namespace = " AWS/ElastiCache"
83
+ period = " 60"
84
+ statistic = " Average"
85
+
83
86
# 10MB in bytes
84
87
threshold = " 10000000"
88
+
85
89
dimensions {
86
90
CacheClusterId = " ${ aws_elasticache_cluster . redis . id } "
87
91
}
92
+
88
93
alarm_actions = [" ${ split (" ," , var. alarm_actions )} " ]
89
94
}
0 commit comments