automated imports.
This commit is contained in:
89
terraform/events.tf
Normal file
89
terraform/events.tf
Normal file
@@ -0,0 +1,89 @@
|
||||
resource "aws_sns_topic" "yodlee_topic" {
|
||||
name = "events-yodlee-${var.stage}"
|
||||
policy = <<EOF
|
||||
{
|
||||
"Version": "2008-10-17",
|
||||
"Id": "__default_policy_ID",
|
||||
"Statement": [
|
||||
{
|
||||
"Sid": "__default_statement_ID",
|
||||
"Effect": "Allow",
|
||||
"Principal": {
|
||||
"AWS": "*"
|
||||
},
|
||||
"Action": [
|
||||
"SNS:Publish",
|
||||
"SNS:RemovePermission",
|
||||
"SNS:SetTopicAttributes",
|
||||
"SNS:DeleteTopic",
|
||||
"SNS:ListSubscriptionsByTopic",
|
||||
"SNS:GetTopicAttributes",
|
||||
"SNS:Receive",
|
||||
"SNS:AddPermission",
|
||||
"SNS:Subscribe"
|
||||
],
|
||||
"Resource": "arn:aws:sns:us-east-1:679918342773:yodlee",
|
||||
"Condition": {
|
||||
"StringEquals": {
|
||||
"AWS:SourceOwner": "679918342773"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Sid": "__console_pub_0",
|
||||
"Effect": "Allow",
|
||||
"Principal": {
|
||||
"AWS": "*"
|
||||
},
|
||||
"Action": "SNS:Publish",
|
||||
"Resource": "arn:aws:sns:us-east-1:679918342773:yodlee"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
resource "aws_sns_topic_subscription" "trigger_yodlee_import" {
|
||||
topic_arn = "${aws_sns_topic.yodlee_topic.arn}"
|
||||
protocol = "https"
|
||||
endpoint = "${var.base_url}/api/events/yodlee-import"
|
||||
endpoint_auto_confirms = true
|
||||
}
|
||||
|
||||
resource "aws_cloudwatch_event_rule" "yodlee_rule" {
|
||||
name = "schedule-yodlee-import-${var.stage}"
|
||||
|
||||
schedule_expression = "rate(4 hours)"
|
||||
role_arn = "${aws_iam_role.yodlee_role.arn}"
|
||||
}
|
||||
|
||||
resource "aws_cloudwatch_event_target" "yodlee_sns_target" {
|
||||
rule = "${aws_cloudwatch_event_rule.yodlee_rule.name}"
|
||||
target_id = "SendToSNS"
|
||||
arn = "${aws_sns_topic.yodlee_topic.arn}"
|
||||
}
|
||||
|
||||
resource "aws_iam_role" "yodlee_role" {
|
||||
name = "yodlee-role-${var.stage}"
|
||||
assume_role_policy = <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Action": "sts:AssumeRole",
|
||||
"Principal": {
|
||||
"Service": "events.amazonaws.com"
|
||||
},
|
||||
"Effect": "Allow",
|
||||
"Sid": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "allow_schedule_yodlee" {
|
||||
role = "${aws_iam_role.yodlee_role.name}"
|
||||
policy_arn = "arn:aws:iam::aws:policy/AmazonSNSFullAccess"
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user