Skip to content

Commit 5b71671

Browse files
maxrabinMax Rabin
and
Max Rabin
authored
feat: Add variable create_lambda_permission in notification module (#302)
Co-authored-by: Max Rabin <[email protected]>
1 parent e23dd4f commit 5b71671

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

modules/notification/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ No modules.
4040
| <a name="input_bucket"></a> [bucket](#input\_bucket) | Name of S3 bucket to use | `string` | `""` | no |
4141
| <a name="input_bucket_arn"></a> [bucket\_arn](#input\_bucket\_arn) | ARN of S3 bucket to use in policies | `string` | `null` | no |
4242
| <a name="input_create"></a> [create](#input\_create) | Whether to create this resource or not? | `bool` | `true` | no |
43+
| <a name="input_create_lambda_permission"></a> [create\_lambda\_permission](#input\_create\_lambda\_permission) | Whether to create Lambda permissions or not? | `bool` | `true` | no |
4344
| <a name="input_create_sns_policy"></a> [create\_sns\_policy](#input\_create\_sns\_policy) | Whether to create a policy for SNS permissions or not? | `bool` | `true` | no |
4445
| <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 |
4546
| <a name="input_eventbridge"></a> [eventbridge](#input\_eventbridge) | Whether to enable Amazon EventBridge notifications | `bool` | `null` | no |

modules/notification/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ resource "aws_s3_bucket_notification" "this" {
6060

6161
# Lambda
6262
resource "aws_lambda_permission" "allow" {
63-
for_each = var.lambda_notifications
63+
for_each = { for k, v in var.lambda_notifications : k => v if var.create_lambda_permission }
6464

6565
statement_id_prefix = "AllowLambdaS3BucketNotification-"
6666
action = "lambda:InvokeFunction"

modules/notification/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ variable "create_sqs_policy" {
1616
default = true
1717
}
1818

19+
variable "create_lambda_permission" {
20+
description = "Whether to create Lambda permissions or not?"
21+
type = bool
22+
default = true
23+
}
24+
1925
variable "bucket" {
2026
description = "Name of S3 bucket to use"
2127
type = string

wrappers/notification/main.tf

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ module "wrapper" {
33

44
for_each = var.items
55

6-
bucket = try(each.value.bucket, var.defaults.bucket, "")
7-
bucket_arn = try(each.value.bucket_arn, var.defaults.bucket_arn, null)
8-
create = try(each.value.create, var.defaults.create, true)
9-
create_sns_policy = try(each.value.create_sns_policy, var.defaults.create_sns_policy, true)
10-
create_sqs_policy = try(each.value.create_sqs_policy, var.defaults.create_sqs_policy, true)
11-
eventbridge = try(each.value.eventbridge, var.defaults.eventbridge, null)
12-
lambda_notifications = try(each.value.lambda_notifications, var.defaults.lambda_notifications, {})
13-
sns_notifications = try(each.value.sns_notifications, var.defaults.sns_notifications, {})
14-
sqs_notifications = try(each.value.sqs_notifications, var.defaults.sqs_notifications, {})
6+
bucket = try(each.value.bucket, var.defaults.bucket, "")
7+
bucket_arn = try(each.value.bucket_arn, var.defaults.bucket_arn, null)
8+
create = try(each.value.create, var.defaults.create, true)
9+
create_lambda_permission = try(each.value.create_lambda_permission, var.defaults.create_lambda_permission, true)
10+
create_sns_policy = try(each.value.create_sns_policy, var.defaults.create_sns_policy, true)
11+
create_sqs_policy = try(each.value.create_sqs_policy, var.defaults.create_sqs_policy, true)
12+
eventbridge = try(each.value.eventbridge, var.defaults.eventbridge, null)
13+
lambda_notifications = try(each.value.lambda_notifications, var.defaults.lambda_notifications, {})
14+
sns_notifications = try(each.value.sns_notifications, var.defaults.sns_notifications, {})
15+
sqs_notifications = try(each.value.sqs_notifications, var.defaults.sqs_notifications, {})
1516
}

0 commit comments

Comments
 (0)