forked from DNXLabs/terraform-aws-cloudtrail-notification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
61 lines (56 loc) · 1.46 KB
/
iam.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
data "aws_iam_policy_document" "lambda_assume_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
}
}
resource "aws_iam_role" "iam_for_lambda" {
name = "iam_for_lambda"
assume_role_policy = data.aws_iam_policy_document.lambda_assume_role.json
tags = var.tags
}
resource "aws_iam_policy" "lambda_cw" {
name = "lambda_cw"
path = "/"
description = "IAM policy for logging from a lambda"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action : [
"cloudwatch:GetMetricData",
"cloudwatch:ListMetrics",
"cloudwatch:DescribeAlarms",
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeMetricFilters",
"logs:FilterLogEvents"
],
Resource : [aws_lambda_function.lambda.arn,"arn:aws:logs:*:*:*","arn:aws:cloudwatch:*:*:*"]
Effect : "Allow"
},
{
Action : [
"SNS:Publish"
],
Resource : "arn:aws:sns:*:*:*",
Effect : "Allow"
},
{
Action : [
"kms:Decrypt", "kms:GenerateDataKey*"
],
Resource : "*",
Effect : "Allow"
}
]
})
}
resource "aws_iam_role_policy_attachment" "lambda_cw" {
role = aws_iam_role.iam_for_lambda.name
policy_arn = aws_iam_policy.lambda_cw.arn
}