Skip to content
Merged
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
10 changes: 7 additions & 3 deletions lambda-function/cloudwatch.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
locals {
log_group_name = "/aws/lambda/${var.name}"
}

resource "aws_cloudwatch_log_group" "logs" {
name = "${var.name}-logs"
name = local.log_group_name
log_group_class = "STANDARD"
retention_in_days = var.cloudwatch.retention_in_days
retention_in_days = var.logs.retention_in_days
tags = var.tags
}
}
4 changes: 2 additions & 2 deletions lambda-function/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ data "archive_file" "func" {
type = "zip"
source_dir = var.src
output_path = local.output_path
depends_on = [null_resource.create_build_dir]
}
depends_on = [null_resource.create_build_dir]
}
18 changes: 18 additions & 0 deletions lambda-function/iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "aws_iam_role_policy" "logging" {
name = "allow-cloudwatch-logs-access"
role = split("/", var.role_arn)[1]
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Action = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
Resource = "${aws_cloudwatch_log_group.logs.arn}:*"
}
]
})
}
10 changes: 5 additions & 5 deletions lambda-function/lambda.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "aws_lambda_function" "lambda" {
resource "aws_lambda_function" "fn" {
function_name = var.name
description = var.description
role = var.role_arn
Expand All @@ -20,8 +20,8 @@ resource "aws_lambda_function" "lambda" {
logging_config {
log_group = aws_cloudwatch_log_group.logs.name
log_format = "JSON"
application_log_level = var.cloudwatch.app_log_level
system_log_level = var.cloudwatch.system_log_level
application_log_level = var.logs.app_log_level
system_log_level = var.logs.system_log_level
}

tags = var.tags
Expand All @@ -31,14 +31,14 @@ resource "aws_lambda_permission" "permissions" {
for_each = var.permissions

action = each.value.action
function_name = aws_lambda_function.lambda.function_name
function_name = aws_lambda_function.fn.function_name
principal = each.value.principal
statement_id = each.key
source_arn = each.value.source_arn
}

resource "aws_lambda_function_event_invoke_config" "invoke_config" {
function_name = aws_lambda_function.lambda.function_name
function_name = aws_lambda_function.fn.function_name

maximum_retry_attempts = var.async_invoke_config.max_retries
maximum_event_age_in_seconds = var.async_invoke_config.max_event_age
Expand Down
4 changes: 2 additions & 2 deletions lambda-function/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
output "lambda" {
value = {
arn = aws_lambda_function.lambda.arn
invoke_arn = aws_lambda_function.lambda.invoke_arn
arn = aws_lambda_function.fn.arn
invoke_arn = aws_lambda_function.fn.invoke_arn
}
}

Expand Down
40 changes: 20 additions & 20 deletions lambda-function/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ variable "runtime" {
}

variable "architectures" {
type = list(string)
default = ["arm64"]
type = list(string)
default = ["arm64"]
description = "A list of the supported architectures"
}

Expand All @@ -45,8 +45,8 @@ variable "concurrency" {
}

variable "layer_arns" {
type = list(string)
default = []
type = list(string)
default = []
description = "ARN of layers"
}

Expand All @@ -56,29 +56,29 @@ variable "handler" {
}

variable "vars" {
type = map(string)
default = {}
type = map(string)
default = {}
description = "Environment variables available to the function"
}

variable "cloudwatch" {
variable "src" {
type = string
description = "The path to your function code"
}

variable "logs" {
type = object({
app_log_level = optional(string, "INFO") # TRACE, DEBUG, INFO, WARN, ERROR, FATAL
system_log_level = optional(string, "INFO") # DEBUG, INFO, WARN
app_log_level = optional(string, "INFO") # TRACE, DEBUG, INFO, WARN, ERROR, FATAL
system_log_level = optional(string, "INFO") # DEBUG, INFO, WARN
retention_in_days = optional(number, 30)
})
default = {}
}

variable "src" {
type = string
description = "The path to your function code"
}

variable "async_invoke_config" {
type = object({
max_retries = optional(number, 2)
max_event_age = optional(number, 3600) # 1 hour
max_retries = optional(number, 2)
max_event_age = optional(number, 3600) # 1 hour
failure_destination_arn = optional(string, null)
success_destination_arn = optional(string, null)
})
Expand All @@ -87,15 +87,15 @@ variable "async_invoke_config" {

variable "permissions" {
type = map(object({
action = string
principal = string
action = string
principal = string
source_arn = optional(string, null)
}))
default = {}
}

variable "tags" {
type = map(string)
type = map(string)
description = "The tags to apply to all resources created"
default = {}
default = {}
}