-
Notifications
You must be signed in to change notification settings - Fork 0
/
kinesis.tf
147 lines (128 loc) · 3.55 KB
/
kinesis.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
resource "aws_kinesis_stream" "zentral-events" {
name = "${local.namespace}-events"
stream_mode_details {
stream_mode = "ON_DEMAND"
}
}
locals {
firehose_name = "${local.namespace}-events-s3"
}
data "aws_iam_policy_document" "firehose" {
statement {
actions = [
"s3:AbortMultipartUpload",
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket",
"s3:ListBucketMultipartUploads",
"s3:PutObject"
]
resources = [
aws_s3_bucket.data.arn,
"${aws_s3_bucket.data.arn}/*"
]
}
statement {
actions = [
"kinesis:DescribeStream",
"kinesis:GetShardIterator",
"kinesis:GetRecords",
"kinesis:ListShards"
]
resources = [
aws_kinesis_stream.zentral-events.arn
]
}
statement {
actions = [
"glue:GetTable",
"glue:GetTableVersion",
"glue:GetTableVersions"
]
resources = [
aws_glue_catalog_database.db.arn,
aws_glue_catalog_table.table.arn,
"arn:aws:glue:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:catalog", # glue:GetTableVersions
]
}
statement {
actions = [
"logs:PutLogEvents"
]
resources = [
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/aws/kinesisfirehose/${local.firehose_name}:log-stream:*"
]
}
}
resource "aws_iam_policy" "firehose" {
name = "${local.namespace}-firehose"
policy = data.aws_iam_policy_document.firehose.json
}
data "aws_iam_policy_document" "firehose_assume_role" {
statement {
actions = [
"sts:AssumeRole"
]
principals {
type = "Service"
identifiers = [
"firehose.amazonaws.com"
]
}
condition {
test = "StringEquals"
variable = "sts:ExternalId"
values = [
data.aws_caller_identity.current.account_id
]
}
}
}
resource "aws_iam_role" "firehose" {
name = "${local.namespace}-firehose"
assume_role_policy = data.aws_iam_policy_document.firehose_assume_role.json
}
resource "aws_iam_role_policy_attachment" "firehose" {
role = aws_iam_role.firehose.name
policy_arn = aws_iam_policy.firehose.arn
}
resource "aws_kinesis_firehose_delivery_stream" "zentral-events-s3" {
name = local.firehose_name
destination = "extended_s3"
kinesis_source_configuration {
kinesis_stream_arn = aws_kinesis_stream.zentral-events.arn
role_arn = aws_iam_role.firehose.arn
}
extended_s3_configuration {
role_arn = aws_iam_role.firehose.arn
bucket_arn = aws_s3_bucket.data.arn
buffer_size = var.firehose_buffer_size
buffer_interval = var.firehose_buffer_interval
prefix = "data/!{timestamp:yyyy/MM/dd/}"
error_output_prefix = "!{firehose:error-output-type}/!{timestamp:yyyy/MM/dd/}"
data_format_conversion_configuration {
enabled = true
input_format_configuration {
deserializer {
hive_json_ser_de { // this ser/der allows custom timestamp formats
timestamp_formats = [
"yyyy-MM-dd'T'HH:mm:ss.SSSSSS",
"yyyy-MM-dd'T'HH:mm:ss.SSS",
"yyyy-MM-dd'T'HH:mm:ss"
]
}
}
}
output_format_configuration {
serializer {
parquet_ser_de {}
}
}
schema_configuration {
database_name = aws_glue_catalog_table.table.database_name
table_name = aws_glue_catalog_table.table.name
role_arn = aws_iam_role.firehose.arn
}
}
}
}