forked from realglobe-Inc/terraform-aws-static-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda_at_edge.tf
46 lines (40 loc) · 1.43 KB
/
lambda_at_edge.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
resource "aws_lambda_function" "this" {
count = var.activate_lambda_sign ? 1 : 0
filename = var.lambda["filename"]
runtime = "nodejs12.x"
function_name = var.lambda["function_name"]
handler = "src/lambda.default"
role = aws_iam_role.iam_for_lambda[count.index].arn
publish = true
}
resource "aws_iam_role" "iam_for_lambda" {
count = var.activate_lambda_sign ? 1 : 0
name = var.lambda["role_name"]
assume_role_policy = var.lambda["assume_role_policy"]
}
data "aws_iam_policy_document" "policy" {
count = var.activate_lambda_sign ? 1 : 0
dynamic "statement" {
for_each = [for s in var.lambda_policy : {
actions = s.actions
effect = s.effect
resources = s.resources
}]
content {
actions = lookup(statement.value, "actions", null)
effect = lookup(statement.value, "effect", null)
resources = lookup(statement.value, "resources", null)
}
}
}
resource "aws_iam_policy" "policy_for_lambda" {
count = var.activate_lambda_sign ? 1 : 0
name = var.lambda["function_name"]
policy = data.aws_iam_policy_document.policy[count.index].json
}
resource "aws_iam_policy_attachment" "lambda-attach" {
count = var.activate_lambda_sign ? 1 : 0
name = "lambda-attachment"
roles = [aws_iam_role.iam_for_lambda[count.index].name]
policy_arn = aws_iam_policy.policy_for_lambda[count.index].arn
}