Skip to content

Commit 0099c43

Browse files
feat: Add schema discoverer (terraform-aws-modules#64)
Co-authored-by: Anton Babenko <anton@antonbabenko.com>
1 parent d934f5d commit 0099c43

File tree

6 files changed

+45
-4
lines changed

6 files changed

+45
-4
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.62.3
3+
rev: v1.76.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate
@@ -23,7 +23,7 @@ repos:
2323
- '--args=--only=terraform_standard_module_structure'
2424
- '--args=--only=terraform_workspace_remote'
2525
- repo: https://github.com/pre-commit/pre-commit-hooks
26-
rev: v4.1.0
26+
rev: v4.3.0
2727
hooks:
2828
- id: check-merge-conflict
2929
- id: end-of-file-fixer

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ No modules.
407407
| [aws_iam_role.eventbridge](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
408408
| [aws_iam_role_policy_attachment.additional_many](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
409409
| [aws_iam_role_policy_attachment.additional_one](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
410+
| [aws_schemas_discoverer.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/schemas_discoverer) | resource |
411+
| [aws_cloudwatch_event_bus.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/cloudwatch_event_bus) | data source |
410412
| [aws_iam_policy.tracing](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy) | data source |
411413
| [aws_iam_policy_document.additional_inline](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
412414
| [aws_iam_policy_document.api_destination](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
@@ -453,6 +455,7 @@ No modules.
453455
| <a name="input_create_permissions"></a> [create\_permissions](#input\_create\_permissions) | Controls whether EventBridge Permission resources should be created | `bool` | `true` | no |
454456
| <a name="input_create_role"></a> [create\_role](#input\_create\_role) | Controls whether IAM roles should be created | `bool` | `true` | no |
455457
| <a name="input_create_rules"></a> [create\_rules](#input\_create\_rules) | Controls whether EventBridge Rule resources should be created | `bool` | `true` | no |
458+
| <a name="input_create_schemas_discoverer"></a> [create\_schemas\_discoverer](#input\_create\_schemas\_discoverer) | Controls whether default schemas discoverer should be created | `bool` | `false` | no |
456459
| <a name="input_create_targets"></a> [create\_targets](#input\_create\_targets) | Controls whether EventBridge Target resources should be created | `bool` | `true` | no |
457460
| <a name="input_ecs_target_arns"></a> [ecs\_target\_arns](#input\_ecs\_target\_arns) | The Amazon Resource Name (ARN) of the AWS ECS Tasks you want to use as EventBridge targets | `list(string)` | `[]` | no |
458461
| <a name="input_kinesis_firehose_target_arns"></a> [kinesis\_firehose\_target\_arns](#input\_kinesis\_firehose\_target\_arns) | The Amazon Resource Name (ARN) of the Kinesis Firehose Delivery Streams you want to use as EventBridge targets | `list(string)` | `[]` | no |
@@ -473,6 +476,7 @@ No modules.
473476
| <a name="input_role_permissions_boundary"></a> [role\_permissions\_boundary](#input\_role\_permissions\_boundary) | The ARN of the policy that is used to set the permissions boundary for the IAM role used by Lambda Function | `string` | `null` | no |
474477
| <a name="input_role_tags"></a> [role\_tags](#input\_role\_tags) | A map of tags to assign to IAM role | `map(string)` | `{}` | no |
475478
| <a name="input_rules"></a> [rules](#input\_rules) | A map of objects with EventBridge Rule definitions. | `map(any)` | `{}` | no |
479+
| <a name="input_schemas_discoverer_description"></a> [schemas\_discoverer\_description](#input\_schemas\_discoverer\_description) | Default schemas discoverer description | `string` | `"Auto schemas discoverer event"` | no |
476480
| <a name="input_sfn_target_arns"></a> [sfn\_target\_arns](#input\_sfn\_target\_arns) | The Amazon Resource Name (ARN) of the StepFunctions you want to use as EventBridge targets | `list(string)` | `[]` | no |
477481
| <a name="input_sqs_target_arns"></a> [sqs\_target\_arns](#input\_sqs\_target\_arns) | The Amazon Resource Name (ARN) of the AWS SQS Queues you want to use as EventBridge targets | `list(string)` | `[]` | no |
478482
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to assign to resources. | `map(string)` | `{}` | no |

examples/complete/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Note that this example may create resources which cost money. Run `terraform des
3636

3737
| Name | Source | Version |
3838
|------|--------|---------|
39+
| <a name="module_disabled"></a> [disabled](#module\_disabled) | ../../ | n/a |
3940
| <a name="module_ecs"></a> [ecs](#module\_ecs) | terraform-aws-modules/ecs/aws | ~> 3.0 |
4041
| <a name="module_eventbridge"></a> [eventbridge](#module\_eventbridge) | ../../ | n/a |
4142
| <a name="module_lambda"></a> [lambda](#module\_lambda) | terraform-aws-modules/lambda/aws | ~> 2.0 |

examples/complete/main.tf

+11-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ module "eventbridge" {
1717
# Some targets are only working with the default bus, so we don't have to create a new one like this:
1818
# bus_name = "${random_pet.this.id}-bus"
1919

20+
create_schemas_discoverer = true
21+
2022
attach_tracing_policy = true
2123

2224
attach_kinesis_policy = true
@@ -161,8 +163,9 @@ EOF
161163
]
162164
number_of_policy_jsons = 1
163165

164-
attach_policy = true
165-
policy = "arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess"
166+
# # Error can be that maximum 10 policies can be attached to IAM role
167+
# attach_policy = true
168+
# policy = "arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess"
166169

167170
attach_policies = true
168171
policies = ["arn:aws:iam::aws:policy/AWSXrayReadOnlyAccess"]
@@ -194,6 +197,12 @@ EOF
194197
###########################
195198
}
196199

200+
module "disabled" {
201+
source = "../../"
202+
203+
create = false
204+
}
205+
197206
locals {
198207
order_input_transformer = {
199208
input_paths = {

main.tf

+15
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,28 @@ locals {
3131
])
3232
}
3333

34+
data "aws_cloudwatch_event_bus" "this" {
35+
count = (var.create && var.create_bus) || (var.bus_name == "") ? 0 : 1
36+
37+
name = var.bus_name
38+
}
39+
3440
resource "aws_cloudwatch_event_bus" "this" {
3541
count = var.create && var.create_bus ? 1 : 0
3642

3743
name = var.bus_name
3844
tags = var.tags
3945
}
4046

47+
resource "aws_schemas_discoverer" "this" {
48+
count = var.create && var.create_schemas_discoverer ? 1 : 0
49+
50+
source_arn = var.create_bus ? aws_cloudwatch_event_bus.this[0].arn : data.aws_cloudwatch_event_bus.this[0].arn
51+
description = var.schemas_discoverer_description
52+
53+
tags = var.tags
54+
}
55+
4156
resource "aws_cloudwatch_event_rule" "this" {
4257
for_each = { for k, v in local.eventbridge_rules : v.name => v if var.create && var.create_rules }
4358

variables.tf

+12
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ variable "create_api_destinations" {
7070
default = false
7171
}
7272

73+
variable "create_schemas_discoverer" {
74+
description = "Controls whether default schemas discoverer should be created"
75+
type = bool
76+
default = false
77+
}
78+
7379
#######################
7480

7581
variable "bus_name" {
@@ -78,6 +84,12 @@ variable "bus_name" {
7884
default = "default"
7985
}
8086

87+
variable "schemas_discoverer_description" {
88+
description = "Default schemas discoverer description"
89+
type = string
90+
default = "Auto schemas discoverer event"
91+
}
92+
8193
variable "rules" {
8294
description = "A map of objects with EventBridge Rule definitions."
8395
type = map(any)

0 commit comments

Comments
 (0)