Skip to content
Open
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
5 changes: 3 additions & 2 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ module "lambda" {

invoke_function_permissions = [
{
principal = "s3.amazonaws.com"
source_arn = join("", aws_s3_bucket.example[*].arn)
principal = "s3.amazonaws.com"
source_arn = join("", aws_s3_bucket.example[*].arn)
source_account = join("", data.aws_caller_identity.current[*].account_id)
}
]

Expand Down
2 changes: 1 addition & 1 deletion examples/complete/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 0.14"
required_version = ">= 1.4"

required_providers {
aws = {
Expand Down
2 changes: 1 addition & 1 deletion examples/docker-image/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 0.14"
required_version = ">= 1.4"

required_providers {
aws = {
Expand Down
9 changes: 5 additions & 4 deletions lambda-permissions.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
resource "aws_lambda_permission" "invoke_function" {
for_each = local.enabled ? { for i, permission in var.invoke_function_permissions : i => permission } : {}

action = "lambda:InvokeFunction"
function_name = aws_lambda_function.this[0].function_name
principal = each.value.principal
source_arn = each.value.source_arn
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.this[0].function_name
principal = each.value.principal
source_arn = each.value.source_arn
source_account = each.value.source_account
}
13 changes: 10 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,16 @@ variable "inline_iam_policy" {

variable "invoke_function_permissions" {
type = list(object({
principal = string
source_arn = string
principal = string
source_arn = optional(string)
source_account = optional(string)
}))
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"
description = <<EOF
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.
- principal: The AWS service or account that will invoke the function
- source_arn: (Optional) The ARN of the specific resource that will invoke the function
- source_account: (Optional) The AWS account ID that is allowed to invoke the function. Used to restrict cross-account access when needed. This must be specified to satisfy the config rule [lambda-function-public-access-prohibited](https://docs.aws.amazon.com/config/latest/developerguide/lambda-function-public-access-prohibited.html).
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
EOF
default = []
}