Skip to content

Commit

Permalink
review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-hoyle committed Jul 8, 2024
1 parent c9b44ac commit e8d6480
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions lambda/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
locals {
sqs_mapping_without_ignore_enabled = { for mapping in var.lambda_sqs_queue_mappings : (mapping.sqs_queue_arn) => mapping.sqs_queue_concurrency if mapping.ignore_enabled_status == false }
sqs_mapping_ignore_enabled = { for mapping in var.lambda_sqs_queue_mappings : (mapping.sqs_queue_arn) => mapping.sqs_queue_concurrency if mapping.ignore_enabled_status == true }
lambda = var.use_image ? aws_lambda_function.lambda_function_ecr[0] : aws_lambda_function.lambda_function[0]
lambda_arn = local.lambda.arn
lambda_name = local.lambda.function_name
}
resource "aws_lambda_function" "lambda_function" {
count = var.use_image ? 0 : 1
Expand Down Expand Up @@ -78,7 +81,7 @@ resource "aws_lambda_function" "lambda_function_ecr" {


resource "aws_cloudwatch_log_group" "lambda_log_group" {
name = var.use_image ? "/aws/lambda/${aws_lambda_function.lambda_function_ecr[0].function_name}" : "/aws/lambda/${aws_lambda_function.lambda_function[0].function_name}"
name = "/aws/lambda/${local.lambda_name}"
retention_in_days = var.log_retention
kms_key_id = var.log_group_kms_key_arn
tags = var.tags
Expand All @@ -100,7 +103,7 @@ resource "aws_kms_ciphertext" "encrypted_environment_variables" {
resource "aws_lambda_event_source_mapping" "sqs_queue_mappings" {
for_each = local.sqs_mapping_without_ignore_enabled
event_source_arn = each.key
function_name = var.use_image ? aws_lambda_function.lambda_function_ecr.*.arn[0] : aws_lambda_function.lambda_function.*.arn[0]
function_name = local.lambda_arn
batch_size = var.sqs_queue_mapping_batch_size
maximum_batching_window_in_seconds = var.sqs_queue_batching_window
dynamic "scaling_config" {
Expand All @@ -114,7 +117,7 @@ resource "aws_lambda_event_source_mapping" "sqs_queue_mappings" {
resource "aws_lambda_event_source_mapping" "sqs_queue_mappings_ignore_enabled" {
for_each = local.sqs_mapping_ignore_enabled
event_source_arn = each.key
function_name = var.use_image ? aws_lambda_function.lambda_function_ecr.*.arn[0] : aws_lambda_function.lambda_function.*.arn[0]
function_name = local.lambda_arn
batch_size = var.sqs_queue_mapping_batch_size
maximum_batching_window_in_seconds = var.sqs_queue_batching_window
dynamic "scaling_config" {
Expand All @@ -132,7 +135,7 @@ resource "aws_lambda_permission" "lambda_permissions" {
for_each = var.lambda_invoke_permissions
statement_id = "AllowExecutionFrom${title(split(".", each.key)[0])}"
action = "lambda:InvokeFunction"
function_name = var.use_image ? aws_lambda_function.lambda_function_ecr[0].function_name : aws_lambda_function.lambda_function[0].function_name
function_name = local.lambda_name
principal = each.key
source_arn = each.value
}
Expand Down
2 changes: 1 addition & 1 deletion lambda/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
output "lambda_arn" {
value = var.use_image ? aws_lambda_function.lambda_function_ecr[0].arn : aws_lambda_function.lambda_function[0].arn
value = local.lambda_arn
}

output "lambda_role_arn" {
Expand Down

0 comments on commit e8d6480

Please sign in to comment.