This repository has been archived by the owner on Oct 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
lambda-authorizer.tf
72 lines (62 loc) · 1.84 KB
/
lambda-authorizer.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
data "archive_file" "authorizer" {
type = "zip"
output_path = "${path.module}/.zip/${module.labels.id}_authorizer.zip"
source_file = "${path.module}/templates/lambda-placeholder.js"
}
data "aws_iam_policy_document" "authorizer_policy" {
statement {
actions = [
"lambda:InvokeFunction",
"secretsmanager:GetSecretValue"
]
resources = ["*"]
}
}
data "aws_iam_policy_document" "authorizer_assume_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [
"apigateway.amazonaws.com",
"lambda.amazonaws.com"
]
}
}
}
resource "aws_iam_policy" "authorizer_policy" {
name = "${module.labels.id}-lambda-authorizer-policy"
path = "/"
policy = data.aws_iam_policy_document.authorizer_policy.json
}
resource "aws_iam_role" "authorizer" {
name = "${module.labels.id}-lambda-authorizer"
assume_role_policy = data.aws_iam_policy_document.authorizer_assume_role.json
tags = module.labels.tags
}
resource "aws_iam_role_policy_attachment" "authorizer_policy" {
role = aws_iam_role.authorizer.name
policy_arn = aws_iam_policy.authorizer_policy.arn
}
resource "aws_lambda_function" "authorizer" {
filename = "${path.module}/.zip/${module.labels.id}_authorizer.zip"
function_name = "${module.labels.id}-authorizer"
source_code_hash = data.archive_file.authorizer.output_base64sha256
role = aws_iam_role.authorizer.arn
runtime = "nodejs10.x"
handler = "authorizer.handler"
memory_size = 128
timeout = 15
tags = module.labels.tags
environment {
variables = {
CONFIG_VAR_PREFIX = local.config_var_prefix,
NODE_ENV = "production"
}
}
lifecycle {
ignore_changes = [
source_code_hash
]
}
}