Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_apigatewayv2_route is missing support for request parameters #18387

Closed
pedrodbsa opened this issue Mar 24, 2021 · 5 comments · Fixed by #18410
Closed

aws_apigatewayv2_route is missing support for request parameters #18387

pedrodbsa opened this issue Mar 24, 2021 · 5 comments · Fixed by #18410
Assignees
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/apigatewayv2 Issues and PRs that pertain to the apigatewayv2 service.
Milestone

Comments

@pedrodbsa
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

aws_apigatewayv2_route is missing the ability to configure request parameters as can be seen in this example: https://docs.aws.amazon.com/apigateway/latest/developerguide/websocket-api-data-mapping.html#websocket-data-mapping-examples

This makes forwarding headers (like Authorization) to an HTTP_PROXY integration fail with following error:

Error: error updating API Gateway v2 integration: BadRequestException: Error while validating the connection between the integration <integration_id> and the route <route_id>: Invalid mapping expression parameter specified: route.request.header.authorization

The only way to get this to work is by temporarily apply the configuration without the header forwarding request parameters, manually add the request parameters to the route using something like
aws apigatewayv2 update-route --route-id <route-id>--api-id <api-id> --request-parameters '{"route.request.header.authorization": {"Required": false}}' and then re-apply the configuration with the header forwarding in place.

New or Affected Resource(s)

  • aws_apigatewayv2_route

Potential Terraform Configuration

resource "aws_apigatewayv2_api" "example" {
  name                       = "example"
  protocol_type              = "WEBSOCKET"
  route_selection_expression = "$request.body.action"
}

resource "aws_apigatewayv2_route" "connect" {
  api_id = aws_apigatewayv2_api.example.id

  route_key                           = "$connect"
  route_response_selection_expression = "$default"

  request_parameters = {
    "route.request.header.authorization" = true
  }

  target = "integrations/${aws_apigatewayv2_integration.connect.id}"
}

resource "aws_apigatewayv2_integration" "connect" {
  api_id = aws_apigatewayv2_api.example.id

  integration_type   = "HTTP_PROXY"
  integration_method = "ANY"
  integration_uri    = var.integration_uri

  request_parameters = {
    "integration.request.header.authorization" = "route.request.header.authorization"
    "integration.request.header.connectionId"  = "context.connectionId"
  }
}

References

@pedrodbsa pedrodbsa added the enhancement Requests to existing resources that expand the functionality or scope. label Mar 24, 2021
@ghost ghost added the service/apigatewayv2 Issues and PRs that pertain to the apigatewayv2 service. label Mar 24, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Mar 24, 2021
@ewbankkit ewbankkit removed the needs-triage Waiting for first response or review from a maintainer. label Mar 25, 2021
@ewbankkit ewbankkit self-assigned this Mar 25, 2021
@ewbankkit
Copy link
Contributor

Given the structure of the underlying AWS API, I suggest a slightly more complex configuration syntax:

resource "aws_apigatewayv2_route" "connect" {
  api_id = aws_apigatewayv2_api.example.id

  route_key                           = "$connect"
  route_response_selection_expression = "$default"

  request_parameter {
    request_parameter_key = "route.request.header.authorization"
    required              = true
  }

  target = "integrations/${aws_apigatewayv2_integration.connect.id}"
}

@pedrodbsa
Copy link
Author

Looks perfectly fine to me.

My suggestion was based on this one https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method#request_parameters but to be honest I wouldn't be able to say if it fits or not - was mainly for consistency sake.

@ewbankkit
Copy link
Contributor

ewbankkit commented Mar 25, 2021

The underlying problem is that the current Plugin SDK does not support maps with values anything other than simple types:

https://github.com/hashicorp/terraform-plugin-sdk/blob/b5604678a4d0326c5c94366bb89bb7d3ad06bc29/helper/schema/schema.go#L790-L796

AWS has the map value for a request parameter as a struct (which today only has one field, required, but we don't want to get into a situation where AWS adds another field to this structure and we can't easily project that onto provider attributes).
This is similar to the situation with aws_apigatewayv2_stage.route_settings.

@ghost
Copy link

ghost commented Apr 1, 2021

This has been released in version 3.35.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented May 1, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators May 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/apigatewayv2 Issues and PRs that pertain to the apigatewayv2 service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants