Skip to content

Commit 9211110

Browse files
committed
Add eventbridge-event-bus module
1 parent 2fe551e commit 9211110

File tree

6 files changed

+313
-0
lines changed

6 files changed

+313
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# eventbridge-event-bus
2+
3+
This module creates following resources.
4+
5+
- `aws_cloudwatch_event_bus`
6+
- `aws_cloudwatch_event_bus_policy` (optional)
7+
- `aws_cloudwatch_event_archive` (optional)
8+
- `aws_schemas_discoverer` (optional)
9+
10+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
11+
## Requirements
12+
13+
| Name | Version |
14+
|------|---------|
15+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
16+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.58 |
17+
18+
## Providers
19+
20+
| Name | Version |
21+
|------|---------|
22+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.59.0 |
23+
24+
## Modules
25+
26+
| Name | Source | Version |
27+
|------|--------|---------|
28+
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | tedilabs/misc/aws//modules/resource-group | ~> 0.10.0 |
29+
30+
## Resources
31+
32+
| Name | Type |
33+
|------|------|
34+
| [aws_cloudwatch_event_archive.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_archive) | resource |
35+
| [aws_cloudwatch_event_bus.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_bus) | resource |
36+
| [aws_cloudwatch_event_bus_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_bus_policy) | resource |
37+
| [aws_schemas_discoverer.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/schemas_discoverer) | resource |
38+
39+
## Inputs
40+
41+
| Name | Description | Type | Default | Required |
42+
|------|-------------|------|---------|:--------:|
43+
| <a name="input_name"></a> [name](#input\_name) | (Required) The name of the new event bus. The name of custom event bus can't contain the `/` character, but you can use the `/` character in partner event bus names. You can't use the name `default` for a custom event bus, as this name is already used for your account's default event bus. | `string` | n/a | yes |
44+
| <a name="input_archives"></a> [archives](#input\_archives) | (Required) The configuration to create archives for the event bus. Events are continuously saved in archives, and individual events will be deleted after the retention period. An archive will persist until you manually delete it. Each block of `archives` as defined below.<br> (Required) `name` - The name of the new event archive. Maximum of 48 characters consisting of numbers, lower/upper case letters, `.`, `-`, `_`. You can't change the name of the archive after it is created.<br> (Optional) `description` - The description of the new event archive.<br> (Optional) `retention_in_days` - The maximum number of days to retain events in the new event archive. `0` is equivalent to Indefinite. The maximum is 2 billion days. Defaults to `0`.<br> (Optional) `event_pattern` - An event pattern to use to filter events sent to the archive. | <pre>list(object({<br> name = string<br> description = optional(string, "Managed by Terraform.")<br> retention_in_days = optional(number, 0)<br> event_pattern = optional(string)<br> }))</pre> | `[]` | no |
45+
| <a name="input_module_tags_enabled"></a> [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no |
46+
| <a name="input_policy"></a> [policy](#input\_policy) | (Optional) A valid policy JSON document. The resource-based policy defines who can access your event bus. By default, only the event bus owner can send events to the event bus. | `string` | `null` | no |
47+
| <a name="input_resource_group_description"></a> [resource\_group\_description](#input\_resource\_group\_description) | (Optional) The description of Resource Group. | `string` | `"Managed by Terraform."` | no |
48+
| <a name="input_resource_group_enabled"></a> [resource\_group\_enabled](#input\_resource\_group\_enabled) | (Optional) Whether to create Resource Group to find and group AWS resources which are created by this module. | `bool` | `true` | no |
49+
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | (Optional) The name of Resource Group. A Resource Group name can have a maximum of 127 characters, including letters, numbers, hyphens, dots, and underscores. The name cannot start with `AWS` or `aws`. | `string` | `""` | no |
50+
| <a name="input_schema_discovery"></a> [schema\_discovery](#input\_schema\_discovery) | (Required) The configuration for schema discovery of the event bus. Enabling event discovery on an event bus will generate EventBridge Schemas for events on that bus. This may incur a cost (the first five million ingested events in each month is free). `schema_discovery` as defined below.<br> (Optional) `enabled` - Whether to enable schema discovery. Defaults to `false`.<br> (Optional) `description` - The description of the schema discoverer. Maximum of 256 characters. | <pre>object({<br> enabled = optional(bool, false)<br> description = optional(string, "Managed by Terraform.")<br> })</pre> | `{}` | no |
51+
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) A map of tags to add to all resources. | `map(string)` | `{}` | no |
52+
53+
## Outputs
54+
55+
| Name | Description |
56+
|------|-------------|
57+
| <a name="output_archives"></a> [archives](#output\_archives) | A list of archives for the event bus. |
58+
| <a name="output_arn"></a> [arn](#output\_arn) | The Amazon Resource Name (ARN) of the event bus. |
59+
| <a name="output_id"></a> [id](#output\_id) | The unique identifier for the event bus. |
60+
| <a name="output_name"></a> [name](#output\_name) | The name of the event bus. |
61+
| <a name="output_schema_discovery"></a> [schema\_discovery](#output\_schema\_discovery) | The configuration for schema discovery of the event bus. |
62+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
locals {
2+
metadata = {
3+
package = "terraform-aws-messaging"
4+
version = trimspace(file("${path.module}/../../VERSION"))
5+
module = basename(path.module)
6+
name = var.name
7+
}
8+
module_tags = var.module_tags_enabled ? {
9+
"module.terraform.io/package" = local.metadata.package
10+
"module.terraform.io/version" = local.metadata.version
11+
"module.terraform.io/name" = local.metadata.module
12+
"module.terraform.io/full-name" = "${local.metadata.package}/${local.metadata.module}"
13+
"module.terraform.io/instance" = local.metadata.name
14+
} : {}
15+
}
16+
17+
18+
###################################################
19+
# Event Bus on EventBridge
20+
###################################################
21+
22+
resource "aws_cloudwatch_event_bus" "this" {
23+
name = var.name
24+
event_source_name = startswith(var.name, "aws.partner/") ? var.name : null
25+
26+
tags = merge(
27+
{
28+
"Name" = local.metadata.name
29+
},
30+
local.module_tags,
31+
var.tags,
32+
)
33+
}
34+
35+
36+
###################################################
37+
# Event Bus Policy
38+
###################################################
39+
40+
resource "aws_cloudwatch_event_bus_policy" "this" {
41+
count = var.policy != null ? 1 : 0
42+
43+
event_bus_name = aws_cloudwatch_event_bus.this.name
44+
policy = var.policy
45+
}
46+
47+
48+
###################################################
49+
# Event Bus Archives
50+
###################################################
51+
52+
resource "aws_cloudwatch_event_archive" "this" {
53+
for_each = {
54+
for archive in var.archives :
55+
archive.name => archive
56+
}
57+
58+
event_source_arn = aws_cloudwatch_event_bus.this.arn
59+
60+
name = each.key
61+
description = each.value.description
62+
retention_days = each.value.retention_in_days
63+
64+
event_pattern = each.value.event_pattern
65+
}
66+
67+
68+
###################################################
69+
# Schema Discovery of Event Bus
70+
###################################################
71+
72+
resource "aws_schemas_discoverer" "this" {
73+
count = var.schema_discovery.enabled ? 1 : 0
74+
75+
source_arn = aws_cloudwatch_event_bus.this.arn
76+
description = var.schema_discovery.description
77+
78+
tags = merge(
79+
{
80+
"Name" = local.metadata.name
81+
},
82+
local.module_tags,
83+
var.tags,
84+
)
85+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
output "id" {
2+
description = "The unique identifier for the event bus."
3+
value = aws_cloudwatch_event_bus.this.id
4+
}
5+
6+
output "arn" {
7+
description = "The Amazon Resource Name (ARN) of the event bus."
8+
value = aws_cloudwatch_event_bus.this.arn
9+
}
10+
11+
output "name" {
12+
description = "The name of the event bus."
13+
value = aws_cloudwatch_event_bus.this.name
14+
}
15+
16+
output "archives" {
17+
description = "A list of archives for the event bus."
18+
value = [
19+
for archive in aws_cloudwatch_event_archive.this : {
20+
id = archive.id
21+
arn = archive.arn
22+
name = archive.name
23+
description = archive.description
24+
retention_in_days = archive.retention_days
25+
}
26+
]
27+
}
28+
29+
output "schema_discovery" {
30+
description = "The configuration for schema discovery of the event bus."
31+
value = {
32+
enabled = var.schema_discovery.enabled
33+
discoverer = (var.schema_discovery.enabled
34+
? {
35+
id = one(aws_schemas_discoverer.this[*].id)
36+
arn = one(aws_schemas_discoverer.this[*].arn)
37+
description = one(aws_schemas_discoverer.this[*].description)
38+
}
39+
: null
40+
)
41+
}
42+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
locals {
2+
resource_group_name = (var.resource_group_name != ""
3+
? var.resource_group_name
4+
: join(".", [
5+
local.metadata.package,
6+
local.metadata.module,
7+
replace(local.metadata.name, "/[^a-zA-Z0-9_\\.-]/", "-"),
8+
])
9+
)
10+
}
11+
12+
13+
module "resource_group" {
14+
source = "tedilabs/misc/aws//modules/resource-group"
15+
version = "~> 0.10.0"
16+
17+
count = (var.resource_group_enabled && var.module_tags_enabled) ? 1 : 0
18+
19+
name = local.resource_group_name
20+
description = var.resource_group_description
21+
22+
query = {
23+
resource_tags = local.module_tags
24+
}
25+
26+
module_tags_enabled = false
27+
tags = merge(
28+
local.module_tags,
29+
var.tags,
30+
)
31+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
variable "name" {
2+
description = "(Required) The name of the new event bus. The name of custom event bus can't contain the `/` character, but you can use the `/` character in partner event bus names. You can't use the name `default` for a custom event bus, as this name is already used for your account's default event bus."
3+
type = string
4+
nullable = false
5+
}
6+
7+
variable "policy" {
8+
description = "(Optional) A valid policy JSON document. The resource-based policy defines who can access your event bus. By default, only the event bus owner can send events to the event bus."
9+
type = string
10+
default = null
11+
}
12+
13+
variable "archives" {
14+
description = <<EOF
15+
(Required) The configuration to create archives for the event bus. Events are continuously saved in archives, and individual events will be deleted after the retention period. An archive will persist until you manually delete it. Each block of `archives` as defined below.
16+
(Required) `name` - The name of the new event archive. Maximum of 48 characters consisting of numbers, lower/upper case letters, `.`, `-`, `_`. You can't change the name of the archive after it is created.
17+
(Optional) `description` - The description of the new event archive.
18+
(Optional) `retention_in_days` - The maximum number of days to retain events in the new event archive. `0` is equivalent to Indefinite. The maximum is 2 billion days. Defaults to `0`.
19+
(Optional) `event_pattern` - An event pattern to use to filter events sent to the archive.
20+
EOF
21+
type = list(object({
22+
name = string
23+
description = optional(string, "Managed by Terraform.")
24+
retention_in_days = optional(number, 0)
25+
event_pattern = optional(string)
26+
}))
27+
default = []
28+
nullable = false
29+
}
30+
31+
variable "schema_discovery" {
32+
description = <<EOF
33+
(Required) The configuration for schema discovery of the event bus. Enabling event discovery on an event bus will generate EventBridge Schemas for events on that bus. This may incur a cost (the first five million ingested events in each month is free). `schema_discovery` as defined below.
34+
(Optional) `enabled` - Whether to enable schema discovery. Defaults to `false`.
35+
(Optional) `description` - The description of the schema discoverer. Maximum of 256 characters.
36+
EOF
37+
type = object({
38+
enabled = optional(bool, false)
39+
description = optional(string, "Managed by Terraform.")
40+
})
41+
default = {}
42+
nullable = false
43+
}
44+
45+
variable "tags" {
46+
description = "(Optional) A map of tags to add to all resources."
47+
type = map(string)
48+
default = {}
49+
nullable = false
50+
}
51+
52+
variable "module_tags_enabled" {
53+
description = "(Optional) Whether to create AWS Resource Tags for the module informations."
54+
type = bool
55+
default = true
56+
nullable = false
57+
}
58+
59+
60+
###################################################
61+
# Resource Group
62+
###################################################
63+
64+
variable "resource_group_enabled" {
65+
description = "(Optional) Whether to create Resource Group to find and group AWS resources which are created by this module."
66+
type = bool
67+
default = true
68+
nullable = false
69+
}
70+
71+
variable "resource_group_name" {
72+
description = "(Optional) The name of Resource Group. A Resource Group name can have a maximum of 127 characters, including letters, numbers, hyphens, dots, and underscores. The name cannot start with `AWS` or `aws`."
73+
type = string
74+
default = ""
75+
nullable = false
76+
}
77+
78+
variable "resource_group_description" {
79+
description = "(Optional) The description of Resource Group."
80+
type = string
81+
default = "Managed by Terraform."
82+
nullable = false
83+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.3"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 4.58"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)