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
/
main.tf
144 lines (115 loc) · 3.75 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# --- AppSync Setup ---
# Create the AppSync GraphQL api.
resource "aws_appsync_graphql_api" "appsync" {
name = "${var.prefix}_appsync"
schema = file("schema.graphql")
authentication_type = "API_KEY"
}
# Create the API key.
resource "aws_appsync_api_key" "appsync_api_key" {
api_id = aws_appsync_graphql_api.appsync.id
}
# --- DynamoDB ---
resource "aws_dynamodb_table" "Comments" {
name = "${var.prefix}_Comments"
attribute {
name = "createdAt"
type = "S"
}
attribute {
name = "eventId"
type = "S"
}
attribute {
name = "commentId"
type = "S"
}
billing_mode = "PROVISIONED"
hash_key = "eventId"
range_key = "commentId"
read_capacity = "1"
write_capacity = "1"
local_secondary_index {
name = "LSI-Comments-by-eventId-createdAt"
projection_type = "ALL"
range_key = "createdAt"
}
}
resource "aws_dynamodb_table" "Events" {
name = "${var.prefix}_Events"
attribute {
name = "id"
type = "S"
}
billing_mode = "PROVISIONED"
hash_key = "id"
read_capacity = "1"
write_capacity = "1"
}
resource "aws_appsync_datasource" "Comments" {
name = "Comments"
api_id = aws_appsync_graphql_api.appsync.id
service_role_arn = aws_iam_role.iam_appsync_role.arn
type = "AMAZON_DYNAMODB"
dynamodb_config {
table_name = aws_dynamodb_table.Comments.name
}
}
resource "aws_appsync_datasource" "Events" {
name = "Events"
api_id = aws_appsync_graphql_api.appsync.id
service_role_arn = aws_iam_role.iam_appsync_role.arn
type = "AMAZON_DYNAMODB"
dynamodb_config {
table_name = aws_dynamodb_table.Events.name
}
}
# --- Resolvers ---
resource "aws_appsync_resolver" "EventComments" {
api_id = aws_appsync_graphql_api.appsync.id
type = "Event"
field = "comments"
data_source = aws_appsync_datasource.Comments.name
request_template = file("./resolvers/Event.comments/request.vtl")
response_template = file("./resolvers/Event.comments/response.vtl")
}
resource "aws_appsync_resolver" "createEvent" {
api_id = aws_appsync_graphql_api.appsync.id
type = "Mutation"
field = "createEvent"
data_source = aws_appsync_datasource.Events.name
request_template = file("./resolvers/createEvent/request.vtl")
response_template = file("./resolvers/createEvent/response.vtl")
}
resource "aws_appsync_resolver" "deleteEvent" {
api_id = aws_appsync_graphql_api.appsync.id
type = "Mutation"
field = "deleteEvent"
data_source = aws_appsync_datasource.Events.name
request_template = file("./resolvers/deleteEvent/request.vtl")
response_template = file("./resolvers/deleteEvent/response.vtl")
}
resource "aws_appsync_resolver" "commentOnEvent" {
api_id = aws_appsync_graphql_api.appsync.id
type = "Mutation"
field = "commentOnEvent"
data_source = aws_appsync_datasource.Comments.name
request_template = file("./resolvers/commentOnEvent/request.vtl")
response_template = file("./resolvers/commentOnEvent/response.vtl")
}
resource "aws_appsync_resolver" "getEvent" {
api_id = aws_appsync_graphql_api.appsync.id
type = "Query"
field = "getEvent"
data_source = aws_appsync_datasource.Events.name
request_template = file("./resolvers/getEvent/request.vtl")
response_template = file("./resolvers/getEvent/response.vtl")
}
resource "aws_appsync_resolver" "listEvents" {
api_id = aws_appsync_graphql_api.appsync.id
type = "Query"
field = "listEvents"
data_source = aws_appsync_datasource.Events.name
request_template = file("./resolvers/listEvents/request.vtl")
response_template = file("./resolvers/listEvents/response.vtl")
}