-
Notifications
You must be signed in to change notification settings - Fork 4
/
lambda.tf
55 lines (50 loc) · 1.63 KB
/
lambda.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
data "aws_iam_policy_document" "lambda_log_access" {
statement {
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
]
resources = ["arn:aws:logs:*:*:*"]
}
}
# This function is created in us-east-1 as required by CloudFront.
resource "aws_lambda_function" "cloudfront_auth" {
#provider = aws.us-east-1
# checkov:skip=CKV_AWS_50:x-ray tracing not used
description = "${var.auth_provider} authentication for ${var.hostname}"
runtime = "nodejs12.x"
role = aws_iam_role.lambda_role.arn
filename = "${path.module}/lambda.zip"
function_name = "${replace(var.hostname, "/[^A-Za-z0-9-]/", "_")}-cloudfront_auth"
handler = "index.handler"
publish = true
timeout = 5
source_code_hash = data.archive_file.lambda.output_base64sha256
tags = var.tags
}
data "aws_iam_policy_document" "lambda_assume_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [
"edgelambda.amazonaws.com",
"lambda.amazonaws.com",
]
}
}
}
resource "aws_iam_role" "lambda_role" {
name = "lambda_role"
assume_role_policy = data.aws_iam_policy_document.lambda_assume_role.json
tags = var.tags
}
resource "aws_iam_role_policy_attachment" "lambda_log_access" {
role = aws_iam_role.lambda_role.name
policy_arn = aws_iam_policy.lambda_log_access.arn
}
resource "aws_iam_policy" "lambda_log_access" {
name = "cloudfront_auth_lambda_log_access"
policy = data.aws_iam_policy_document.lambda_log_access.json
}