This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
56 lines (45 loc) · 1.67 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
# =============
# --- Roles ---
# -------------
# Appsync role
data "aws_iam_policy_document" "iam_appsync_role_document" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["appsync.amazonaws.com"]
}
}
}
resource "aws_iam_role" "iam_appsync_role" {
name = "${var.prefix}_iam_appsync_role"
assume_role_policy = data.aws_iam_policy_document.iam_appsync_role_document.json
}
# ================
# --- Policies ---
# ----------------
data "aws_caller_identity" "current" {}
# DynamoDB policy
data "aws_iam_policy_document" "iam_dynamodb_policy_document" {
statement {
actions = ["dynamodb:DeleteItem","dynamodb:GetItem","dynamodb:PutItem",
"dynamodb:Query","dynamodb:Scan","dynamodb:UpdateItem"
]
resources = ["arn:aws:dynamodb:${var.region}:${data.aws_caller_identity.current.account_id}:table/mah-oum_Events",
"arn:aws:dynamodb:${var.region}:${data.aws_caller_identity.current.account_id}:table/mah-oum_Comments",
"arn:aws:dynamodb:${var.region}:${data.aws_caller_identity.current.account_id}:table/mah-oum_Comments/index/LSI-Comments-by-eventId-createdAt"
]
}
}
resource "aws_iam_policy" "iam_dynamodb_policy" {
name = "${var.prefix}_iam_dynamodb_policy"
policy = data.aws_iam_policy_document.iam_dynamodb_policy_document.json
}
# ===================
# --- Attachments ---
# -------------------
# Attach Invoke Lambda policy to AppSync role.
resource "aws_iam_role_policy_attachment" "appsync_dynamodb" {
role = aws_iam_role.iam_appsync_role.name
policy_arn = aws_iam_policy.iam_dynamodb_policy.arn
}