-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
67 lines (48 loc) · 1.63 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
resource "aws_sqs_queue" "this" {
name = var.is_fifo ? "${var.name}.fifo" : var.name
fifo_queue = var.is_fifo
visibility_timeout_seconds = var.visibility_timeout
sqs_managed_sse_enabled = true
receive_wait_time_seconds = var.long_poll_time_seconds
message_retention_seconds = var.message_retention_seconds
redrive_policy = jsonencode({
deadLetterTargetArn = aws_sqs_queue.dlq.arn
maxReceiveCount = var.max_tries_before_sending_to_dlq
})
}
resource "aws_sqs_queue" "dlq" {
name = var.is_fifo ? "${var.name}-dlq.fifo" : "${var.name}-dlq"
fifo_queue = var.is_fifo
message_retention_seconds = var.message_retention_seconds_dlq
}
data "aws_iam_policy_document" "allow_sns_recieve" {
count = length(var.subscribe_sns_arns) == 0 ? 0 : 1
statement {
effect = "Allow"
principals {
type = "Service"
identifiers = ["sns.amazonaws.com"]
}
actions = ["sqs:SendMessage"]
resources = [aws_sqs_queue.this.arn]
condition {
test = "ArnEquals"
variable = "aws:SourceArn"
values = var.subscribe_sns_arns
}
}
}
resource "aws_sqs_queue_policy" "allow_sns_recieve" {
count = length(var.subscribe_sns_arns) == 0 ? 0 : 1
queue_url = aws_sqs_queue.this.id
policy = data.aws_iam_policy_document.allow_sns_recieve[0].json
}
resource "aws_sns_topic_subscription" "this" {
for_each = toset(var.subscribe_sns_arns)
topic_arn = each.value
protocol = "sqs"
endpoint = aws_sqs_queue.this.arn
raw_message_delivery = var.raw_message_delivery
filter_policy = var.filter_policy
filter_policy_scope = var.filter_policy_scope
}