-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathpolicy-cd-lambdas.tf
80 lines (69 loc) · 1.8 KB
/
policy-cd-lambdas.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
78
79
###############################################################################
# Policy: Create/Delete Lambdas
###############################################################################
resource "aws_iam_policy" "cd_lambdas" {
name = "${local.tf_service_name}-${local.stage}-cd-lambdas"
path = "/"
policy = data.aws_iam_policy_document.cd_lambdas.json
}
data "aws_iam_policy_document" "cd_lambdas" {
# Lambda: Create, delete the serverless Lambda.
statement {
actions = [
"lambda:GetEventSourceMapping",
"lambda:ListEventSourceMappings",
"lambda:ListFunctions",
"lambda:ListTags",
"lambda:TagResource",
"lambda:UntagResource",
]
# Necessary wildcards
# https://iam.cloudonaut.io/reference/lambda.html
# https://docs.aws.amazon.com/lambda/latest/dg/lambda-api-permissions-ref.html
resources = [
"*",
]
}
statement {
# Note: `lambda:CreateFunction` now supports function ARNs!
# https://docs.aws.amazon.com/lambda/latest/dg/lambda-api-permissions-ref.html
actions = [
"lambda:CreateFunction",
"lambda:DeleteFunction",
]
resources = [
local.sls_lambda_arn,
]
}
# IAM: Integrate Lambda roles.
statement {
actions = [
"iam:PutRolePolicy",
"iam:DeleteRolePolicy",
]
resources = [
local.lambda_role_iam_arn,
]
}
# Logs (`sls logs`)
# - Need "all" ARN for `logs:DescribeLogGroups` in creating deleted Lambda.
statement {
actions = [
"logs:DescribeLogGroups",
]
resources = [
local.sls_log_stream_all_arn,
]
}
statement {
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:DeleteLogGroup",
"logs:PutLogEvents",
]
resources = [
local.sls_log_stream_arn,
]
}
}