Skip to content

Commit

Permalink
PNGDAT-1800 Add built in support for shipping logs to sumo (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
bchinpp authored Jul 26, 2024
1 parent 76e3b21 commit dfca4af
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lambda_function/lambda_function.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
locals {
log_group_name = var.log_group_name == null ? "/aws/lambda/${var.function_name}" : var.log_group_name
}

resource "aws_cloudwatch_log_group" "lambda_log_group" {
name = local.log_group_name
retention_in_days = var.log_retention_in_days
tags = var.log_tags == {} ? var.tags : var.log_tags
skip_destroy = var.log_skip_destroy
}

resource "aws_cloudwatch_log_subscription_filter" "example_subscription_filter" {
count = var.ship_logs_to_sumo ? 1 : 0
name = "${var.function_name}_subscription_filter"
log_group_name = aws_cloudwatch_log_group.lambda_log_group.name
destination_arn = "arn:aws:lambda:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:function:SumoCWLogsLambda"
filter_pattern = ""
}

resource "aws_lambda_function" "lambda" {
function_name = var.function_name
description = var.description
Expand Down
29 changes: 29 additions & 0 deletions lambda_function/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,33 @@ variable "create_codebuild_to_run_unit_test" {
type = bool
default = false
description = "If true, will create codebuild and all the resources for running unit tests"
}

variable "log_group_name" {
type = string
default = null
description = "If set, will create a log group with that name for the lambda, otherwise the default name (/aws/lambda/<function name>) will be used"
}

variable "log_retention_in_days" {
type = number
default = 0 # Never expire
}

variable "log_skip_destroy" {
type = bool
default = true
description = "If true, the log group will not be destroyed when the lambda is destroyed"
}

variable "ship_logs_to_sumo" {
type = bool
default = false
description = "If true, will create a subscription filter to send logs to Sumo Logic"
}

variable "log_tags" {
type = map(string)
default = {}
description = "Tags to apply to the log group. Defaults to the same tags as the lambda function if nothing is passed in."
}

0 comments on commit dfca4af

Please sign in to comment.