-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
50 lines (42 loc) · 1.2 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
43
44
45
46
47
48
49
50
module "sns_topic" {
source = "terraform-aws-modules/sns/aws"
version = "~> 2.0"
name = "Codepipeline-${var.name}-failures"
display_name = "Codepipeline ${var.name}"
tags = var.tags
}
resource "aws_cloudwatch_event_rule" "rule" {
name = "Codepipeline-${var.name}-failures"
description = "Codepipeline-${var.name}-failures"
event_pattern = <<PATTERN
{
"source": [ "aws.codepipeline" ],
"detail-type": [ "CodePipeline Action Execution State Change" ],
"resources":[ "${var.codepipeline_arn}" ],
"detail": {
"state": [ "FAILED" ]
}
}
PATTERN
tags = var.tags
}
resource "aws_cloudwatch_event_target" "sns" {
rule = aws_cloudwatch_event_rule.rule.name
target_id = "SendToSNS"
arn = module.sns_topic.this_sns_topic_arn
}
resource "aws_sns_topic_policy" "default" {
arn = module.sns_topic.this_sns_topic_arn
policy = data.aws_iam_policy_document.sns_topic_policy.json
}
data "aws_iam_policy_document" "sns_topic_policy" {
statement {
effect = "Allow"
actions = ["SNS:Publish"]
principals {
type = "Service"
identifiers = ["events.amazonaws.com"]
}
resources = [module.sns_topic.this_sns_topic_arn]
}
}