Skip to content

Commit 2f509fe

Browse files
committed
pass allowed events to lambda
1 parent 2f8eebc commit 2f509fe

File tree

9 files changed

+36
-9
lines changed

9 files changed

+36
-9
lines changed

examples/multi-runner/main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ module "runners" {
8080

8181
# Deploy webhook in EventBridge mode
8282
webhook_mode = "eventbridge"
83+
# adjust the allow events to only allow specific events, like workflow_job
84+
# eventbridge_allowed_events = ['workflow_job']
8385

8486
# enable this section for tracing
8587
# tracing_config = {

main.tf

+3-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ module "ssm" {
124124
module "webhook" {
125125
source = "./modules/webhook"
126126

127-
mode = var.webhook_mode
127+
mode = var.webhook_mode
128+
eventbridge_allowed_events = var.eventbridge_allowed_events
129+
128130
ssm_paths = {
129131
root = local.ssm_root_path
130132
webhook = var.ssm_paths.webhook

modules/multi-runner/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ variable "webhook_mode" {
283283
}
284284
}
285285

286+
variable "eventbridge_allowed_events" {
287+
description = "List of events that are allowed (accepted) to be sent to the eventbridge by the webhook. Variable only have effect if `webhook_mode` is set to `eventbridge`."
288+
type = list(string)
289+
default = []
290+
}
291+
286292
variable "webhook_lambda_s3_key" {
287293
description = "S3 key for webhook lambda function. Required if using S3 bucket to specify lambdas."
288294
type = string

modules/multi-runner/webhook.tf

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
module "webhook" {
2-
source = "../webhook"
3-
prefix = var.prefix
4-
tags = local.tags
5-
mode = var.webhook_mode
6-
kms_key_arn = var.kms_key_arn
2+
source = "../webhook"
3+
prefix = var.prefix
4+
tags = local.tags
5+
mode = var.webhook_mode
6+
eventbridge_allowed_events = var.eventbridge_allowed_events
7+
kms_key_arn = var.kms_key_arn
78

89
runner_matcher_config = local.runner_config
910
matcher_config_parameter_store_tier = var.matcher_config_parameter_store_tier

modules/webhook/eventbridge/variables.tf

+1
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@ variable "config" {
5050
arn = string
5151
version = string
5252
})
53+
allowed_events = optional(list(string), [])
5354
})
5455
}

modules/webhook/eventbridge/webhook.tf

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ resource "aws_lambda_function" "webhook" {
2121
POWERTOOLS_TRACE_ENABLED = var.config.tracing_config.mode != null ? true : false
2222
POWERTOOLS_TRACER_CAPTURE_HTTPS_REQUESTS = var.config.tracing_config.capture_http_requests
2323
POWERTOOLS_TRACER_CAPTURE_ERROR = var.config.tracing_config.capture_error
24-
PARAMETER_GITHUB_APP_WEBHOOK_SECRET = var.config.github_app_parameters.webhook_secret.name
25-
PARAMETER_RUNNER_MATCHER_CONFIG_PATH = var.config.ssm_parameter_runner_matcher_config.name
26-
EVENT_BUS_NAME = aws_cloudwatch_event_bus.main.name
24+
# Parameters required for lambda configuration
25+
ALLOWED_EVENTS = jsonencode(var.config.allowed_events)
26+
EVENT_BUS_NAME = aws_cloudwatch_event_bus.main.name
27+
PARAMETER_GITHUB_APP_WEBHOOK_SECRET = var.config.github_app_parameters.webhook_secret.name
28+
PARAMETER_RUNNER_MATCHER_CONFIG_PATH = var.config.ssm_parameter_runner_matcher_config.name
2729
} : k => v if v != null
2830
}
2931
}

modules/webhook/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,9 @@ variable "mode" {
220220
error_message = "`mode` value is not valid, valid values are: `direct`, and `eventbridge`."
221221
}
222222
}
223+
224+
variable "eventbridge_allowed_events" {
225+
description = "List of events that are allowed (accepted) to be sent to the eventbridge by the webhook."
226+
type = list(string)
227+
default = []
228+
}

modules/webhook/webhook.tf

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ module "eventbridge" {
8484
lambda_tags = var.lambda_tags,
8585
api_gw_source_arn = "${aws_apigatewayv2_api.webhook.execution_arn}/*/*/${local.webhook_endpoint}"
8686
ssm_parameter_runner_matcher_config = aws_ssm_parameter.runner_matcher_config
87+
allowed_events = var.eventbridge_allowed_events
8788
}
8889

8990
}

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -955,3 +955,9 @@ variable "webhook_mode" {
955955
error_message = "`mode` value is not valid, valid values are: `direct`, and `eventbridge`."
956956
}
957957
}
958+
959+
variable "eventbridge_allowed_events" {
960+
description = "List of events that are allowed (accepted) to be sent to the eventbridge by the webhook. Variable only have effect if `webhook_mode` is set to `eventbridge`."
961+
type = list(string)
962+
default = []
963+
}

0 commit comments

Comments
 (0)