-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtopic.tf
70 lines (63 loc) · 2.14 KB
/
topic.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#
# Create an SNS Topic for receiving RDS Snapshot Events
#
resource "aws_sns_topic" "rdsSnapshotsEvents" {
name = "${local.prefix}rds-snapshots-creation${local.postfix}"
tags = merge({ Name = "${local.prefix}rds-snapshots-creation${local.postfix}" }, var.tags)
}
resource "aws_sns_topic" "exportMonitorNotifications" {
count = var.create_notifications_topic ? 1 : 0
name = "${local.prefix}rds-exports-monitor-notifications${local.postfix}"
tags = merge({ Name = "${local.prefix}rds-exports-monitor-notifications${local.postfix}" }, var.tags)
}
#
# Allow CloudWatch to publish events on the SNS Topics
#
resource "aws_sns_topic_policy" "default" {
arn = aws_sns_topic.rdsSnapshotsEvents.arn
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "events.amazonaws.com"
},
"Action": "SNS:Publish",
"Resource": "${aws_sns_topic.rdsSnapshotsEvents.arn}"
}
]
}
POLICY
}
#
# Subscribe Lambdas to the Topics
#
resource "aws_sns_topic_subscription" "lambdaRdsSnapshotToS3Exporter" {
topic_arn = aws_sns_topic.rdsSnapshotsEvents.arn
protocol = "lambda"
endpoint = module.start_export_task_lambda.lambda_function_arn
}
resource "aws_sns_topic_subscription" "lambdaRdsSnapshotToS3Monitor" {
topic_arn = aws_sns_topic.rdsSnapshotsEvents.arn
protocol = "lambda"
endpoint = module.monitor_export_task_lambda.lambda_function_arn
}
#
# Allow SNS Topics to trigger Lambda
#
resource "aws_lambda_permission" "snsCanTriggerStartExportTask" {
statement_id = "AllowExecutionFromSNS"
action = "lambda:InvokeFunction"
function_name = module.start_export_task_lambda.lambda_function_name
principal = "sns.amazonaws.com"
source_arn = aws_sns_topic.rdsSnapshotsEvents.arn
}
resource "aws_lambda_permission" "snsCanTriggerMonitorExportTask" {
statement_id = "AllowExecutionFromSNS"
action = "lambda:InvokeFunction"
function_name = module.monitor_export_task_lambda.lambda_function_name
principal = "sns.amazonaws.com"
source_arn = aws_sns_topic.rdsSnapshotsEvents.arn
}