File tree Expand file tree Collapse file tree 2 files changed +44
-3
lines changed
Expand file tree Collapse file tree 2 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ resource "aws_lambda_function" "auto_tagging" {
1717
1818 environment {
1919 variables = {
20- UNWRAP_SNS_ENVELOPE = var.sns_topic_arn == " " ? false : true
20+ UNWRAP_SNS_ENVELOPE = var.sns_topic_arn == " " ? false : true
2121 }
2222 }
2323
@@ -37,7 +37,7 @@ resource "aws_sqs_queue" "auto_tagging" {
3737 count = var. enable_auto_tagging == true ? 1 : 0
3838
3939 name = " ${ var . sqs_queue_name } -auto_tagging"
40- policy = data. aws_iam_policy_document . auto_tagging_sqs [0 ]. json
40+ policy = var . sns_topic_arn == " " ? data. aws_iam_policy_document . auto_tagging_sqs [ 0 ] . json : data . aws_iam_policy_document . auto_tagging_sns [0 ]. json
4141 visibility_timeout_seconds = var. sqs_visibility_timeout_seconds
4242 delay_seconds = var. sqs_delay_seconds
4343
@@ -98,6 +98,26 @@ data "aws_iam_policy_document" "auto_tagging_sqs" {
9898 }
9999}
100100
101+ data "aws_iam_policy_document" "auto_tagging_sns" {
102+ count = var. sns_topic_arn == " " ? 0 : 1
103+
104+ statement {
105+ effect = " Allow"
106+ principals {
107+ type = " "
108+ identifiers = [" " ]
109+ }
110+ actions = [" sqs:SendMessage" ]
111+ resources = [" arn:aws:sqs:*:*:${ var . sqs_queue_name } -auto_tagging" , ]
112+ condition {
113+ test = " ArnEquals"
114+ variable = " aws:SourceArn"
115+ values = [var . sns_topic_arn ]
116+ }
117+ }
118+
119+ }
120+
101121data "aws_iam_policy_document" "auto_tagging_sqs_dl" {
102122 count = var. enable_auto_tagging == true ? 1 : 0
103123
Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ resource "aws_lambda_event_source_mapping" "this_lambda_events" {
170170resource "aws_sqs_queue" "this_sqs" {
171171 count = local. enable_group_events ? 0 : 1
172172 name = var. sqs_queue_name
173- policy = data. aws_iam_policy_document . this_sqs_queue_policy_data . json
173+ policy = var . sns_topic_arn == " " ? data. aws_iam_policy_document . this_sqs_queue_policy_data . json : data . aws_iam_policy_document . this_sns_to_sqs [ 0 ] . json
174174 visibility_timeout_seconds = var. sqs_visibility_timeout_seconds
175175 delay_seconds = var. sqs_delay_seconds
176176 redrive_policy = jsonencode ({
@@ -312,6 +312,27 @@ data "aws_iam_policy_document" "this_sqs_queue_policy_data" {
312312 }
313313}
314314
315+ data "aws_iam_policy_document" "this_sns_to_sqs" {
316+ count = var. sns_topic_arn == " " ? 0 : 1
317+
318+ statement {
319+ effect = " Allow"
320+ principals {
321+ type = " "
322+ identifiers = [" " ]
323+ }
324+ actions = [" sqs:SendMessage" ]
325+ resources = local. enable_group_events ? [" arn:aws:sqs:*:*:${ var . sqs_group_queue_name } " , " arn:aws:sqs:*:*:${ var . sqs_fifo_queue_name } .fifo" ] : [" arn:aws:sqs:*:*:${ var . sqs_queue_name } " ]
326+ condition {
327+ test = " ArnEquals"
328+ variable = " aws:SourceArn"
329+ values = [var . sns_topic_arn ]
330+ }
331+ }
332+
333+ }
334+
335+
315336data "aws_iam_policy_document" "this_dead_letter_queue_policy" {
316337 statement {
317338 sid = " DLQSendMessages"
You can’t perform that action at this time.
0 commit comments