This repository has been archived by the owner on Jan 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathiam.tf
67 lines (58 loc) · 1.39 KB
/
iam.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
locals {
api_gateway_assume_policy = {
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = "sts:AssumeRole"
Principal = {
Service = "apigateway.amazonaws.com"
},
},
]
}
}
resource "aws_iam_role" "modules" {
name = "${local.name_prefix}-modules"
assume_role_policy = jsonencode(local.api_gateway_assume_policy)
}
resource "aws_iam_role_policy" "modules" {
role = aws_iam_role.modules.name
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"dynamodb:Query",
"dynamodb:GetItem",
"dynamodb:BatchGetItem",
"dynamodb:GetRecords",
"dynamodb:Scan",
]
Resource = [
module.modules_store.dynamodb_table_arn,
],
},
]
})
}
resource "aws_iam_role" "auth" {
count = length(local.authorizers)
name = "${local.name_prefix}-authorizer"
assume_role_policy = jsonencode(local.api_gateway_assume_policy)
}
resource "aws_iam_role_policy" "auth" {
count = length(local.authorizers)
role = aws_iam_role.auth[count.index].name
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = "lambda:InvokeFunction"
Resource = data.aws_lambda_function.auth[count.index].arn,
},
]
})
}