Skip to content

Commit

Permalink
Introducing destinations in lambda function
Browse files Browse the repository at this point in the history
  • Loading branch information
ewastempel committed Dec 5, 2023
1 parent db5be11 commit 94ad4f1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ module "lambda" {
}
```
<!--- BEGIN_TF_DOCS --->
<!--- END_TF_DOCS --->

## Looking for issues?
If you're looking to raise an issue with this module, please create a new issue in the [Modernisation Platform repository](https://github.com/ministryofjustice/modernisation-platform/issues).
Expand Down Expand Up @@ -70,6 +68,7 @@ No modules.
| [aws_iam_role_policy_attachment.policy_arns](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [aws_iam_role_policy_attachment.policy_from_json](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [aws_lambda_function.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function) | resource |
| [aws_lambda_function_event_invoke_config.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function_event_invoke_config) | resource |
| [aws_lambda_permission.allowed_triggers](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource |
| [aws_iam_policy_document.assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.combined-assume-role-policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
Expand Down Expand Up @@ -97,6 +96,8 @@ No modules.
| <a name="input_reserved_concurrent_executions"></a> [reserved\_concurrent\_executions](#input\_reserved\_concurrent\_executions) | The amount of reserved concurrent executions for this Lambda Function. A value of 0 disables Lambda Function from being triggered and -1 removes any concurrency limitations. Defaults to Unreserved Concurrency Limits -1. | `number` | `-1` | no |
| <a name="input_role_description"></a> [role\_description](#input\_role\_description) | Description of IAM role to use for Lambda Function | `string` | `null` | no |
| <a name="input_role_name"></a> [role\_name](#input\_role\_name) | Name of IAM role to use for Lambda Function | `string` | `null` | no |
| <a name="input_sns_topic_on_failure"></a> [sns\_topic\_on\_failure](#input\_sns\_topic\_on\_failure) | A json policy document is being passed into the module | `string` | `""` | no |
| <a name="input_sns_topic_on_success"></a> [sns\_topic\_on\_success](#input\_sns\_topic\_on\_success) | A json policy document is being passed into the module | `string` | `""` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Common tags to be used by all resources | `map(string)` | n/a | yes |
| <a name="input_timeout"></a> [timeout](#input\_timeout) | The amount of time your Lambda Function has to run in seconds. | `number` | `3` | no |
| <a name="input_tracing_mode"></a> [tracing\_mode](#input\_tracing\_mode) | Tracing mode of the Lambda Function. Valid value can be either PassThrough or Active. | `string` | `null` | no |
Expand Down
22 changes: 21 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,24 @@ resource "aws_lambda_permission" "allowed_triggers" {
action = try(each.value.action, "lambda:InvokeFunction")
principal = try(each.value.principal, format("%s.amazonaws.com", try(each.value.service, "")))
source_arn = try(each.value.source_arn, null)
}
}

resource "aws_lambda_function_event_invoke_config" "this" {
count = var.sns_topic_on_success == "" && var.sns_topic_on_failure == "" ? 0 : 1
function_name = aws_lambda_function.this.function_name

destination_config {
dynamic "on_failure" {
for_each = var.sns_topic_on_failure != "" ? [1] : []
content {
destination = var.sns_topic_on_failure
}
}
dynamic "on_success" {
for_each = var.sns_topic_on_success != "" ? [1] : []
content {
destination = var.sns_topic_on_success
}
}
}
}
14 changes: 13 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ variable "tracing_mode" {
type = string
default = null
}

variable "tags" {
type = map(string)
description = "Common tags to be used by all resources"
}

variable "application_name" {
type = string
description = "Name of application"
Expand All @@ -120,9 +122,19 @@ variable "memory_size" {
}

variable "policy_json_attached" {

description = "A json policy document is being passed into the module"
type = bool
default = false
}

variable "sns_topic_on_failure" {
description = "A json policy document is being passed into the module"
type = string
default = ""
}

variable "sns_topic_on_success" {
description = "A json policy document is being passed into the module"
type = string
default = ""
}

0 comments on commit 94ad4f1

Please sign in to comment.