diff --git a/modules/notification/README.md b/modules/notification/README.md index 364305b..99879d2 100644 --- a/modules/notification/README.md +++ b/modules/notification/README.md @@ -45,6 +45,7 @@ No modules. | [create\_sqs\_policy](#input\_create\_sqs\_policy) | Whether to create a policy for SQS permissions or not? | `bool` | `true` | no | | [eventbridge](#input\_eventbridge) | Whether to enable Amazon EventBridge notifications | `bool` | `null` | no | | [lambda\_notifications](#input\_lambda\_notifications) | Map of S3 bucket notifications to Lambda function | `any` | `{}` | no | +| [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the region set in the provider configuration | `string` | `null` | no | | [sns\_notifications](#input\_sns\_notifications) | Map of S3 bucket notifications to SNS topic | `any` | `{}` | no | | [sqs\_notifications](#input\_sqs\_notifications) | Map of S3 bucket notifications to SQS queue | `any` | `{}` | no | diff --git a/modules/notification/main.tf b/modules/notification/main.tf index 6eb6395..e05e77d 100644 --- a/modules/notification/main.tf +++ b/modules/notification/main.tf @@ -13,6 +13,8 @@ resource "aws_s3_bucket_notification" "this" { bucket = var.bucket + region = var.region + eventbridge = var.eventbridge dynamic "lambda_function" { @@ -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 @@ -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 } @@ -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 } diff --git a/modules/notification/variables.tf b/modules/notification/variables.tf index a534368..5aa81a1 100644 --- a/modules/notification/variables.tf +++ b/modules/notification/variables.tf @@ -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 diff --git a/wrappers/notification/main.tf b/wrappers/notification/main.tf index 9e54f2d..82032bb 100644 --- a/wrappers/notification/main.tf +++ b/wrappers/notification/main.tf @@ -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, {}) }