-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiam.tf
77 lines (62 loc) · 1.71 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
data "aws_iam_policy_document" "lambda_assume_role_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = concat(["lambda.amazonaws.com"], var.principal_services)
}
}
}
resource "aws_iam_role" "iam_for_lambda" {
name = "${var.name}-role"
assume_role_policy = data.aws_iam_policy_document.lambda_assume_role_policy.json
tags = merge({
name = "${var.name}-role"
}, var.tags)
}
data "aws_iam_policy_document" "lambda_service_access" {
statement {
actions = [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
]
resources = ["*"]
}
statement {
actions = [
"logs:PutLogEvents",
"logs:DescribeLogStreams"
]
resources = ["${aws_cloudwatch_log_group.main.arn}:log-stream:*"]
}
statement {
actions = [
"logs:CreateLogStream"
]
resources = [aws_cloudwatch_log_group.main.arn]
}
}
resource "aws_iam_policy" "lambda_service_access" {
name = "${var.name}-service-access"
policy = data.aws_iam_policy_document.lambda_service_access.json
tags = merge({
name = "${var.name}-service-access"
}, var.tags)
}
resource "aws_iam_role_policy_attachment" "lambda_service_access" {
role = aws_iam_role.iam_for_lambda.name
policy_arn = aws_iam_policy.lambda_service_access.arn
}
#
# VPC Permissions
#
data "aws_iam_policy" "vpc_access" {
name = "AWSLambdaVPCAccessExecutionRole"
}
resource "aws_iam_role_policy_attachment" "vpc_access" {
count = var.enable_networking ? 1 : 0
role = aws_iam_role.iam_for_lambda.name
policy_arn = data.aws_iam_policy.vpc_access.arn
}