generated from DNXLabs/terraform-aws-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
43 lines (37 loc) · 1.51 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
locals {
custom_event_pattern = {
"source" = ["aws.health"],
"detail-type" = ["AWS Health Event"],
"detail" = {
"service" = var.aws_health_services
}
}
default_event_pattern = {
"source" = ["aws.health"],
"detail-type" = ["AWS Health Event"]
}
}
resource "aws_cloudwatch_event_rule" "console" {
name = var.event_rule_name
description = "EventBridge rule for AWS Health events"
event_pattern = var.use_default_event_pattern ? jsonencode(local.default_event_pattern) : jsonencode(local.custom_event_pattern)
}
resource "aws_sns_topic" "health_event_topic" {
count = var.sns_topic_name != "" ? 1 : 0
kms_master_key_id = var.sns_kms_encryption ? aws_kms_key.sns[0].id : null # default key does not allow cloudwatch alarms to publish
name = var.sns_topic_name
}
resource "aws_sns_topic_subscription" "email_subscription" {
count = var.email_endpoint != "" && var.sns_topic_name != "" ? 1 : 0
topic_arn = aws_sns_topic.health_event_topic[count.index].arn
protocol = "email"
endpoint = var.email_endpoint
}
resource "aws_sns_topic_subscription" "webhook_subscription" {
count = var.webhook_endpoint != "" && var.sns_topic_name != "" ? 1 : 0
topic_arn = aws_sns_topic.health_event_topic[count.index].arn
protocol = "https"
endpoint = var.webhook_endpoint
confirmation_timeout_in_minutes = 1
endpoint_auto_confirms = true
}