From 6fffbf98e4135c3d7d95742892d8c3963a53851d Mon Sep 17 00:00:00 2001
From: Mayank Sharma <83959396+mayank0202@users.noreply.github.com>
Date: Tue, 9 Apr 2024 15:39:51 +0530
Subject: [PATCH] added optional sns topic in alarm actions (#31)
---
README.md | 3 ++-
main.tf | 12 ++++++++----
variables.tf | 7 +++++++
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index c229637..1d9fa55 100644
--- a/README.md
+++ b/README.md
@@ -59,7 +59,7 @@ In order to run all checks at any point run the following command:
| Name | Version |
|------|---------|
-| [aws](#provider\_aws) | 4.24.0 |
+| [aws](#provider\_aws) | 5.44.0 |
## Modules
@@ -90,6 +90,7 @@ No modules.
| [name\_prefix](#input\_name\_prefix) | Name prefix for resources on AWS | `any` | n/a | yes |
| [scale\_target\_max\_capacity](#input\_scale\_target\_max\_capacity) | The max capacity of the scalable target | `number` | `5` | no |
| [scale\_target\_min\_capacity](#input\_scale\_target\_min\_capacity) | The min capacity of the scalable target | `number` | `1` | no |
+| [sns\_topic\_arn](#input\_sns\_topic\_arn) | The ARN of an SNS topic to send notifications on alarm actions. | `string` | `""` | no |
| [tags](#input\_tags) | Resource tags | `map(string)` | `{}` | no |
## Outputs
diff --git a/main.tf b/main.tf
index daa6eb7..21ed96f 100644
--- a/main.tf
+++ b/main.tf
@@ -14,8 +14,10 @@ resource "aws_cloudwatch_metric_alarm" "cpu_high" {
ClusterName = var.ecs_cluster_name
ServiceName = var.ecs_service_name
}
- alarm_actions = [aws_appautoscaling_policy.scale_up_policy.arn]
-
+ alarm_actions = [
+ aws_appautoscaling_policy.scale_up_policy.arn,
+ var.sns_topic_arn != "" ? var.sns_topic_arn : null
+ ]
tags = var.tags
}
@@ -35,8 +37,10 @@ resource "aws_cloudwatch_metric_alarm" "cpu_low" {
ClusterName = var.ecs_cluster_name
ServiceName = var.ecs_service_name
}
- alarm_actions = [aws_appautoscaling_policy.scale_down_policy.arn]
-
+ alarm_actions = [
+ aws_appautoscaling_policy.scale_down_policy.arn,
+ var.sns_topic_arn != "" ? var.sns_topic_arn : null
+ ]
tags = var.tags
}
diff --git a/variables.tf b/variables.tf
index 722ff9d..acf3250 100644
--- a/variables.tf
+++ b/variables.tf
@@ -66,3 +66,10 @@ variable "scale_target_min_capacity" {
default = 1
type = number
}
+
+variable "sns_topic_arn" {
+ # Optional ARN of an SNS topic for sending notifications
+ type = string
+ description = "The ARN of an SNS topic to send notifications on alarm actions."
+ default = "" # Set an empty string as default to avoid potential errors
+}