-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.tf
77 lines (67 loc) · 1.47 KB
/
main.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
73
74
75
76
77
provider "aws" {
region = "${var.aws_region}"
}
resource "aws_dynamodb_table" "people" {
name = "${var.datasource_name}"
read_capacity = 1
write_capacity = 1
hash_key = "id"
attribute {
name = "id"
type = "S"
}
}
resource "aws_appsync_graphql_api" "people" {
name = "${var.appsync_name}"
authentication_type = "API_KEY"
}
resource "aws_appsync_api_key" "people_api" {
api_id = "${aws_appsync_graphql_api.people.id}"
}
resource "aws_iam_role" "api" {
name = "${var.appsync_name}-role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "appsync.amazonaws.com"
},
"Effect": "Allow"
}
]
}
EOF
}
resource "aws_iam_role_policy" "api_to_dynamodb_policy" {
name = "${var.appsync_name}_api_dynamodb_policy"
role = "${aws_iam_role.api.id}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"dynamodb:PutItem",
"dynamodb:Scan"
],
"Effect": "Allow",
"Resource": [
"${aws_dynamodb_table.people.arn}"
]
}
]
}
EOF
}
resource "aws_appsync_datasource" "people" {
api_id = "${aws_appsync_graphql_api.people.id}"
name = "${var.datasource_name}"
service_role_arn = "${aws_iam_role.api.arn}"
type = "AMAZON_DYNAMODB"
dynamodb_config {
table_name = "${aws_dynamodb_table.people.name}"
}
}