main.tf 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. locals {
  2. webhook_endpoint = "webhook"
  3. role_path = var.role_path == null ? "/${var.prefix}/" : var.role_path
  4. lambda_zip = var.lambda_zip == null ? "${path.module}/lambdas/webhook/webhook.zip" : var.lambda_zip
  5. }
  6. resource "aws_apigatewayv2_api" "webhook" {
  7. name = "${var.prefix}-github-action-webhook"
  8. protocol_type = "HTTP"
  9. tags = var.tags
  10. }
  11. resource "aws_apigatewayv2_route" "webhook" {
  12. api_id = aws_apigatewayv2_api.webhook.id
  13. route_key = "POST /${local.webhook_endpoint}"
  14. target = "integrations/${aws_apigatewayv2_integration.webhook.id}"
  15. }
  16. resource "aws_apigatewayv2_stage" "webhook" {
  17. lifecycle {
  18. ignore_changes = [
  19. // see bug https://github.com/terraform-providers/terraform-provider-aws/issues/12893
  20. default_route_settings,
  21. // not terraform managed
  22. deployment_id
  23. ]
  24. }
  25. api_id = aws_apigatewayv2_api.webhook.id
  26. name = "$default"
  27. auto_deploy = true
  28. tags = var.tags
  29. }
  30. resource "aws_apigatewayv2_integration" "webhook" {
  31. lifecycle {
  32. ignore_changes = [
  33. // not terraform managed
  34. passthrough_behavior
  35. ]
  36. }
  37. api_id = aws_apigatewayv2_api.webhook.id
  38. integration_type = "AWS_PROXY"
  39. connection_type = "INTERNET"
  40. description = "GitHub App webhook for receiving build events."
  41. integration_method = "POST"
  42. integration_uri = aws_lambda_function.webhook.invoke_arn
  43. }