Skip to content

Commit e41806c

Browse files
committed
Adding terraform example with AWS resources
1 parent 3a6b87d commit e41806c

File tree

1 file changed

+278
-0
lines changed

1 file changed

+278
-0
lines changed

website/docs/r/kinesis_metrics_source.html.markdown

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,282 @@ HTTP sources can be imported using the collector name and source name (`collecto
128128
terraform import sumologic_kinesis_metrics_source.test my-test-collector/my-test-source
129129
```
130130

131+
## Full Example (Including terraform for AWS asset creation)
132+
```hcl
133+
terraform {
134+
required_providers {
135+
sumologic = {
136+
source = "sumologic/sumologic"
137+
}
138+
aws = {
139+
source = "hashicorp/aws"
140+
}
141+
}
142+
}
143+
144+
provider "sumologic" {}
145+
provider "aws" {}
146+
147+
locals {
148+
account_id = ""
149+
aws_access_key = ""
150+
aws_secret_key = ""
151+
152+
description = "update your terraform description here"
153+
identifier = "SumologicMetricStream"
154+
155+
region = "us-west-2"
156+
157+
tagfilters = [
158+
{ type = "TagFilters", namespace = "AWS/ApplicationELB", tags = ["Deployment=prod"] },
159+
]
160+
161+
}
162+
163+
resource "sumologic_collector" "collector_for_kinesis_metrics" {
164+
name = "AWS Metrics via Kinesis"
165+
}
166+
167+
resource "sumologic_kinesis_metrics_source" "kinesis_source" {
168+
name = "CloudWatch Metrics via Kinesis"
169+
description = "Description for Sumologic source"
170+
category = "aws/cloudwatch"
171+
content_type = "KinesisMetric"
172+
collector_id = sumologic_collector.collector_for_kinesis_metrics.id
173+
174+
authentication {
175+
type = "S3BucketAuthentication"
176+
access_key = local.aws_access_key
177+
secret_key = local.aws_secret_key
178+
}
179+
180+
path {
181+
type = "KinesisMetricPath"
182+
183+
dynamic "tag_filters" {
184+
for_each = local.tagfilters
185+
content {
186+
type = tag_filters.value.type
187+
namespace = tag_filters.value.namespace
188+
tags = tag_filters.value.tags
189+
}
190+
}
191+
}
192+
}
193+
194+
// ------------------------------------ AWS Kinesis part
195+
196+
resource "aws_cloudwatch_metric_stream" "main" {
197+
name = local.identifier
198+
role_arn = aws_iam_role.metric_stream_to_firehose.arn
199+
firehose_arn = aws_kinesis_firehose_delivery_stream.kinesis_stream.arn
200+
output_format = "opentelemetry0.7"
201+
202+
// include_filter {
203+
// namespace = "AWS/ApplicationELB"
204+
// }
205+
// include_filter {
206+
// namespace = "AWS/DynamoDB"
207+
// }
208+
209+
}
210+
211+
resource "aws_iam_role" "metric_stream_to_firehose" {
212+
name = "${local.identifier}-stream_to_firehose"
213+
214+
assume_role_policy = <<EOF
215+
{
216+
"Version": "2012-10-17",
217+
"Statement": [
218+
{
219+
"Action": "sts:AssumeRole",
220+
"Principal": {
221+
"Service": "streams.metrics.cloudwatch.amazonaws.com"
222+
},
223+
"Effect": "Allow",
224+
"Sid": ""
225+
}
226+
]
227+
}
228+
EOF
229+
}
230+
231+
resource "aws_iam_role_policy" "metric_stream_to_firehose" {
232+
name = "default"
233+
role = aws_iam_role.metric_stream_to_firehose.id
234+
235+
policy = <<EOF
236+
{
237+
"Version": "2012-10-17",
238+
"Statement": [
239+
{
240+
"Effect": "Allow",
241+
"Action": [
242+
"firehose:PutRecord",
243+
"firehose:PutRecordBatch"
244+
],
245+
"Resource": "${aws_kinesis_firehose_delivery_stream.kinesis_stream.arn}"
246+
}
247+
]
248+
}
249+
EOF
250+
}
251+
252+
resource "aws_iam_role" "firehose_role" {
253+
name = "${local.identifier}_firehose"
254+
255+
assume_role_policy = <<EOF
256+
{
257+
"Version": "2012-10-17",
258+
"Statement": [
259+
{
260+
"Action": "sts:AssumeRole",
261+
"Principal": {
262+
"Service": "firehose.amazonaws.com"
263+
},
264+
"Effect": "Allow",
265+
"Sid": ""
266+
}
267+
]
268+
}
269+
EOF
270+
}
271+
272+
resource "aws_iam_role_policy" "firehose_can_log_errors_to_Cloudwatch" {
273+
role = aws_iam_role.firehose_role.id
274+
275+
policy = <<EOF
276+
{
277+
"Version": "2012-10-17",
278+
"Statement": [
279+
{
280+
"Effect": "Allow",
281+
"Action": [
282+
"logs:PutLogEvents"
283+
],
284+
"Resource": [
285+
"arn:aws:logs:${local.region}:${local.account_id}:log-group:/aws/kinesisfirehose/${local.identifier}:*",
286+
"arn:aws:logs:${local.region}:${local.account_id}:log-group:/aws/kinesisfirehose/${local.identifier}:*:log-stream:*"
287+
]
288+
}
289+
]
290+
}
291+
EOF
292+
}
293+
294+
resource "aws_iam_role_policy" "firehose_can_use_s3_bucket_for_failures" {
295+
role = aws_iam_role.firehose_role.id
296+
297+
policy = <<EOF
298+
{
299+
"Version": "2012-10-17",
300+
"Statement": [
301+
{
302+
"Action": [
303+
"s3:AbortMultipartUpload",
304+
"s3:GetBucketLocation",
305+
"s3:GetObject",
306+
"s3:ListBucket",
307+
"s3:ListBucketMultipartUploads",
308+
"s3:PutObject"
309+
],
310+
"Resource": [
311+
"arn:aws:s3:::${aws_s3_bucket.bucket_for_Kinesis_failures.bucket}/*",
312+
"arn:aws:s3:::${aws_s3_bucket.bucket_for_Kinesis_failures.bucket}"
313+
],
314+
"Effect": "Allow"
315+
}
316+
]
317+
}
318+
EOF
319+
}
320+
321+
resource "aws_s3_bucket" "bucket_for_Kinesis_failures" {
322+
bucket = "${replace(lower(local.identifier),"_", "-")}-kinesisfailures"
323+
}
324+
resource "aws_s3_bucket_acl" "bucket_for_Kinesis_failures" {
325+
bucket = aws_s3_bucket.bucket_for_Kinesis_failures.id
326+
acl = "private"
327+
}
328+
resource "aws_kinesis_firehose_delivery_stream" "kinesis_stream" {
329+
name = local.identifier
330+
destination = "http_endpoint"
331+
332+
http_endpoint_configuration {
333+
name = "ToSumo"
334+
url = sumologic_kinesis_metrics_source.kinesis_source.url
335+
role_arn = aws_iam_role.firehose_role.arn
336+
buffering_interval = 60
337+
s3_backup_mode = "FailedDataOnly"
338+
339+
request_configuration {
340+
content_encoding = "GZIP"
341+
}
342+
343+
cloudwatch_logging_options {
344+
enabled = true
345+
log_group_name = "/aws/kinesisfirehose/${local.identifier}"
346+
log_stream_name = "DestinationDelivery"
347+
}
348+
}
349+
350+
s3_configuration {
351+
role_arn = aws_iam_role.firehose_role.arn
352+
bucket_arn = aws_s3_bucket.bucket_for_Kinesis_failures.arn
353+
}
354+
}
355+
356+
357+
// ------------------------------------ authorizing Sumo to use our AWS accounts
358+
359+
resource "aws_iam_policy" "cloudwatch_ingest" {
360+
name = "policy-for-cloudwatch-ingest"
361+
description = "Managed by Terraform"
362+
363+
policy = <<EOF
364+
{
365+
"Version": "2012-10-17",
366+
"Statement": [
367+
{
368+
"Action": [
369+
"cloudwatch:ListMetrics",
370+
"cloudwatch:GetMetricStatistics",
371+
"tag:GetResources"
372+
],
373+
"Effect": "Allow",
374+
"Resource": "*"
375+
}
376+
]
377+
}
378+
EOF
379+
}
380+
381+
data "aws_iam_policy_document" "sumo_can_use_our_AWS" {
382+
statement {
383+
actions = ["sts:AssumeRole"]
384+
condition {
385+
test = "StringEquals"
386+
variable = "sts:ExternalId"
387+
values = [local.account_id]
388+
}
389+
principals {
390+
identifiers = ["arn:aws:iam::${local.account_id}:root"]
391+
type = "AWS"
392+
}
393+
}
394+
}
395+
396+
resource "aws_iam_role" "cloudwatch_role" {
397+
name = "role-for-cloudwatch-ingest"
398+
assume_role_policy = data.aws_iam_policy_document.sumo_can_use_our_AWS.json
399+
}
400+
401+
resource "aws_iam_role_policy_attachment" "test-attach" {
402+
role = aws_iam_role.cloudwatch_role.name
403+
policy_arn = aws_iam_policy.cloudwatch_ingest.arn
404+
}
405+
406+
```
407+
408+
131409
[1]: https://help.sumologic.com/Send_Data/Sources/03Use_JSON_to_Configure_Sources/JSON_Parameters_for_Hosted_Sources

0 commit comments

Comments
 (0)