|
| 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 --> |
0 commit comments