-
Notifications
You must be signed in to change notification settings - Fork 34
/
cloudwatch_logs.tf
27 lines (23 loc) · 1.12 KB
/
cloudwatch_logs.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
resource "aws_cloudwatch_log_group" "lambda" {
name = "/aws/lambda/${var.lambda_at_edge ? "us-east-1." : ""}${var.function_name}"
retention_in_days = var.cloudwatch_logs_retention_in_days
kms_key_id = var.cloudwatch_logs_kms_key_id
tags = var.tags
}
resource "aws_lambda_permission" "cloudwatch_logs" {
for_each = var.cloudwatch_log_subscription_filters
action = "lambda:InvokeFunction"
function_name = lookup(each.value, "destination_arn", null)
principal = "logs.${data.aws_region.current.name}.amazonaws.com"
source_arn = "${aws_cloudwatch_log_group.lambda.arn}:*"
}
resource "aws_cloudwatch_log_subscription_filter" "cloudwatch_logs" {
for_each = var.cloudwatch_log_subscription_filters
depends_on = [aws_lambda_permission.cloudwatch_logs]
destination_arn = lookup(each.value, "destination_arn", null)
distribution = lookup(each.value, "distribution", null)
filter_pattern = lookup(each.value, "filter_pattern", "")
log_group_name = aws_cloudwatch_log_group.lambda.name
name = each.key
role_arn = lookup(each.value, "role_arn", null)
}