Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/notification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ No modules.
| <a name="input_create_sqs_policy"></a> [create\_sqs\_policy](#input\_create\_sqs\_policy) | Whether to create a policy for SQS permissions or not? | `bool` | `true` | no |
| <a name="input_eventbridge"></a> [eventbridge](#input\_eventbridge) | Whether to enable Amazon EventBridge notifications | `bool` | `null` | no |
| <a name="input_lambda_notifications"></a> [lambda\_notifications](#input\_lambda\_notifications) | Map of S3 bucket notifications to Lambda function | `any` | `{}` | no |
| <a name="input_region"></a> [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the region set in the provider configuration | `string` | `null` | no |
| <a name="input_sns_notifications"></a> [sns\_notifications](#input\_sns\_notifications) | Map of S3 bucket notifications to SNS topic | `any` | `{}` | no |
| <a name="input_sqs_notifications"></a> [sqs\_notifications](#input\_sqs\_notifications) | Map of S3 bucket notifications to SQS queue | `any` | `{}` | no |

Expand Down
8 changes: 8 additions & 0 deletions modules/notification/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ resource "aws_s3_bucket_notification" "this" {

bucket = var.bucket

region = var.region

eventbridge = var.eventbridge

dynamic "lambda_function" {
Expand Down Expand Up @@ -62,6 +64,8 @@ resource "aws_s3_bucket_notification" "this" {
resource "aws_lambda_permission" "allow" {
for_each = { for k, v in var.lambda_notifications : k => v if var.create_lambda_permission }

region = var.region

statement_id_prefix = "AllowLambdaS3BucketNotification-"
action = "lambda:InvokeFunction"
function_name = each.value.function_name
Expand Down Expand Up @@ -110,6 +114,8 @@ data "aws_iam_policy_document" "sqs" {
resource "aws_sqs_queue_policy" "allow" {
for_each = { for k, v in var.sqs_notifications : k => v if var.create_sqs_policy }

region = var.region

queue_url = try(each.value.queue_id, local.queue_ids[each.key], null)
policy = data.aws_iam_policy_document.sqs[each.key].json
}
Expand Down Expand Up @@ -145,6 +151,8 @@ data "aws_iam_policy_document" "sns" {
resource "aws_sns_topic_policy" "allow" {
for_each = { for k, v in var.sns_notifications : k => v if var.create_sns_policy }

region = var.region

arn = each.value.topic_arn
policy = data.aws_iam_policy_document.sns[each.key].json
}
6 changes: 6 additions & 0 deletions modules/notification/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ variable "create_lambda_permission" {
default = true
}

variable "region" {
description = "Region where the resource(s) will be managed. Defaults to the region set in the provider configuration"
type = string
default = null
}

variable "bucket" {
description = "Name of S3 bucket to use"
type = string
Expand Down
1 change: 1 addition & 0 deletions wrappers/notification/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module "wrapper" {
create_sqs_policy = try(each.value.create_sqs_policy, var.defaults.create_sqs_policy, true)
eventbridge = try(each.value.eventbridge, var.defaults.eventbridge, null)
lambda_notifications = try(each.value.lambda_notifications, var.defaults.lambda_notifications, {})
region = try(each.value.region, var.defaults.region, null)
sns_notifications = try(each.value.sns_notifications, var.defaults.sns_notifications, {})
sqs_notifications = try(each.value.sqs_notifications, var.defaults.sqs_notifications, {})
}