Skip to content

Commit 2eee676

Browse files
authored
Merge pull request #86 from NHSDigital/feature/CCM-10464_configure-lambda-resource-policies
CCM-10464: add configurable lambda resource policies
2 parents 6db6311 + 2a393ad commit 2eee676

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

infrastructure/modules/lambda/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
| <a name="input_log_subscription_lambda_create_permission"></a> [log\_subscription\_lambda\_create\_permission](#input\_log\_subscription\_lambda\_create\_permission) | Whether to create a permission for the log forwarder. Set to false if using a generic one. | `bool` | `true` | no |
4242
| <a name="input_log_subscription_role_arn"></a> [log\_subscription\_role\_arn](#input\_log\_subscription\_role\_arn) | The ARN of the IAM role to use for the log subscription filter | `string` | `""` | no |
4343
| <a name="input_memory"></a> [memory](#input\_memory) | The amount of memory to apply to the created Lambda | `number` | n/a | yes |
44+
| <a name="input_permission_statements"></a> [permission\_statements](#input\_permission\_statements) | Statements giving an external source permission to invoke the Lambda function | <pre>list(object({<br/> action = optional(string)<br/> principal = string<br/> source_arn = optional(string)<br/> source_account = optional(string)<br/> statement_id = string<br/> }))</pre> | `[]` | no |
4445
| <a name="input_project"></a> [project](#input\_project) | The name of the tfscaffold project | `string` | n/a | yes |
4546
| <a name="input_region"></a> [region](#input\_region) | The AWS Region | `string` | n/a | yes |
4647
| <a name="input_runtime"></a> [runtime](#input\_runtime) | The runtime to use for the lambda function | `string` | n/a | yes |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resource "aws_lambda_permission" "main" {
2+
for_each = { for statement in var.permission_statements : statement.statement_id => statement }
3+
4+
action = try(each.value.action, "lambda:InvokeFunction")
5+
function_name = local.csi
6+
principal = each.value.principal
7+
source_arn = try(each.value.source_arn, null)
8+
source_account = try(each.value.source_account, null)
9+
statement_id = each.value.statement_id
10+
}

infrastructure/modules/lambda/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,15 @@ variable "log_subscription_role_arn" {
236236
description = "The ARN of the IAM role to use for the log subscription filter"
237237
default = ""
238238
}
239+
240+
variable "permission_statements" {
241+
type = list(object({
242+
action = optional(string)
243+
principal = string
244+
source_arn = optional(string)
245+
source_account = optional(string)
246+
statement_id = string
247+
}))
248+
description = "Statements giving an external source permission to invoke the Lambda function"
249+
default = []
250+
}

0 commit comments

Comments
 (0)