Skip to content

Commit

Permalink
feat: Add option to enable access log for API gateway (#2387)
Browse files Browse the repository at this point in the history
Co-authored-by: Yuto Nakamura <maron07222010@gmail.com>
  • Loading branch information
ktaroabobon and yutyan0119 authored Sep 16, 2022
1 parent 5f28350 commit fcd9fba
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ In case the setup does not work as intended follow the trace of events:
| <a name="input_userdata_pre_install"></a> [userdata\_pre\_install](#input\_userdata\_pre\_install) | Script to be ran before the GitHub Actions runner is installed on the EC2 instances | `string` | `""` | no |
| <a name="input_userdata_template"></a> [userdata\_template](#input\_userdata\_template) | Alternative user-data template, replacing the default template. By providing your own user\_data you have to take care of installing all required software, including the action runner. Variables userdata\_pre/post\_install are ignored. | `string` | `null` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The VPC for security groups of the action runners. | `string` | n/a | yes |
| <a name="input_webhook_lambda_apigateway_access_log_settings"></a> [webhook\_lambda\_apigateway\_access\_log\_settings](#input\_webhook\_lambda\_apigateway\_access\_log\_settings) | n/a | <pre>object({<br> destination_arn = string<br> format = string<br> })</pre> | `null` | no |
| <a name="input_webhook_lambda_s3_key"></a> [webhook\_lambda\_s3\_key](#input\_webhook\_lambda\_s3\_key) | S3 key for webhook lambda function. Required if using S3 bucket to specify lambdas. | `any` | `null` | no |
| <a name="input_webhook_lambda_s3_object_version"></a> [webhook\_lambda\_s3\_object\_version](#input\_webhook\_lambda\_s3\_object\_version) | S3 object version for webhook lambda function. Useful if S3 versioning is enabled on source bucket. | `any` | `null` | no |
| <a name="input_webhook_lambda_timeout"></a> [webhook\_lambda\_timeout](#input\_webhook\_lambda\_timeout) | Time out of the webhook lambda in seconds. | `number` | `10` | no |
Expand Down
19 changes: 10 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,16 @@ module "webhook" {
sqs_build_queue_fifo = var.fifo_build_queue
github_app_webhook_secret_arn = module.ssm.parameters.github_app_webhook_secret.arn

lambda_s3_bucket = var.lambda_s3_bucket
webhook_lambda_s3_key = var.webhook_lambda_s3_key
webhook_lambda_s3_object_version = var.webhook_lambda_s3_object_version
lambda_runtime = var.lambda_runtime
lambda_architecture = var.lambda_architecture
lambda_zip = var.webhook_lambda_zip
lambda_timeout = var.webhook_lambda_timeout
logging_retention_in_days = var.logging_retention_in_days
logging_kms_key_id = var.logging_kms_key_id
lambda_s3_bucket = var.lambda_s3_bucket
webhook_lambda_s3_key = var.webhook_lambda_s3_key
webhook_lambda_s3_object_version = var.webhook_lambda_s3_object_version
webhook_lambda_apigateway_access_log_settings = var.webhook_lambda_apigateway_access_log_settings
lambda_runtime = var.lambda_runtime
lambda_architecture = var.lambda_architecture
lambda_zip = var.webhook_lambda_zip
lambda_timeout = var.webhook_lambda_timeout
logging_retention_in_days = var.logging_retention_in_days
logging_kms_key_id = var.logging_kms_key_id

# labels
enable_workflow_job_labels_check = var.runner_enable_workflow_job_labels_check
Expand Down
1 change: 1 addition & 0 deletions modules/webhook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ No modules.
| <a name="input_sqs_build_queue"></a> [sqs\_build\_queue](#input\_sqs\_build\_queue) | SQS queue to publish accepted build events. | <pre>object({<br> id = string<br> arn = string<br> })</pre> | n/a | yes |
| <a name="input_sqs_build_queue_fifo"></a> [sqs\_build\_queue\_fifo](#input\_sqs\_build\_queue\_fifo) | Enable a FIFO queue to remain the order of events received by the webhook. Suggest to set to true for repo level runners. | `bool` | `false` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Map of tags that will be added to created resources. By default resources will be tagged with name and environment. | `map(string)` | `{}` | no |
| <a name="input_webhook_lambda_apigateway_access_log_settings"></a> [webhook\_lambda\_apigateway\_access\_log\_settings](#input\_webhook\_lambda\_apigateway\_access\_log\_settings) | Access log settings for webhook API gateway. | <pre>object({<br> destination_arn = string<br> format = string<br> })</pre> | `null` | no |
| <a name="input_webhook_lambda_s3_key"></a> [webhook\_lambda\_s3\_key](#input\_webhook\_lambda\_s3\_key) | S3 key for webhook lambda function. Required if using S3 bucket to specify lambdas. | `any` | `null` | no |
| <a name="input_webhook_lambda_s3_object_version"></a> [webhook\_lambda\_s3\_object\_version](#input\_webhook\_lambda\_s3\_object\_version) | S3 object version for webhook lambda function. Useful if S3 versioning is enabled on source bucket. | `any` | `null` | no |
| <a name="input_workflow_job_labels_check_all"></a> [workflow\_job\_labels\_check\_all](#input\_workflow\_job\_labels\_check\_all) | If set to true all labels in the workflow job must match the GitHub labels (os, architecture and `self-hosted`). When false if __any__ label matches it will trigger the webhook. `enable_workflow_job_labels_check` must be true for this to take effect. | `bool` | `true` | no |
Expand Down
9 changes: 8 additions & 1 deletion modules/webhook/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ resource "aws_apigatewayv2_stage" "webhook" {
api_id = aws_apigatewayv2_api.webhook.id
name = "$default"
auto_deploy = true
tags = var.tags
dynamic "access_log_settings" {
for_each = var.webhook_lambda_apigateway_access_log_settings[*]
content {
destination_arn = access_log_settings.value.destination_arn
format = access_log_settings.value.format
}
}
tags = var.tags
}

resource "aws_apigatewayv2_integration" "webhook" {
Expand Down
9 changes: 9 additions & 0 deletions modules/webhook/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ variable "webhook_lambda_s3_object_version" {
default = null
}

variable "webhook_lambda_apigateway_access_log_settings" {
description = "Access log settings for webhook API gateway."
type = object({
destination_arn = string
format = string
})
default = null
}

variable "repository_white_list" {
description = "List of repositories allowed to use the github app"
type = list(string)
Expand Down
8 changes: 8 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ variable "webhook_lambda_s3_object_version" {
default = null
}

variable "webhook_lambda_apigateway_access_log_settings" {
type = object({
destination_arn = string
format = string
})
default = null
}

variable "runners_lambda_s3_key" {
description = "S3 key for runners lambda function. Required if using S3 bucket to specify lambdas."
default = null
Expand Down

0 comments on commit fcd9fba

Please sign in to comment.