forked from futurice/terraform-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
permissions.tf
61 lines (56 loc) · 1.46 KB
/
permissions.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
# Allow Lambda to invoke our functions:
resource "aws_iam_role" "this" {
name = "${local.prefix_with_domain}"
tags = "${var.tags}"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com",
"edgelambda.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
# Allow API Gateway to invoke our functions:
resource "aws_lambda_permission" "this" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = "${local.function_arn}"
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_stage.this.execution_arn}/*/*" # the /*/* portion grants access from any method on any resource within the API Gateway "REST API"
}
# Allow writing logs to CloudWatch from our functions:
resource "aws_iam_policy" "this" {
count = "${var.lambda_logging_enabled ? 1 : 0}"
name = "${local.prefix_with_domain}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*",
"Effect": "Allow"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "this" {
count = "${var.lambda_logging_enabled ? 1 : 0}"
role = "${aws_iam_role.this.name}"
policy_arn = "${aws_iam_policy.this.arn}"
}