-
Notifications
You must be signed in to change notification settings - Fork 7
/
iam.tf
89 lines (78 loc) · 1.94 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
78
79
80
81
82
83
84
85
86
87
88
89
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
data "aws_iam_policy_document" "allow_lambda_service_assume" {
statement {
sid = "AllowAwsToAssumeRole"
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [
"edgelambda.amazonaws.com",
"lambda.amazonaws.com"
]
}
}
}
resource "aws_iam_role" "lambda_at_edge" {
name = "${var.name}-lambda-edge-role"
tags = var.tags
assume_role_policy = data.aws_iam_policy_document.allow_lambda_service_assume.json
inline_policy {
name = "AllowCloudwatchLogs"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = ["logs:CreateLogStream", "logs:PutLogEvents", "logs:CreateLogGroup"]
Effect = "Allow"
Resource = "*"
},
]
})
}
inline_policy {
name = "LambdaEdgeSelfRoleRead"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = ["iam:GetRolePolicy"]
Effect = "Allow"
Resource = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${var.name}-lambda-edge-role"
},
{
Action = ["sts:GetCallerIdentity"]
Effect = "Allow"
Resource = "*"
}
]
})
}
inline_policy {
name = "SSM_PARAMETER_PERMISSION_FOR_LAMBDA_AUTH"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = ["ssm:GetParameter"]
Effect = "Allow"
Resource = aws_ssm_parameter.lambda_configuration_parameters.arn
},
]
})
}
inline_policy {
name = "ssmParameterDecrypt"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = ["kms:Decrypt"]
Effect = "Allow"
Resource = aws_kms_key.ssm_kms_key.arn
},
]
})
}
}