Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 2dd5287

Browse files
committed
initial commit
1 parent 10a880e commit 2dd5287

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

main.tf

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
###############################################################################
2+
# VARIABLES #
3+
###############################################################################
4+
5+
variable name {
6+
type = "string"
7+
description = "Name of the firehose"
8+
}
9+
10+
variable account_id {
11+
type = "string"
12+
description = "AWS account ID"
13+
}
14+
15+
variable region {
16+
default = "eu-west-1"
17+
type = "string"
18+
description = "AWS region"
19+
}
20+
21+
variable destination {
22+
default = "s3"
23+
}
24+
25+
variable s3_configuration {
26+
type = "map"
27+
description = "AWS S3 configuration"
28+
default = {}
29+
}
30+
31+
variable enable {
32+
type = "string"
33+
description = "Enable firehose"
34+
default = "1"
35+
}
36+
37+
###############################################################################
38+
# MAIN #
39+
###############################################################################
40+
41+
resource "aws_iam_role" "firehose_role" {
42+
name = "${var.name}"
43+
path = "/environment/${terraform.workspace}/"
44+
force_detach_policies = true
45+
46+
assume_role_policy = <<EOF
47+
{
48+
"Version": "2012-10-17",
49+
"Statement": [
50+
{
51+
"Action": "sts:AssumeRole",
52+
"Principal": {
53+
"Service": "firehose.amazonaws.com"
54+
},
55+
"Effect": "Allow",
56+
"Sid": ""
57+
}
58+
]
59+
}
60+
EOF
61+
}
62+
63+
data "aws_iam_policy_document" "firehose_role" {
64+
statement {
65+
actions = [
66+
"s3:AbortMultipartUpload",
67+
"s3:GetBucketLocation",
68+
"s3:GetObject",
69+
"s3:ListBucket",
70+
"s3:ListBucketMultipartUploads",
71+
"s3:PutObject",
72+
"s3:PutObjectAcl",
73+
]
74+
75+
resources = [
76+
"${lookup(var.s3_configuration, "bucket_arn")}",
77+
"${lookup(var.s3_configuration, "bucket_arn")}/*",
78+
"arn:aws:s3:::%FIREHOSE_BUCKET_NAME%",
79+
"arn:aws:s3:::%FIREHOSE_BUCKET_NAME%/*",
80+
]
81+
}
82+
83+
statement {
84+
actions = [
85+
"lambda:InvokeFunction",
86+
"lambda:GetFunctionConfiguration",
87+
]
88+
89+
resources = [
90+
"arn:aws:lambda:${var.region}:${var.account_id}:function:%FIREHOSE_DEFAULT_FUNCTION%:%FIREHOSE_DEFAULT_VERSION%",
91+
]
92+
}
93+
94+
statement {
95+
actions = [
96+
"logs:*",
97+
]
98+
99+
resources = [
100+
"arn:aws:logs:${var.region}:${var.account_id}:log-group:/aws/kinesisfirehose/${var.name}:log-stream:*",
101+
]
102+
}
103+
}
104+
105+
resource "aws_iam_role_policy" "firehose_role" {
106+
name = "${var.name}"
107+
role = "${aws_iam_role.firehose_role.id}"
108+
109+
policy = "${data.aws_iam_policy_document.firehose_role.json}"
110+
}
111+
112+
resource "aws_kinesis_firehose_delivery_stream" "stream" {
113+
count = "${var.enable}"
114+
name = "${var.name}"
115+
destination = "${var.destination}"
116+
117+
s3_configuration {
118+
role_arn = "${aws_iam_role.firehose_role.arn}"
119+
bucket_arn = "${lookup(var.s3_configuration, "bucket_arn")}"
120+
buffer_interval = "${lookup(var.s3_configuration, "buffer_interval", 300)}"
121+
buffer_size = "${lookup(var.s3_configuration, "buffer_size", 5)}"
122+
prefix = "${lookup(var.s3_configuration, "prefix")}"
123+
124+
cloudwatch_logging_options {
125+
enabled = true
126+
log_group_name = "/aws/kinesisfirehose/${var.name}"
127+
log_stream_name = "S3Delivery"
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)