From 1ec45f821fab7e2b2ef5d1e8cb7eaf1b8e7dff47 Mon Sep 17 00:00:00 2001 From: jacobgill1 Date: Thu, 16 May 2024 15:26:55 +0100 Subject: [PATCH] Add advanced lambda logging options --- locals.tf | 4 ++++ main.tf | 4 ++++ modules/opennext-lambda/lambda.tf | 11 +++++++++++ modules/opennext-lambda/variables.tf | 10 ++++++++++ variables.tf | 24 ++++++++++++++++++++++++ 5 files changed, 53 insertions(+) diff --git a/locals.tf b/locals.tf index 6099b7d..4d2f608 100644 --- a/locals.tf +++ b/locals.tf @@ -79,6 +79,7 @@ locals { dead_letter_config = try(var.server_options.function.dead_letter_config, null) reserved_concurrent_executions = coalesce(try(var.server_options.function.reserved_concurrent_executions, null), 10) code_signing_config = try(var.server_options.function.code_signing_config, null) + logging_config = try(var.server_options.function.logging_config, null) } log_group = { @@ -141,6 +142,7 @@ locals { dead_letter_config = try(var.image_optimization_options.function.dead_letter_config, null) reserved_concurrent_executions = coalesce(try(var.image_optimization_options.function.reserved_concurrent_executions, null), 3) code_signing_config = try(var.image_optimization_options.function.code_signing_config, null) + logging_config = try(var.image_optimization_options.function.logging_config, null) } log_group = { @@ -191,6 +193,7 @@ locals { dead_letter_config = try(var.revalidation_options.function.dead_letter_config, null) reserved_concurrent_executions = coalesce(try(var.revalidation_options.function.reserved_concurrent_executions, null), 3) code_signing_config = try(var.revalidation_options.function.code_signing_config, null) + logging_config = try(var.revalidation_options.function.logging_config, null) } log_group = { @@ -242,6 +245,7 @@ locals { dead_letter_config = try(var.warmer_options.function.dead_letter_config, null) reserved_concurrent_executions = coalesce(try(var.warmer_options.function.reserved_concurrent_executions, null), 3) code_signing_config = try(var.warmer_options.function.code_signing_config, null) + logging_config = try(var.warmer_options.function.logging_config, null) } log_group = { diff --git a/main.tf b/main.tf index d3e732c..cb9f961 100644 --- a/main.tf +++ b/main.tf @@ -54,6 +54,7 @@ module "server_function" { reserved_concurrent_executions = local.server_options.function.reserved_concurrent_executions code_signing_config = local.server_options.function.code_signing_config log_group = local.server_options.log_group + logging_config = local.server_options.logging_config source_dir = local.server_options.package.source_dir @@ -91,6 +92,7 @@ module "image_optimization_function" { reserved_concurrent_executions = local.image_optimization_options.function.reserved_concurrent_executions code_signing_config = local.image_optimization_options.function.code_signing_config log_group = local.image_optimization_options.log_group + logging_config = local.image_optimization_options.logging_config source_dir = local.image_optimization_options.package.source_dir output_dir = local.image_optimization_options.package.output_dir @@ -126,6 +128,7 @@ module "revalidation_function" { reserved_concurrent_executions = local.revalidation_options.function.reserved_concurrent_executions code_signing_config = local.revalidation_options.function.code_signing_config log_group = local.revalidation_options.log_group + logging_config = local.revalidation_options.logging_config source_dir = local.revalidation_options.package.source_dir output_dir = local.revalidation_options.package.output_dir @@ -177,6 +180,7 @@ module "warmer_function" { reserved_concurrent_executions = local.warmer_options.function.reserved_concurrent_executions code_signing_config = local.warmer_options.function.code_signing_config log_group = local.warmer_options.log_group + logging_config = local.warmer_options.logging_config source_dir = local.warmer_options.package.source_dir output_dir = local.warmer_options.package.output_dir diff --git a/modules/opennext-lambda/lambda.tf b/modules/opennext-lambda/lambda.tf index d4afb07..ab29a2d 100644 --- a/modules/opennext-lambda/lambda.tf +++ b/modules/opennext-lambda/lambda.tf @@ -60,6 +60,17 @@ resource "aws_lambda_function" "function" { target_arn = var.dead_letter_config.target_arn } } + + dynamic "logging_config" { + for_each = var.logging_config != null ? [true] : [] + + content { + log_format = var.logging_config.log_format + log_group = try(var.logging_config.log_group, null) + application_log_level = try(var.logging_config.application_log_level, null) + system_log_level = try(var.logging_config.system_log_level, null) + } + } } resource "aws_lambda_function_url" "function_url" { diff --git a/modules/opennext-lambda/variables.tf b/modules/opennext-lambda/variables.tf index 5afac3e..5217102 100644 --- a/modules/opennext-lambda/variables.tf +++ b/modules/opennext-lambda/variables.tf @@ -135,6 +135,16 @@ variable "reserved_concurrent_executions" { default = 10 } +variable "logging_config" { + description = "Advanced Logging Configuration for the Lambda Function" + default = null + type = object({ + log_format = string + log_group = optional(string) + application_log_level = optional(string) + system_log_level = optional(string) + }) +} /** * Lambda Networking diff --git a/variables.tf b/variables.tf index 6cebad7..aa59d48 100644 --- a/variables.tf +++ b/variables.tf @@ -86,6 +86,12 @@ variable "server_options" { signing_profile_version_arns = list(string) untrusted_artfact_on_deployment = optional(string) })) + logging_config = optional(object({ + log_format = string + log_group = optional(string) + application_log_level = optional(string) + system_log_level = optional(string) + })) })) environment_variables = optional(map(string)) iam_policy = optional(list(object({ @@ -152,6 +158,12 @@ variable "image_optimization_options" { signing_profile_version_arns = list(string) untrusted_artfact_on_deployment = optional(string) })) + logging_config = optional(object({ + log_format = string + log_group = optional(string) + application_log_level = optional(string) + system_log_level = optional(string) + })) })) environment_variables = optional(map(string)) iam_policy = optional(list(object({ @@ -218,6 +230,12 @@ variable "revalidation_options" { signing_profile_version_arns = list(string) untrusted_artfact_on_deployment = optional(string) })) + logging_config = optional(object({ + log_format = string + log_group = optional(string) + application_log_level = optional(string) + system_log_level = optional(string) + })) })) environment_variables = optional(map(string)) iam_policy = optional(list(object({ @@ -284,6 +302,12 @@ variable "warmer_options" { signing_profile_version_arns = list(string) untrusted_artfact_on_deployment = optional(string) })) + logging_config = optional(object({ + log_format = string + log_group = optional(string) + application_log_level = optional(string) + system_log_level = optional(string) + })) })) environment_variables = optional(map(string)) iam_policy = optional(list(object({