Skip to content

Commit 7a02b44

Browse files
author
Sean Turner
committed
Initial module commit
0 parents  commit 7a02b44

21 files changed

+638
-0
lines changed

.gitignore

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Created by https://www.gitignore.io/api/terraform
2+
# Edit at https://www.gitignore.io/?templates=terraform
3+
4+
### Terraform ###
5+
# Local .terraform directories
6+
**/.terraform/*
7+
8+
# .tfstate files
9+
*.tfstate
10+
*.tfstate.*
11+
12+
# Crash log files
13+
crash.log
14+
15+
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
16+
# .tfvars files are managed as part of configuration and so should be included in
17+
# version control.
18+
#
19+
# example.tfvars
20+
terraform.auto.tfvars
21+
22+
# Ignore override files as they are usually used to override resources locally and so
23+
# are not checked in
24+
override.tf
25+
override.tf.json
26+
*_override.tf
27+
*_override.tf.json
28+
29+
# Include override files you do wish to add to version control using negated pattern
30+
# !example_override.tf
31+
32+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
33+
# example: *tfplan*
34+
35+
# End of https://www.gitignore.io/api/terraform
36+
37+
# macOS
38+
*.DS_Store
39+
40+
# lambda archive
41+
*.zip
42+
43+
# vscode
44+
**/.vscode/*
45+
46+
**/archive/*
47+
!**/archive/.keep
48+
**/bin/*
49+
!**/bin/.keep

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
repos:
2+
- repo: git://github.com/antonbabenko/pre-commit-terraform
3+
rev: v1.47.0
4+
hooks:
5+
- id: terraform_docs
6+
- id: terraform_fmt
7+
- repo: git://github.com/pre-commit/pre-commit-hooks
8+
rev: v3.4.0
9+
hooks:
10+
- id: check-merge-conflict

