Skip to content

Commit ffcd082

Browse files
Rory Nolanclaude
andcommitted
feat: add optional source_account to lambda permissions
- Make both source_arn and source_account optional in invoke_function_permissions - Add comprehensive documentation for all permission fields - Update complete example to demonstrate source_account usage - Maintain backward compatibility with existing configurations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 18354c0 commit ffcd082

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

examples/complete/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ module "lambda" {
105105

106106
invoke_function_permissions = [
107107
{
108-
principal = "s3.amazonaws.com"
109-
source_arn = join("", aws_s3_bucket.example[*].arn)
108+
principal = "s3.amazonaws.com"
109+
source_arn = join("", aws_s3_bucket.example[*].arn)
110+
source_account = join("", data.aws_caller_identity.current[*].account_id)
110111
}
111112
]
112113

lambda-permissions.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
resource "aws_lambda_permission" "invoke_function" {
22
for_each = local.enabled ? { for i, permission in var.invoke_function_permissions : i => permission } : {}
33

4-
action = "lambda:InvokeFunction"
5-
function_name = aws_lambda_function.this[0].function_name
6-
principal = each.value.principal
7-
source_arn = each.value.source_arn
4+
action = "lambda:InvokeFunction"
5+
function_name = aws_lambda_function.this[0].function_name
6+
principal = each.value.principal
7+
source_arn = each.value.source_arn
8+
source_account = each.value.source_account
89
}

variables.tf

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,16 @@ variable "inline_iam_policy" {
248248

249249
variable "invoke_function_permissions" {
250250
type = list(object({
251-
principal = string
252-
source_arn = string
251+
principal = string
252+
source_arn = optional(string)
253+
source_account = optional(string)
253254
}))
254-
description = "Defines which external source(s) can invoke this function (action 'lambda:InvokeFunction'). Attributes map to those of https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission. NOTE: to keep things simple, we only expose a subset of said attributes. If a more complex configuration is needed, declare the necessary lambda permissions outside of this module"
255+
description = <<EOF
256+
Defines which external source(s) can invoke this function (action 'lambda:InvokeFunction'). Attributes map to those of https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission.
257+
- principal: The AWS service or account that will invoke the function
258+
- source_arn: (Optional) The ARN of the specific resource that will invoke the function
259+
- source_account: (Optional) The AWS account ID that is allowed to invoke the function. Used to restrict cross-account access when needed.
260+
NOTE: to keep things simple, we only expose a subset of said attributes. If a more complex configuration is needed, declare the necessary lambda permissions outside of this module
261+
EOF
255262
default = []
256263
}

0 commit comments

Comments
 (0)