Skip to content

Commit 70d532d

Browse files
committed
add each log destination example
1 parent cf14e22 commit 70d532d

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

examples/with-pipes/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ Note that this example may create resources which cost money. Run `terraform des
3737
| Name | Source | Version |
3838
|------|--------|---------|
3939
| <a name="module_eventbridge"></a> [eventbridge](#module\_eventbridge) | ../../ | n/a |
40+
| <a name="module_firehose_to_s3"></a> [firehose\_to\_s3](#module\_firehose\_to\_s3) | terraform-aws-modules/iam/aws//modules/iam-assumable-role | >= 5.30 |
41+
| <a name="module_firehose_to_s3_policy"></a> [firehose\_to\_s3\_policy](#module\_firehose\_to\_s3\_policy) | terraform-aws-modules/iam/aws//modules/iam-policy | >= 5.30 |
4042
| <a name="module_lambda_target"></a> [lambda\_target](#module\_lambda\_target) | terraform-aws-modules/lambda/aws | ~> 6.0 |
43+
| <a name="module_logs_bucket"></a> [logs\_bucket](#module\_logs\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> 4.0 |
4144
| <a name="module_step_function_target"></a> [step\_function\_target](#module\_step\_function\_target) | terraform-aws-modules/step-functions/aws | ~> 2.0 |
4245

4346
## Resources
@@ -53,13 +56,16 @@ Note that this example may create resources which cost money. Run `terraform des
5356
| [aws_dynamodb_table.source](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dynamodb_table) | resource |
5457
| [aws_iam_role.eventbridge_pipe](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
5558
| [aws_iam_role_policy_attachment.pipe](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
59+
| [aws_kinesis_firehose_delivery_stream.logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kinesis_firehose_delivery_stream) | resource |
5660
| [aws_kinesis_stream.source](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kinesis_stream) | resource |
5761
| [aws_sqs_queue.dlq](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue) | resource |
5862
| [aws_sqs_queue.source](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue) | resource |
5963
| [aws_sqs_queue.target](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue) | resource |
6064
| [null_resource.download_package](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
6165
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
66+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
6267
| [aws_iam_policy_document.assume_role_pipe](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
68+
| [aws_iam_policy_document.firehose_to_s3](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
6369

6470
## Inputs
6571

examples/with-pipes/main.tf

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ provider "aws" {
77
skip_credentials_validation = true
88
}
99

10+
data "aws_caller_identity" "current" {}
11+
1012
module "eventbridge" {
1113
source = "../../"
1214

@@ -196,6 +198,15 @@ module "eventbridge" {
196198
}
197199
}
198200

201+
log_configuration = {
202+
level = "INFO"
203+
s3_log_destination = {
204+
bucket_name = module.logs_bucket.s3_bucket_id
205+
bucket_owner = data.aws_caller_identity.current.account_id
206+
output_format = "json"
207+
}
208+
}
209+
199210
tags = {
200211
Pipe = "sqs_source_eventbridge_target"
201212
}
@@ -212,6 +223,13 @@ module "eventbridge" {
212223
}
213224
}
214225

226+
log_configuration = {
227+
level = "INFO"
228+
firehose_log_destination = {
229+
delivery_stream_arn = aws_kinesis_firehose_delivery_stream.logs.arn
230+
}
231+
}
232+
215233
tags = {
216234
Pipe = "sqs_source_lambda_target"
217235
}
@@ -488,3 +506,72 @@ EOF
488506
resource "aws_cloudwatch_log_group" "logs" {
489507
name = "${random_pet.this.id}-my-log-group"
490508
}
509+
510+
module "logs_bucket" {
511+
source = "terraform-aws-modules/s3-bucket/aws"
512+
version = "~> 4.0"
513+
514+
bucket_prefix = "${random_pet.this.id}-logs"
515+
516+
force_destroy = true
517+
}
518+
519+
resource "aws_kinesis_firehose_delivery_stream" "logs" {
520+
name = "${random_pet.this.id}-logs"
521+
destination = "extended_s3"
522+
523+
extended_s3_configuration {
524+
role_arn = module.firehose_to_s3.iam_role_arn
525+
bucket_arn = module.logs_bucket.s3_bucket_arn
526+
prefix = "from-firehose-logs/"
527+
}
528+
}
529+
530+
module "firehose_to_s3" {
531+
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role"
532+
version = ">= 5.30"
533+
534+
trusted_role_services = [
535+
"firehose.amazonaws.com"
536+
]
537+
538+
create_role = true
539+
540+
role_name_prefix = "${random_pet.this.id}-firehose-to-s3-"
541+
role_requires_mfa = false
542+
543+
custom_role_policy_arns = [
544+
module.firehose_to_s3_policy.arn
545+
]
546+
}
547+
548+
module "firehose_to_s3_policy" {
549+
source = "terraform-aws-modules/iam/aws//modules/iam-policy"
550+
version = ">= 5.30"
551+
552+
name = "${random_pet.this.id}-firehose-to-s3"
553+
path = "/"
554+
description = "Pipes logging firehose to s3 policy"
555+
556+
policy = data.aws_iam_policy_document.firehose_to_s3.json
557+
}
558+
559+
data "aws_iam_policy_document" "firehose_to_s3" {
560+
statement {
561+
effect = "Allow"
562+
563+
actions = [
564+
"s3:AbortMultipartUpload",
565+
"s3:GetBucketLocation",
566+
"s3:GetObject",
567+
"s3:ListBucket",
568+
"s3:ListBucketMultipartUploads",
569+
"s3:PutObject",
570+
]
571+
572+
resources = [
573+
module.logs_bucket.s3_bucket_arn,
574+
"${module.logs_bucket.s3_bucket_arn}/*",
575+
]
576+
}
577+
}

0 commit comments

Comments
 (0)