.terraform.lock.hcl

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# terraform-module-eventbridge-debug-logger
2+
3+
A terraform module to create resources for capturing all eventbridge events for a given service.
4+
5+
## Contributing
6+
7+
Ensure that the pre-commit hooks are installed by running the following command: `pre-commit install`
8+
9+
## Usage example
10+
11+
Full example(s) leveraging this module is contained in the [examples](https://github.com/seanturner026/terraform-module-eventbridge-debug-logger/tree/master/examples/).
12+
13+
**IMPORTANT**: The master branch is used in source just as an example. In your code, do not pin to master because there may be breaking changes between releases. Instead pin to the release tag (e.g. `git@github.com:seanturner026/terraform-module-eventbridge-debug-logger.git?ref=vX.Y.Z`) using one of the [latest releases](https://github.com/seanturner026/terraform-module-eventbridge-debug-logger/releases/).
14+
15+
```hcl
16+
module "eventbridge_debug_logger" {
17+
source = "git@github.com:seanturner026/terraform-module-eventbridge-debug-logger.git"
18+
19+
name = "eventbridge_debug_logger"
20+
service_name = "ec2"
21+
lambda_logs_retention_in_days = 1
22+
tags = var.tags
23+
}
24+
```
25+
26+
The above example module invocation will track all ec2 events. Using a tool like saw to tail cloudwatch logs, the following log events will be written by launching and terminating an EC2 instance.
27+
28+
```
29+
$ saw watch /aws/lambda/events_debug_logger_ec2 --expand
30+
[2021-04-17T12:30:43+12:00] START RequestId: 9130fe6d-4a72-460f-87bb-2e3ede273772 Version: $LATEST
31+
[2021-04-17T12:30:43+12:00] {
32+
"account-id": "123456789012",
33+
"detail": {
34+
"instance-id": "i-0e12345678cdfc123",
35+
"state": "pending"
36+
},
37+
"detail-type": "EC2 Instance State-change Notification",
38+
"id": "01d4aadf-a202-ed3e-0464-8bb84910a8ec",
39+
"region": "us-east-1",
40+
"resources": [
41+
"arn:aws:ec2:us-east-1:123456789012:instance/i-0e12345678cdfc123"
42+
],
43+
"source": "aws.ec2",
44+
"version": "0",
45+
"level": "info",
46+
"msg": "handled event",
47+
"time": "2021-04-17T00:30:43Z"
48+
}
49+
[2021-04-17T12:30:43+12:00] END RequestId: 9130fe6d-4a72-460f-87bb-2e3ede273772
50+
[2021-04-17T12:30:43+12:00] REPORT RequestId: 9130fe6d-4a72-460f-87bb-2e3ede273772 Duration: 0.88 ms Billed Duration: 1 ms Memory Size: 128 MB Max Memory Used: 30 MB Init Duration: 74.44 ms
51+
[2021-04-17T12:33:58+12:00] START RequestId: 4c13af9e-3b16-4f8e-b8ac-56f524a6435e Version: $LATEST
52+
[2021-04-17T12:33:58+12:00] {
53+
"account": "123456789012",
54+
"detail": {
55+
"instance-id": "i-0e12345678cdfc123",
56+
"state": "shutting-down"
57+
},
58+
"detail-type": "EC2 Instance State-change Notification",
59+
"fields.time": "2021-04-17T00:33:57Z",
60+
"id": "cb3e793e-613b-a733-91e3-b92907d6f9fd",
61+
"level": "info",
62+
"msg": "handled event",
63+
"region": "us-east-1",
64+
"resources": [
65+
"arn:aws:ec2:us-east-1:123456789012:instance/i-0e12345678cdfc123"
66+
],
67+
"source": "aws.ec2",
68+
"time": "2021-04-17T00:33:58Z",
69+
"version": "0"
70+
}
71+
[2021-04-17T12:33:58+12:00] END RequestId: 4c13af9e-3b16-4f8e-b8ac-56f524a6435e
72+
[2021-04-17T12:33:58+12:00] REPORT RequestId: 4c13af9e-3b16-4f8e-b8ac-56f524a6435e Duration: 1.14 ms Billed Duration: 2 ms Memory Size: 128 MB Max Memory Used: 31 MB Init Duration: 61.97 ms
73+
```
74+
75+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
76+
## Requirements
77+
78+
| Name | Version |
79+
|------|---------|
80+
| archive | >= 2.0 |
81+
| aws | >= 3.0 |
82+
| null | >= 3.0 |
83+
84+
## Providers
85+
86+
| Name | Version |
87+
|------|---------|
88+
| archive | >= 2.0 |
89+
| aws | >= 3.0 |
90+
| null | >= 3.0 |
91+
92+
## Inputs
93+
94+
| Name | Description | Type | Default | Required |
95+
|------|-------------|------|---------|:--------:|
96+
| lambda\_logs\_retention\_in\_days | Specifies the number of days you want to retain log events in the specified lambda log group.<br><br>Specifying "0" means logs are permanently retained. | `number` | `1` | no |
97+
| name | Common name shared between resources. | `string` | n/a | yes |
98+
| service\_name | Name of the service to create a catch-all eventbridge rule for.<br><br>See variables.tf for a complete list of input options. | `string` | n/a | yes |
99+
| tags | A map of tags to add to all resources. | `map(string)` | n/a | yes |
100+
101+
## Outputs
102+
103+
No output.
104+
105+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

data.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
data "null_data_source" "wait_for_lambda_build" {
2+
for_each = local.lambdas
3+
4+
inputs = {
5+
lambda_build_id = null_resource.lambda_build[each.key].id
6+
source = "${path.module}/lambdas/bin/${each.key}"
7+
}
8+
}
9+
10+
data "archive_file" "this" {
11+
for_each = local.lambdas
12+
13+
type = "zip"
14+
source_file = data.null_data_source.wait_for_lambda_build[each.key].outputs["source"]
15+
output_path = "${path.module}/archive/${each.key}.zip"
16+
}
17+
18+
19+
data "aws_iam_policy_document" "this" {
20+
statement {
21+
actions = ["sts:AssumeRole"]
22+
23+
principals {
24+
type = "Service"
25+
identifiers = ["lambda.amazonaws.com"]
26+
}
27+
}
28+
}
29+

examples/.terraform.lock.hcl

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
provider "aws" {
2+
region = "us-east-1"
3+
profile = "sean"
4+
}

examples/modules.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module "eventbridge_debug_logger" {
2+
source = "../"
3+
4+
name = "eventbridge_debug_logger"
5+
service_name = "ec2"
6+
lambda_logs_retention_in_days = 1
7+
tags = var.tags
8+
}

examples/terraform.tfvars

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
tags = {
2+
name = "eventbridge_debug_logger"
3+
managed_by = "terraform"
4+
}

examples/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "tags" {
2+
description = "A map of tags to add to all resources."
3+
type = map(string)
4+
}

0 commit comments

Comments
 (0)