@@ -17,10 +17,12 @@ data "aws_region" "current" {}
17
17
# #########################################################################
18
18
19
19
resource "aws_sns_topic" "marbot" {
20
+ count = var. enabled ? 1 : 0
20
21
}
21
22
22
23
resource "aws_sns_topic_policy" "marbot" {
23
- arn = aws_sns_topic. marbot . arn
24
+ count = var. enabled ? 1 : 0
25
+ arn = join (" " , aws_sns_topic. marbot . * . arn )
24
26
policy = data. aws_iam_policy_document . topic_policy . json
25
27
}
26
28
@@ -32,7 +34,7 @@ data "aws_iam_policy_document" "topic_policy" {
32
34
resources = [aws_sns_topic . marbot . arn ]
33
35
34
36
principals {
35
- type = " Service"
37
+ type = " Service"
36
38
identifiers = [
37
39
" events.amazonaws.com" ,
38
40
" rds.amazonaws.com" ,
@@ -60,9 +62,10 @@ data "aws_iam_policy_document" "topic_policy" {
60
62
}
61
63
62
64
resource "aws_sns_topic_subscription" "marbot" {
65
+ count = var. enabled ? 1 : 0
63
66
depends_on = [aws_sns_topic_policy . marbot ]
64
67
65
- topic_arn = aws_sns_topic. marbot . arn
68
+ topic_arn = join ( " " , aws_sns_topic. marbot . * . arn )
66
69
protocol = " https"
67
70
endpoint = " https://api.marbot.io/${ var . stage } /endpoint/${ var . endpoint_id } "
68
71
endpoint_auto_confirms = true
89
92
# #########################################################################
90
93
91
94
resource "random_id" "id8" {
92
- byte_length = 8
95
+ byte_length = 8
93
96
}
94
97
95
98
96
99
97
100
resource "aws_cloudwatch_metric_alarm" "cpu_utilization" {
101
+ count = var. enabled ? 1 : 0
98
102
depends_on = [aws_sns_topic_subscription . marbot ]
99
103
100
104
alarm_name = " marbot-cpu-utilization-${ random_id . id8 . hex } "
@@ -106,17 +110,18 @@ resource "aws_cloudwatch_metric_alarm" "cpu_utilization" {
106
110
evaluation_periods = 1
107
111
comparison_operator = " GreaterThanThreshold"
108
112
threshold = var. cpu_utilization_threshold
109
- alarm_actions = [aws_sns_topic . marbot . arn ]
110
- ok_actions = [aws_sns_topic . marbot . arn ]
111
- dimensions = {
113
+ alarm_actions = [join ( " " , aws_sns_topic. marbot . * . arn ) ]
114
+ ok_actions = [join ( " " , aws_sns_topic. marbot . * . arn ) ]
115
+ dimensions = {
112
116
DBClusterIdentifier = var.db_cluster_identifier
113
117
}
114
- treat_missing_data = " notBreaching"
118
+ treat_missing_data = " notBreaching"
115
119
}
116
120
117
121
118
122
119
123
resource "aws_cloudwatch_metric_alarm" "cpu_credit_balance" {
124
+ count = var. enabled ? 1 : 0
120
125
depends_on = [aws_sns_topic_subscription . marbot ]
121
126
122
127
alarm_name = " marbot-cpu-credit-balance-${ random_id . id8 . hex } "
@@ -128,17 +133,18 @@ resource "aws_cloudwatch_metric_alarm" "cpu_credit_balance" {
128
133
evaluation_periods = 1
129
134
comparison_operator = " LessThanThreshold"
130
135
threshold = var. cpu_credit_balance_threshold
131
- alarm_actions = [aws_sns_topic . marbot . arn ]
132
- ok_actions = [aws_sns_topic . marbot . arn ]
133
- dimensions = {
136
+ alarm_actions = [join ( " " , aws_sns_topic. marbot . * . arn ) ]
137
+ ok_actions = [join ( " " , aws_sns_topic. marbot . * . arn ) ]
138
+ dimensions = {
134
139
DBClusterIdentifier = var.db_cluster_identifier
135
140
}
136
- treat_missing_data = " notBreaching"
141
+ treat_missing_data = " notBreaching"
137
142
}
138
143
139
144
140
145
141
146
resource "aws_cloudwatch_metric_alarm" "freeable_memory" {
147
+ count = var. enabled ? 1 : 0
142
148
depends_on = [aws_sns_topic_subscription . marbot ]
143
149
144
150
alarm_name = " marbot-freeable-memory-${ random_id . id8 . hex } "
@@ -150,12 +156,12 @@ resource "aws_cloudwatch_metric_alarm" "freeable_memory" {
150
156
evaluation_periods = 1
151
157
comparison_operator = " LessThanThreshold"
152
158
threshold = var. freeable_memory_threshold
153
- alarm_actions = [aws_sns_topic . marbot . arn ]
154
- ok_actions = [aws_sns_topic . marbot . arn ]
155
- dimensions = {
159
+ alarm_actions = [join ( " " , aws_sns_topic. marbot . * . arn ) ]
160
+ ok_actions = [join ( " " , aws_sns_topic. marbot . * . arn ) ]
161
+ dimensions = {
156
162
DBClusterIdentifier = var.db_cluster_identifier
157
163
}
158
- treat_missing_data = " notBreaching"
164
+ treat_missing_data = " notBreaching"
159
165
}
160
166
161
167
# #########################################################################
@@ -165,9 +171,10 @@ resource "aws_cloudwatch_metric_alarm" "freeable_memory" {
165
171
# #########################################################################
166
172
167
173
resource "aws_db_event_subscription" "rds_cluster_issue" {
174
+ count = var. enabled ? 1 : 0
168
175
depends_on = [aws_sns_topic_subscription . marbot ]
169
176
170
- sns_topic = aws_sns_topic. marbot . arn
177
+ sns_topic = join ( " " , aws_sns_topic. marbot . * . arn )
171
178
source_type = " db-cluster"
172
179
source_ids = [var . db_cluster_identifier ]
173
180
}
0 commit comments