-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.tf
50 lines (43 loc) · 1.36 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
data "aws_iam_policy_document" "sqs_from_cloudwatch_event" {
statement {
sid = "AllowQueueFromCloudwatchEvent"
actions = ["sqs:SendMessage"]
principals {
type = "Service"
identifiers = ["events.amazonaws.com"]
}
resources = [aws_sqs_queue.cron_sqs.arn]
condition {
test = "ArnEquals"
variable = "aws:SourceArn"
values = [aws_cloudwatch_event_rule.cron_sqs.arn]
}
}
}
resource "aws_sqs_queue" "cron_sqs_dlq" {
name = "${var.name}-dlq"
tags = var.tags
}
resource "aws_sqs_queue" "cron_sqs" {
name = var.name
visibility_timeout_seconds = var.sqs_visibility_timeout_seconds
tags = var.tags
redrive_policy = jsonencode({
deadLetterTargetArn = aws_sqs_queue.cron_sqs_dlq.arn
maxReceiveCount = var.sqs_retry_count
})
}
resource "aws_cloudwatch_event_rule" "cron_sqs" {
name = var.name
description = "Triggers SQS"
schedule_expression = var.cloudwatch_event_rule_schedule_expression
tags = var.tags
}
resource "aws_cloudwatch_event_target" "cron_sqs" {
rule = aws_cloudwatch_event_rule.cron_sqs.name
arn = aws_sqs_queue.cron_sqs.arn
}
resource "aws_sqs_queue_policy" "cron_sqs" {
queue_url = aws_sqs_queue.cron_sqs.id
policy = data.aws_iam_policy_document.sqs_from_cloudwatch_event.json
}