I am creating a terraform script for Amazon API Gateway Version 2 using terraform, using HTTP protocol type. I am not able to figure out how to link the gateway route with the integration. I have tried using the "target" attribute in "aws_apigatewayv2_route" but its not working. Below is the code I have written for it.
resource "aws_apigatewayv2_api" "mrw-api" {
name = "mrw-http-api"
protocol_type = "HTTP"
}
resource "aws_apigatewayv2_vpc_link" "mrw-link" {
name = "mrw-link"
security_group_ids = [data.aws_security_group.mrw-sg.id]
subnet_ids = [data.aws_subnet.mrw-subnet.id, data.aws_subnet.mrw-subnet2.id]
}
resource "aws_apigatewayv2_route" "healthcheck" {
api_id = aws_apigatewayv2_api.mrw-api.id
route_key = "GET /"
target = aws_apigatewayv2_integration.mrw-int-get.id
}
resource "aws_apigatewayv2_integration" "mrw-int-get" {
api_id = aws_apigatewayv2_api.mrw-api.id
integration_type = "HTTP_PROXY"
connection_type = "VPC_LINK"
connection_id = aws_apigatewayv2_vpc_link.mrw-link.id
integration_uri = aws_lb_listener.mrw-lb-listener.arn
integration_method = "GET"
tls_config {
server_name_to_verify = var.tls_server_name
}
}
Can anyone help on how to link the route with the integration.
Terraform's documentation for this isn't very clear. The format for target
is integrations/integration-id
. In your case, use "integrations/${aws_apigatewayv2_integration.mrw-int-get.id}"