Skip to content

Commit

Permalink
LPAL-1290 Remove ECS state change alarm for development
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Ainsworth committed Mar 14, 2024
1 parent f5bdd79 commit 68fc20c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion terraform/region/modules/region/cloudwatch.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
locals {
# Don't create ECS Task Stopped alerts in development account
enable_task_stopped_alerts = var.account_name != "development" ? 1 : 0
}
resource "aws_cloudwatch_metric_alarm" "elasticache_high_cpu_utilization" {
count = local.cache_cluster_count
actions_enabled = true
Expand Down Expand Up @@ -45,6 +49,7 @@ resource "aws_cloudwatch_metric_alarm" "elasticache_high_swap_utilization" {
}

resource "aws_cloudwatch_event_rule" "tasks_stopped" {
count = local.enable_task_stopped_alerts ? 1 : 0
name = "${local.account_name}-${local.region_name}-capture-ecs-task-stopped"
description = "Capture each task-stopped event in ECS"

Expand All @@ -66,17 +71,34 @@ resource "aws_cloudwatch_event_rule" "tasks_stopped" {
)
}

moved {
from = aws_cloudwatch_event_rule.tasks_stopped
to = aws_cloudwatch_event_rule.tasks_stopped[0]
}

resource "aws_cloudwatch_event_target" "tasks_stopped" {
rule = aws_cloudwatch_event_rule.tasks_stopped.name
count = local.enable_task_stopped_alerts ? 1 : 0
rule = aws_cloudwatch_event_rule.tasks_stopped[0].name
target_id = "SendToSNS"
arn = aws_sns_topic.cloudwatch_to_account_ops_alerts.arn
}

moved {
from = aws_cloudwatch_event_target.tasks_stopped
to = aws_cloudwatch_event_target.tasks_stopped[0]
}

resource "aws_sns_topic_policy" "task_stopped_policy" {
count = local.enable_task_stopped_alerts ? 1 : 0
arn = aws_sns_topic.cloudwatch_to_account_ops_alerts.arn
policy = data.aws_iam_policy_document.task_stopped_topic_policy.json
}

moved {
from = aws_sns_topic_policy.task_stopped_policy
to = aws_sns_topic_policy.task_stopped_policy[0]
}

data "aws_iam_policy_document" "task_stopped_topic_policy" {
statement {
effect = "Allow"
Expand Down

0 comments on commit 68fc20c

Please sign in to comment.