In console, you have to "attach" the authorizer to a route. How is this achieved in TF?
HTTP API Gateway - How to map authorizer to route in Terraform?
861 Views Asked by Em Ma At
2
There are 2 best solutions below
0
On
resource "aws_apigatewayv2_api" "service_http_api" {
name = var.name
description = var.description
tags = var.tags
protocol_type = "HTTP"
}
resource "aws_apigatewayv2_authorizer" "authorizer" {
api_id = aws_apigatewayv2_api.service_http_api.id
authorizer_type = "JWT"
identity_sources = ["$request.header.Authorization"]
name = "AuthName"
jwt_configuration {
audience = [var.open_id_audience]
issuer = var.open_id_issuer
}
}
resource "aws_apigatewayv2_integration" "function" {
api_id = aws_apigatewayv2_api.service_http_api.id
integration_type = "AWS_PROXY"
connection_type = "INTERNET"
integration_method = "POST"
integration_uri = var.function_arn
payload_format_version = "2.0"
}
resource "aws_apigatewayv2_route" "route" {
api_id = aws_apigatewayv2_api.service_http_api.id
authorizer_id = aws_apigatewayv2_authorizer.authorizer.id
target = "integrations/${aws_apigatewayv2_integration.function.id}"
authorization_type = "JWT"
route_key = "/route/"
}