-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added modules/notifications for S3 bucket notifications (#31)
- Loading branch information
1 parent
b99dea2
commit 96be82e
Showing
11 changed files
with
416 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
repos: | ||
- repo: git://github.com/antonbabenko/pre-commit-terraform | ||
rev: v1.27.0 | ||
rev: v1.30.0 | ||
hooks: | ||
- id: terraform_fmt | ||
- id: terraform_docs | ||
- repo: git://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.5.0 | ||
rev: v3.1.0 | ||
hooks: | ||
- id: check-merge-conflict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# S3 bucket notifications to Lambda functions, SQS queues, and SNS topics | ||
|
||
Configuration in this directory creates S3 bucket notifications to all supported destinations. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
No requirements. | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| aws | n/a | | ||
| random | n/a | | ||
|
||
## Inputs | ||
|
||
No input. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| this\_s3\_bucket\_arn | The ARN of the bucket. Will be of format arn:aws:s3:::bucketname. | | ||
| this\_s3\_bucket\_bucket\_domain\_name | The bucket domain name. Will be of format bucketname.s3.amazonaws.com. | | ||
| this\_s3\_bucket\_bucket\_regional\_domain\_name | The bucket region-specific domain name. The bucket domain name including the region name, please refer here for format. Note: The AWS CloudFront allows specifying S3 region-specific endpoint when creating S3 origin, it will prevent redirect issues from CloudFront to S3 Origin URL. | | ||
| this\_s3\_bucket\_hosted\_zone\_id | The Route 53 Hosted Zone ID for this bucket's region. | | ||
| this\_s3\_bucket\_id | The name of the bucket. | | ||
| this\_s3\_bucket\_region | The AWS region this bucket resides in. | | ||
| this\_s3\_bucket\_website\_domain | The domain of the website endpoint, if the bucket is configured with a website. If not, this will be an empty string. This is used to create Route 53 alias records. | | ||
| this\_s3\_bucket\_website\_endpoint | The website endpoint, if the bucket is configured with a website. If not, this will be an empty string. | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
locals { | ||
bucket_name = "s3-bucket-${random_pet.this.id}" | ||
} | ||
|
||
resource "random_pet" "this" { | ||
length = 2 | ||
} | ||
|
||
module "s3_bucket" { | ||
source = "../../" | ||
|
||
bucket = local.bucket_name | ||
force_destroy = true | ||
} | ||
|
||
module "lambda_function1" { | ||
source = "terraform-aws-modules/cloudwatch/aws//examples/fixtures/aws_lambda_function" | ||
} | ||
|
||
module "lambda_function2" { | ||
source = "terraform-aws-modules/cloudwatch/aws//examples/fixtures/aws_lambda_function" | ||
} | ||
|
||
module "sns_topic1" { | ||
source = "terraform-aws-modules/cloudwatch/aws//examples/fixtures/aws_sns_topic" | ||
} | ||
|
||
module "sns_topic2" { | ||
source = "terraform-aws-modules/cloudwatch/aws//examples/fixtures/aws_sns_topic" | ||
} | ||
|
||
resource "aws_sqs_queue" "this" { | ||
count = 2 | ||
name = "${random_pet.this.id}-${count.index}" | ||
} | ||
|
||
module "all_notifications" { | ||
source = "../../modules/notification" | ||
|
||
bucket = module.s3_bucket.this_s3_bucket_id | ||
create = false | ||
|
||
// Common error - Error putting S3 notification configuration: InvalidArgument: Configuration is ambiguously defined. Cannot have overlapping suffixes in two rules if the prefixes are overlapping for the same event type. | ||
|
||
lambda_notifications = { | ||
lambda1 = { | ||
lambda_function_arn = module.lambda_function1.this_lambda_function_arn | ||
events = ["s3:ObjectCreated:Put"] | ||
filter_prefix = "prefix/" | ||
filter_suffix = ".json" | ||
} | ||
|
||
lambda2 = { | ||
lambda_function_arn = module.lambda_function2.this_lambda_function_arn | ||
events = ["s3:ObjectCreated:Post"] | ||
} | ||
} | ||
|
||
sqs_notifications = { | ||
sqs1 = { | ||
queue_arn = aws_sqs_queue.this[0].arn | ||
events = ["s3:ObjectCreated:Put"] | ||
filter_prefix = "prefix2/" | ||
filter_suffix = ".txt" | ||
|
||
// queue_id = aws_sqs_queue.this[0].id // optional | ||
} | ||
|
||
sqs2 = { | ||
queue_arn = aws_sqs_queue.this[1].arn | ||
events = ["s3:ObjectCreated:Copy"] | ||
} | ||
} | ||
|
||
sns_notifications = { | ||
sns1 = { | ||
topic_arn = module.sns_topic1.this_sns_topic_arn | ||
events = ["s3:ObjectRemoved:Delete"] | ||
filter_prefix = "prefix3/" | ||
filter_suffix = ".csv" | ||
} | ||
|
||
sns2 = { | ||
topic_arn = module.sns_topic2.this_sns_topic_arn | ||
events = ["s3:ObjectRemoved:DeleteMarkerCreated"] | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
output "this_s3_bucket_id" { | ||
description = "The name of the bucket." | ||
value = module.s3_bucket.this_s3_bucket_id | ||
} | ||
|
||
output "this_s3_bucket_arn" { | ||
description = "The ARN of the bucket. Will be of format arn:aws:s3:::bucketname." | ||
value = module.s3_bucket.this_s3_bucket_arn | ||
} | ||
|
||
output "this_s3_bucket_bucket_domain_name" { | ||
description = "The bucket domain name. Will be of format bucketname.s3.amazonaws.com." | ||
value = module.s3_bucket.this_s3_bucket_bucket_domain_name | ||
} | ||
|
||
output "this_s3_bucket_bucket_regional_domain_name" { | ||
description = "The bucket region-specific domain name. The bucket domain name including the region name, please refer here for format. Note: The AWS CloudFront allows specifying S3 region-specific endpoint when creating S3 origin, it will prevent redirect issues from CloudFront to S3 Origin URL." | ||
value = module.s3_bucket.this_s3_bucket_bucket_regional_domain_name | ||
} | ||
|
||
output "this_s3_bucket_hosted_zone_id" { | ||
description = "The Route 53 Hosted Zone ID for this bucket's region." | ||
value = module.s3_bucket.this_s3_bucket_hosted_zone_id | ||
} | ||
|
||
output "this_s3_bucket_region" { | ||
description = "The AWS region this bucket resides in." | ||
value = module.s3_bucket.this_s3_bucket_region | ||
} | ||
|
||
output "this_s3_bucket_website_endpoint" { | ||
description = "The website endpoint, if the bucket is configured with a website. If not, this will be an empty string." | ||
value = module.s3_bucket.this_s3_bucket_website_endpoint | ||
} | ||
|
||
output "this_s3_bucket_website_domain" { | ||
description = "The domain of the website endpoint, if the bucket is configured with a website. If not, this will be an empty string. This is used to create Route 53 alias records. " | ||
value = module.s3_bucket.this_s3_bucket_website_domain | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# S3 bucket notification | ||
|
||
Creates S3 bucket notification resource with all supported types of deliveries: AWS Lambda, SQS Queue, SNS Topic. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
No requirements. | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| aws | n/a | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| bucket | Name of S3 bucket to use | `string` | `""` | no | | ||
| bucket\_arn | ARN of S3 bucket to use in policies | `string` | `null` | no | | ||
| create | Whether to create this resource or not? | `bool` | `true` | no | | ||
| lambda\_notifications | Map of S3 bucket notifications to Lambda function | `any` | `{}` | no | | ||
| sns\_notifications | Map of S3 bucket notifications to SNS topic | `any` | `{}` | no | | ||
| sqs\_notifications | Map of S3 bucket notifications to SQS queue | `any` | `{}` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| this\_s3\_bucket\_notification\_id | ID of S3 bucket | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
Oops, something went wrong.