Skip to content
This repository was archived by the owner on Sep 12, 2023. It is now read-only.

Commit cf113ad

Browse files
committed
added enabled variable
1 parent 0d15dcd commit cf113ad

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

modules/rds-cluster/main.tf

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ data "aws_region" "current" {}
1717
##########################################################################
1818

1919
resource "aws_sns_topic" "marbot" {
20+
count = var.enabled ? 1 : 0
2021
}
2122

2223
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)
2426
policy = data.aws_iam_policy_document.topic_policy.json
2527
}
2628

@@ -32,7 +34,7 @@ data "aws_iam_policy_document" "topic_policy" {
3234
resources = [aws_sns_topic.marbot.arn]
3335

3436
principals {
35-
type = "Service"
37+
type = "Service"
3638
identifiers = [
3739
"events.amazonaws.com",
3840
"rds.amazonaws.com",
@@ -60,9 +62,10 @@ data "aws_iam_policy_document" "topic_policy" {
6062
}
6163

6264
resource "aws_sns_topic_subscription" "marbot" {
65+
count = var.enabled ? 1 : 0
6366
depends_on = [aws_sns_topic_policy.marbot]
6467

65-
topic_arn = aws_sns_topic.marbot.arn
68+
topic_arn = join("", aws_sns_topic.marbot.*.arn)
6669
protocol = "https"
6770
endpoint = "https://api.marbot.io/${var.stage}/endpoint/${var.endpoint_id}"
6871
endpoint_auto_confirms = true
@@ -89,12 +92,13 @@ JSON
8992
##########################################################################
9093

9194
resource "random_id" "id8" {
92-
byte_length = 8
95+
byte_length = 8
9396
}
9497

9598

9699

97100
resource "aws_cloudwatch_metric_alarm" "cpu_utilization" {
101+
count = var.enabled ? 1 : 0
98102
depends_on = [aws_sns_topic_subscription.marbot]
99103

100104
alarm_name = "marbot-cpu-utilization-${random_id.id8.hex}"
@@ -106,17 +110,18 @@ resource "aws_cloudwatch_metric_alarm" "cpu_utilization" {
106110
evaluation_periods = 1
107111
comparison_operator = "GreaterThanThreshold"
108112
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 = {
112116
DBClusterIdentifier = var.db_cluster_identifier
113117
}
114-
treat_missing_data = "notBreaching"
118+
treat_missing_data = "notBreaching"
115119
}
116120

117121

118122

119123
resource "aws_cloudwatch_metric_alarm" "cpu_credit_balance" {
124+
count = var.enabled ? 1 : 0
120125
depends_on = [aws_sns_topic_subscription.marbot]
121126

122127
alarm_name = "marbot-cpu-credit-balance-${random_id.id8.hex}"
@@ -128,17 +133,18 @@ resource "aws_cloudwatch_metric_alarm" "cpu_credit_balance" {
128133
evaluation_periods = 1
129134
comparison_operator = "LessThanThreshold"
130135
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 = {
134139
DBClusterIdentifier = var.db_cluster_identifier
135140
}
136-
treat_missing_data = "notBreaching"
141+
treat_missing_data = "notBreaching"
137142
}
138143

139144

140145

141146
resource "aws_cloudwatch_metric_alarm" "freeable_memory" {
147+
count = var.enabled ? 1 : 0
142148
depends_on = [aws_sns_topic_subscription.marbot]
143149

144150
alarm_name = "marbot-freeable-memory-${random_id.id8.hex}"
@@ -150,12 +156,12 @@ resource "aws_cloudwatch_metric_alarm" "freeable_memory" {
150156
evaluation_periods = 1
151157
comparison_operator = "LessThanThreshold"
152158
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 = {
156162
DBClusterIdentifier = var.db_cluster_identifier
157163
}
158-
treat_missing_data = "notBreaching"
164+
treat_missing_data = "notBreaching"
159165
}
160166

161167
##########################################################################
@@ -165,9 +171,10 @@ resource "aws_cloudwatch_metric_alarm" "freeable_memory" {
165171
##########################################################################
166172

167173
resource "aws_db_event_subscription" "rds_cluster_issue" {
174+
count = var.enabled ? 1 : 0
168175
depends_on = [aws_sns_topic_subscription.marbot]
169176

170-
sns_topic = aws_sns_topic.marbot.arn
177+
sns_topic = join("", aws_sns_topic.marbot.*.arn)
171178
source_type = "db-cluster"
172179
source_ids = [var.db_cluster_identifier]
173180
}

modules/rds-cluster/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
output "topic_name" {
2-
value = aws_sns_topic.marbot.name
2+
value = join("",aws_sns_topic.marbot.*.name)
33
}
44

55
output "topic_arn" {
6-
value = aws_sns_topic.marbot.arn
6+
value = join("", aws_sns_topic.marbot.*.arn)
77
}

modules/rds-cluster/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ variable "endpoint_id" {
33
description = "Your marbot endpoint ID (to get this value: select a Slack channel where marbot belongs to and send a message like this: \"@marbot show me my endpoint id\")."
44
}
55

6+
variable "enabled" {
7+
type = bool
8+
description = "Turn the module on or off"
9+
default = true
10+
}
11+
612
variable "stage" {
713
type = string
814
description = "marbot stage (never change this!)."

0 commit comments

Comments
 (0)