Skip to content

Commit 04c913f

Browse files
Added variable to enable/disable slack noti.
1 parent f84919d commit 04c913f

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

examples/complete-cluster-mode/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ module "redis" {
117117
cloudwatch_metric_alarms_enabled = false
118118
alarm_cpu_threshold_percent = 70
119119
alarm_memory_threshold_bytes = "10000000" # in bytes
120+
slack_notification_enabled = false
120121
slack_username = ""
121122
slack_channel = ""
122123
slack_webhook_url = ""

examples/complete/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ module "redis" {
114114
cloudwatch_metric_alarms_enabled = false
115115
alarm_cpu_threshold_percent = 70
116116
alarm_memory_threshold_bytes = "10000000" # in bytes
117+
slack_notification_enabled = false
117118
slack_username = ""
118119
slack_channel = ""
119120
slack_webhook_url = ""

main.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,12 @@ resource "aws_cloudwatch_metric_alarm" "cache_memory" {
222222
}
223223

224224
resource "aws_kms_key" "this" {
225-
count = var.cloudwatch_metric_alarms_enabled ? 1 : 0
225+
count = var.slack_notification_enabled ? 1 : 0
226226
description = "KMS key for notify-slack test"
227227
}
228228

229229
resource "aws_kms_ciphertext" "slack_url" {
230-
count = var.cloudwatch_metric_alarms_enabled ? 1 : 0
230+
count = var.slack_notification_enabled ? 1 : 0
231231
plaintext = var.slack_webhook_url
232232
key_id = aws_kms_key.this[0].arn
233233
}
@@ -258,7 +258,7 @@ EOF
258258
}
259259

260260
data "archive_file" "lambdazip" {
261-
count = var.cloudwatch_metric_alarms_enabled ? 1 : 0
261+
count = var.slack_notification_enabled ? 1 : 0
262262
type = "zip"
263263
output_path = "${path.module}/lambda/sns_slack.zip"
264264

@@ -268,7 +268,7 @@ data "archive_file" "lambdazip" {
268268

269269
module "cw_sns_slack" {
270270
source = "./lambda"
271-
count = var.cloudwatch_metric_alarms_enabled ? 1 : 0
271+
count = var.slack_notification_enabled ? 1 : 0
272272
name = format("%s-%s-%s", var.environment, var.name, "sns-slack")
273273
description = "notify slack channel on sns topic"
274274
artifact_file = "${path.module}/lambda/sns_slack.zip"
@@ -288,15 +288,15 @@ module "cw_sns_slack" {
288288
}
289289

290290
resource "aws_sns_topic_subscription" "slack-endpoint" {
291-
count = var.cloudwatch_metric_alarms_enabled ? 1 : 0
291+
count = var.slack_notification_enabled ? 1 : 0
292292
endpoint = module.cw_sns_slack[0].arn
293293
protocol = "lambda"
294294
endpoint_auto_confirms = true
295295
topic_arn = aws_sns_topic.slack_topic[0].arn
296296
}
297297

298298
resource "aws_lambda_permission" "sns_lambda_slack_invoke" {
299-
count = var.cloudwatch_metric_alarms_enabled ? 1 : 0
299+
count = var.slack_notification_enabled ? 1 : 0
300300
statement_id = "sns_slackAllowExecutionFromSNS"
301301
action = "lambda:InvokeFunction"
302302
function_name = module.cw_sns_slack[0].arn

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ variable "alarm_memory_threshold_bytes" {
221221
description = "Ram threshold alarm level in bytes"
222222
}
223223

224+
variable "slack_notification_enabled" {
225+
type = bool
226+
description = "Whether to enable/disable slack notification."
227+
default = false
228+
}
229+
224230
variable "slack_webhook_url" {
225231
description = "The Slack Webhook URL where notifications will be sent."
226232
default = ""

0 commit comments

Comments
 (0)