-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.tf
432 lines (403 loc) · 13 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
variable "aiven_api_token" {}
variable "allowed_ips" {}
variable "project_name" {}
variable "kafka_version" {}
variable "service_cloud" {}
variable "service_cloud_alt" {}
variable "service_cloud_flink" {}
variable "service_name_prefix" {}
variable "service_plan_clickhouse" {}
variable "service_plan_flink" {}
variable "service_plan_kafka" {}
variable "service_plan_kafka_connect" {}
variable "service_plan_grafana" {}
variable "service_plan_influxdb" {}
variable "service_plan_opensearch" {}
variable "service_plan_pg" {}
terraform {
required_providers {
aiven = {
source = "aiven/aiven"
version = ">= 4.0.0, < 5.0.0"
}
}
}
provider "aiven" {
api_token = var.aiven_api_token
}
###################################################
# Apache Kafka
###################################################
resource "aiven_kafka" "demo-kafka" {
project = var.project_name
cloud_name = var.service_cloud
plan = var.service_plan_kafka
service_name = "${var.service_name_prefix}-kafka"
default_acl = false
termination_protection = false
kafka_user_config {
schema_registry = true
kafka_rest = true
kafka_connect = false
kafka_version = var.kafka_version
ip_filter_string = var.allowed_ips
kafka {
auto_create_topics_enable = false
}
public_access {
kafka = false
kafka_rest = false
kafka_connect = true
schema_registry = false
}
}
}
resource "aiven_kafka_connect" "demo-kafka-connect" {
project = var.project_name
cloud_name = var.service_cloud
plan = var.service_plan_kafka_connect
service_name = "${var.service_name_prefix}-kafka-connect"
kafka_connect_user_config {
ip_filter_string = var.allowed_ips
public_access {
kafka_connect = true
prometheus = true
}
}
}
resource "aiven_service_integration" "demo-kafka-connect-source-integration" {
project = var.project_name
integration_type = "kafka_connect"
source_service_name = aiven_kafka.demo-kafka.service_name
destination_service_name = aiven_kafka_connect.demo-kafka-connect.service_name
}
###################################################
# Apache Flink
###################################################
resource "aiven_flink" "demo-flink" {
project = var.project_name
cloud_name = var.service_cloud
plan = var.service_plan_flink
service_name = "${var.service_name_prefix}-flink"
}
resource "aiven_service_integration" "demo-flink-kafka-integration" {
project = var.project_name
integration_type = "flink"
source_service_name = aiven_kafka.demo-kafka.service_name
destination_service_name = aiven_flink.demo-flink.service_name
}
###################################################
# PostgreSQL
###################################################
resource "aiven_pg" "demo-postgres" {
project = var.project_name
cloud_name = var.service_cloud
plan = var.service_plan_pg
service_name = "${var.service_name_prefix}-postgres"
pg_user_config {
pg_version = "14"
}
}
resource "aiven_service_integration" "demo-flink-postgres-integration" {
project = var.project_name
integration_type = "flink"
source_service_name = aiven_pg.demo-postgres.service_name
destination_service_name = aiven_flink.demo-flink.service_name
}
###################################################
# ClickHouse
###################################################
resource "aiven_clickhouse" "demo-clickhouse" {
project = var.project_name
cloud_name = var.service_cloud
plan = var.service_plan_clickhouse
service_name = "${var.service_name_prefix}-clickhouse"
}
resource "aiven_service_integration" "demo-clickhouse-kafka-integration" {
project = var.project_name
integration_type = "clickhouse_kafka"
source_service_name = aiven_kafka.demo-kafka.service_name
destination_service_name = aiven_clickhouse.demo-clickhouse.service_name
clickhouse_kafka_user_config {
# note: JSON is experimental data type and not supported yet
# tables {
# name = "digitransit_hfp_bus_positions_raw"
# group_name = "3e4bf765-3418-42bd-b6f9-0378d677d583"
# data_format = "JSONEachRow"
# columns {
# name = "VP"
# type = "JSON"
# }
# topics {
# name = "digitransit-hfp-bus-positions-raw"
# }
# }
tables {
name = "digitransit_hfp_bus_positions_flattened"
group_name = "65e9b6ef-978e-4746-8714-dfb2cbef6915"
data_format = "JSONEachRow"
columns {
name = "desi"
type = "String"
}
columns {
name = "dir"
type = "String"
}
columns {
name = "oper"
type = "Int32"
}
columns {
name = "oper_name"
type = "String"
}
columns {
name = "veh"
type = "Int32"
}
columns {
name = "tst"
type = "String"
}
columns {
name = "tsi"
type = "Int32"
}
columns {
name = "spd"
type = "Float32"
}
columns {
name = "hdg"
type = "Int32"
}
columns {
name = "lat"
type = "Float32"
}
columns {
name = "long"
type = "Float32"
}
columns {
name = "acc"
type = "Float32"
}
columns {
name = "dl"
type = "Int32"
}
columns {
name = "drst"
type = "Int32"
}
columns {
name = "oday"
type = "String"
}
columns {
name = "start"
type = "String"
}
columns {
name = "loc"
type = "String"
}
columns {
name = "stop"
type = "String"
}
columns {
name = "route"
type = "String"
}
columns {
name = "occu"
type = "Int32"
}
topics {
name = "digitransit-hfp-bus-positions-flattened"
}
}
}
}
###################################################
# DigiTransit HFP feeds
###################################################
module "digitransit-hfp-bus-positions" {
source = "./digitransit-hfp"
connect_integration = aiven_service_integration.demo-kafka-connect-source-integration
aiven_project_name = var.project_name
kafka_connect_service_name = aiven_kafka_connect.demo-kafka-connect.service_name
kafka_service_name = aiven_kafka.demo-kafka.service_name
kafka_topic_name = "digitransit-hfp-bus-positions-raw"
mqtt_topic_name = "/hfp/v2/journey/ongoing/vp/bus/+/+/+/+/+/+/+/+/+/+/+/+"
}
module "digitransit-hfp-train-positions" {
source = "./digitransit-hfp"
connect_integration = aiven_service_integration.demo-kafka-connect-source-integration
aiven_project_name = var.project_name
kafka_connect_service_name = aiven_kafka_connect.demo-kafka-connect.service_name
kafka_service_name = aiven_kafka.demo-kafka.service_name
kafka_topic_name = "digitransit-hfp-train-positions-raw"
mqtt_topic_name = "/hfp/v2/journey/ongoing/vp/train/+/+/+/+/+/+/+/+/+/+/+/+"
}
resource "aiven_kafka_topic" "demo-kafka-topic-digitransit-hfp-bus-positions-flattened" {
project = var.project_name
service_name = aiven_kafka.demo-kafka.service_name
topic_name = "digitransit-hfp-bus-positions-flattened"
partitions = 3
replication = 3
config {
retention_ms = 1209600000
}
}
resource "aiven_flink_application" "demo-flink-application-digitransit-hfp-bus-position-flattening" {
project = var.project_name
service_name = aiven_flink.demo-flink.service_name
name = "digitransit_hfp_bus_positions_flatten"
}
resource "aiven_flink_application_version" "demo-flink-application-version-digitransit-hfp-bus-position-flattening" {
project = var.project_name
service_name = aiven_flink.demo-flink.service_name
application_id = aiven_flink_application.demo-flink-application-digitransit-hfp-bus-position-flattening.application_id
statement = <<EOF
INSERT INTO digitransit_hfp_bus_positions_flattened
SELECT
VP.`desi`,
VP.`dir`,
VP.`oper`,
operators.`name`,
VP.`veh`,
VP.`tst`,
VP.`tsi`,
VP.`spd`,
VP.`hdg`,
VP.`lat`,
VP.`long`,
VP.`acc`,
VP.`dl`,
VP.`drst`,
VP.`oday`,
VP.`start`,
VP.`loc`,
VP.`stop`,
VP.`route`,
VP.`occu`
FROM digitransit_hfp_bus_positions_raw positions
INNER JOIN digitransit_operators operators
ON positions.VP.`oper` = operators.`id`
EOF
sink {
create_table = <<EOT
CREATE TABLE digitransit_hfp_bus_positions_flattened (
`desi` STRING,
`dir` STRING,
`oper` INT,
`oper_name` STRING,
`veh` INT,
`tst` STRING,
`tsi` INT,
`spd` FLOAT,
`hdg` INT,
`lat` FLOAT,
`long` FLOAT,
`acc` FLOAT,
`dl` INT,
`drst` INT,
`oday` STRING,
`start` STRING,
`loc` STRING,
`stop` STRING,
`route` STRING,
`occu` INT
) WITH (
'connector' = 'kafka',
'properties.bootstrap.servers' = '',
'scan.startup.mode' = 'latest-offset',
'topic' = 'digitransit-hfp-bus-positions-flattened',
'value.format' = 'json'
)
EOT
integration_id = aiven_service_integration.demo-flink-kafka-integration.integration_id
}
source {
create_table = <<EOT
CREATE TABLE digitransit_hfp_bus_positions_raw (
`VP` ROW<`desi` STRING,`dir` STRING,`oper` INT,`veh` INT,`tst` STRING,`tsi` INT,`spd` FLOAT,`hdg` INT,`lat` FLOAT,`long` FLOAT,`acc` FLOAT,`dl` INT,`drst` INT,`oday` STRING,`start` STRING,`loc` STRING,`stop` STRING,`route` STRING,`occu` INT>
) WITH (
'connector' = 'kafka',
'properties.bootstrap.servers' = '',
'scan.startup.mode' = 'earliest-offset',
'topic' = 'digitransit-hfp-bus-positions-raw',
'value.format' = 'json'
)
EOT
integration_id = aiven_service_integration.demo-flink-kafka-integration.integration_id
}
source {
create_table = <<EOT
CREATE TABLE digitransit_operators (
`id` INT PRIMARY KEY,
`name` STRING NOT NULL
) WITH (
'connector' = 'jdbc',
'url' = 'jdbc:postgresql://',
'table-name' = 'public.digitransit_operators'
)
EOT
integration_id = aiven_service_integration.demo-flink-postgres-integration.integration_id
}
}
resource "aiven_flink_application_deployment" "demo-flink-application-deployment-digitransit-hfp-bus-position-flattening" {
project = var.project_name
service_name = aiven_flink.demo-flink.service_name
application_id = aiven_flink_application.demo-flink-application-digitransit-hfp-bus-position-flattening.application_id
version_id = aiven_flink_application_version.demo-flink-application-version-digitransit-hfp-bus-position-flattening.application_version_id
}
# *********************************
# Monitoring services
# *********************************
resource "aiven_influxdb" "demo-metrics" {
project = var.project_name
cloud_name = var.service_cloud
plan = var.service_plan_influxdb
service_name = "${var.service_name_prefix}-metrics"
influxdb_user_config {
ip_filter_string = var.allowed_ips
}
}
resource "aiven_grafana" "demo-metrics-dashboard" {
project = var.project_name
cloud_name = var.service_cloud
plan = var.service_plan_grafana
service_name = "${var.service_name_prefix}-metrics-dashboard"
grafana_user_config {
ip_filter_string = var.allowed_ips
public_access {
grafana = true
}
}
}
# Metrics integration: Kafka -> InfluxDB
resource "aiven_service_integration" "demo-metrics-integration-kafka" {
project = var.project_name
integration_type = "metrics"
source_service_name = aiven_kafka.demo-kafka.service_name
destination_service_name = aiven_influxdb.demo-metrics.service_name
}
# Metrics integration: Flink -> InfluxDB
resource "aiven_service_integration" "demo-metrics-integration-flink" {
project = var.project_name
integration_type = "metrics"
source_service_name = aiven_flink.demo-flink.service_name
destination_service_name = aiven_influxdb.demo-metrics.service_name
}
# Dashboard integration = InfluxDB -> Grafana
resource "aiven_service_integration" "demo-dashboard-integration" {
project = var.project_name
integration_type = "dashboard"
source_service_name = aiven_grafana.demo-metrics-dashboard.service_name
destination_service_name = aiven_influxdb.demo-metrics.service_name
}