-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthorizer.tf
55 lines (43 loc) · 1.59 KB
/
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
data "aws_iam_policy_document" "authorizer_assume_role" {
count = var.authorizer != null ? 1 : 0
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["apigateway.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "authorizer" {
count = var.authorizer != null ? 1 : 0
statement {
actions = ["lambda:invokeFunction"]
resources = [var.authorizer.arn]
}
}
resource "aws_iam_role" "authorizer" {
count = var.authorizer != null ? 1 : 0
name_prefix = var.authorizer.function_name
assume_role_policy = data.aws_iam_policy_document.authorizer_assume_role[0].json
permissions_boundary = var.permissions_boundary
}
resource "aws_iam_policy" "authorizer" {
count = var.authorizer != null ? 1 : 0
name_prefix = var.authorizer.function_name
policy = data.aws_iam_policy_document.authorizer[0].json
}
resource "aws_iam_role_policy_attachment" "authorizer" {
count = var.authorizer != null ? 1 : 0
role = aws_iam_role.authorizer[0].name
policy_arn = aws_iam_policy.authorizer[0].arn
}
resource "aws_api_gateway_authorizer" "authorizer" {
count = var.authorizer != null ? 1 : 0
name = var.authorizer.function_name
authorizer_credentials = aws_iam_role.authorizer[0].arn
identity_source = var.authorizer_identity_source
authorizer_result_ttl_in_seconds = 0
authorizer_uri = var.authorizer.invoke_arn
rest_api_id = aws_api_gateway_rest_api.this.id
type = "REQUEST"
}