-
Notifications
You must be signed in to change notification settings - Fork 2
/
aws_lambda_iam_role.tf
44 lines (38 loc) · 1.11 KB
/
aws_lambda_iam_role.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
resource "aws_iam_role" "edge_lambda_role" {
name = "${upper(var.environment)}-${upper(var.function_name)}-LAMBDA-ROLE"
description = "Allows Lambda function to execute log collection."
assume_role_policy = data.aws_iam_policy_document.lambda_config_trust.json
}
/**
* Policy to allow AWS to access this lambda function.
*/
data "aws_iam_policy_document" "lambda_config_trust" {
statement {
sid = "AllowAwsToAssumeRole"
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [
"lambda.amazonaws.com",
"edgelambda.amazonaws.com",
]
}
}
}
data "aws_iam_policy_document" "lambda_logs_policy_doc" {
statement {
effect = "Allow"
resources = ["*"]
actions = [
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:CreateLogGroup",
]
}
}
resource "aws_iam_role_policy" "logs_role_policy" {
name = "${upper(var.environment)}-${upper(var.function_name)}-AT-EDGE"
role = aws_iam_role.edge_lambda_role.id
policy = data.aws_iam_policy_document.lambda_logs_policy_doc.json
}