-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcloudwatch-logs.tf
43 lines (32 loc) · 1.06 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
resource "aws_cloudwatch_log_group" "logs" {
name = var.name
retention_in_days = var.retention
tags = var.tags
}
data "aws_iam_policy_document" "logs_cloudwatch_log_group" {
statement {
actions = ["logs:DescribeLogStreams"]
resources = ["arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:*"]
}
statement {
actions = ["logs:CreateLogStream", "logs:PutLogEvents"]
resources = ["${aws_cloudwatch_log_group.logs.arn}:*"]
}
}
resource "aws_cloudwatch_log_group" "lambda" {
name = "/aws/lambda/${var.name}"
retention_in_days = 3
tags = var.tags
}
data "aws_iam_policy_document" "lambda_cloudwatch_log_group" {
statement {
actions = ["logs:DescribeLogStreams"]
resources = ["arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:*"]
}
statement {
actions = ["logs:CreateLogStream", "logs:PutLogEvents"]
resources = ["${aws_cloudwatch_log_group.lambda.arn}:*"]
}
}