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

API Gateway- Websocket #7004

Closed
bbernays opened this issue Dec 30, 2018 · 76 comments
Closed

API Gateway- Websocket #7004

bbernays opened this issue Dec 30, 2018 · 76 comments
Labels
new-resource Introduces a new resource. service/apigatewayv2 Issues and PRs that pertain to the apigatewayv2 service.
Milestone

Comments

@bbernays
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 "me too" comments, 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

API Gateway now supports WebSocket connections. It would be great to be able to define this resource

New or Affected Resource(s)

  • aws_api_gateway_v2
  • aws_api_gateway_v2_route
  • aws_api_gateway_v2_integration
  • aws_api_gateway_v2_integration_response
  • aws_api_gateway_v2_route_response
  • aws_api_gateway_v2_deployment
  • aws_api_gateway_v2_stage

Potential Terraform Configuration

#Incomplete!!
resource "aws_api_gateway_v2" "websocket" {
  name = "myWebSocketApi3"
  description    = "${format("CMS V2 %s", var.environment)}"
  protocol_type = "WEBSOCKET"
  route_selection_expression = "$request.body.action'"
}
resource "aws_api_gateway_v2_route" "non_default_route" {
  api_id = "${aws_api_gateway_v2.websocket.id}"
  routeKey = "testing"
}

References

@bflad bflad added new-resource Introduces a new resource. service/apigatewayv2 Issues and PRs that pertain to the apigatewayv2 service. labels Jan 3, 2019
@mbonig
Copy link
Contributor

mbonig commented Jan 3, 2019

I'd like to contribute to this, but have never done any development on this project before. Can we explain a little further the changes that are needed?

 . didn't notice before that AWS did the new api...

Either way, I'll try submitting a PR...

@bbernays
Copy link
Author

bbernays commented Jan 3, 2019

I suggested that it be _v2 to stay inline with AWS naming of the new resource. Link here

@mbonig
Copy link
Contributor

mbonig commented Jan 7, 2019

I've created a fork and made some changes to support the first new 'v2' resource. Anyone care to review and let me know things I got wrong before implementing the rest?

https://github.com/mbonig/terraform-provider-aws/tree/f-gatewayv2

Thanks!

@mbonig
Copy link
Contributor

mbonig commented Jan 9, 2019

Additional affected resources:

  • aws_api_gateway_v2_authorizer

@krotscheck
Copy link

Also affected: aws_api_gateway_domain_name - may need a new resource, I'm not familiar with the underlying api.

@mbonig
Copy link
Contributor

mbonig commented Jan 31, 2019

I'm working on this, but on the route object I've come across an issue. I want the terraform to look like this:

resource "aws_api_gateway_v2_route" "test_route" {
   ...
   request_parameters {
       "asdf.asdf.asdf.asdf" {
          required=true
       }
   }
}

as this seems to be the best representation of the underlying data. However, I can't seem to find a schema definition that will work with this. Does anybody have any tips, or can point me to an existing resource that has a similar setup?

API reference:
https://docs.aws.amazon.com/sdk-for-go/api/service/apigatewayv2/#CreateRouteInput

@garrett-hopper
Copy link

Has there been any update on this? I'm willing to help with testing PRs.

@mbonig
Copy link
Contributor

mbonig commented Mar 12, 2019

I have had priorities shift so I haven't been able to work on it. Would be willing to give someone my branch if they want to continue my work...

@sidewaiise
Copy link

sidewaiise commented May 21, 2019

@mbonig I'd be happy to contribute. What's the turnaround time for PR / Testing / Approval? I need this feature actually in the next couple of weeks.

@c1moore
Copy link

c1moore commented May 28, 2019

Has there been any progress on this issue? It looks like it's the second most popular issue. @mbonig could you post your work so somebody else can pick up from it? (Is this it: https://github.com/mbonig/terraform-provider-aws/tree/f-gatewayv2?)

@ewbankkit
Copy link
Contributor

ewbankkit commented Jun 3, 2019

I have made a start on this, based on the initial work from @mbonig. I think a separate PR for each new resource is best:

@rpstreef
Copy link

Is there an ETA when this will be released?

@ewbankkit
Copy link
Contributor

I think we need to decide on the set of resources that comprise an "MVP" and focus on those - @rpstreef, what would be the minimal set of resources for your use case(s)? Thanks.

@rpstreef
Copy link

I wont be using;
aws_api_gateway_v2_api_mapping
aws_api_gateway_v2_model
aws_api_gateway_v2_domain_name

When you use proxy integration, these are not needed
aws_api_gateway_v2_integration_response
aws_api_gateway_v2_route_response

Everything else is MVP in my opinion

@ewbankkit
Copy link
Contributor

ewbankkit commented Jun 27, 2019

API Gateway v2 tagging added in AWS SDK v1.20.9.
Requires:

@ewbankkit
Copy link
Contributor

ewbankkit commented Jul 1, 2019

Tags are supported on:

  • aws_api_gateway_v2_api
  • aws_api_gateway_v2_domain_name
  • aws_api_gateway_v2_stage

Announcement.

@rpstreef
Copy link

rpstreef commented Jul 3, 2019

Is there an ETA when this will be released?

for the MVP, do we have an ETA?

@ewbankkit
Copy link
Contributor

ewbankkit commented Jul 14, 2019

OK, I think I have the resources for @rpstreef's MVP done.
The PR will need to be reviewed and merged in the following order with PRs in later phases rebased:

Phase 1

Phase 2

Phase 3

Phase 4

Phase 5

Phase 6

I will need to add to the Example Usage sections in the relevant documentation and provide full examples in https://github.com/terraform-providers/terraform-provider-aws/tree/master/examples.

Added api-gateway-websocket-chat-app example based on the AWS Serverless Application Model simple-websockets-chat-app - #9533.

@ebarault
Copy link

ebarault commented Apr 7, 2020

@ewbankkit many thanks for pushing all this through!

do you happen to have a single branch where all the feature branches regarding api_gateway_v2 are all merged in ?
I'm currently compiling the aws provider from your different branches and it will be easier to test by building only one provider gathering all the new features.

@ebarault
Copy link

Splendid !
3 new ressources are available as of today:
aws_apigatewayv2_authorizer
aws_apigatewayv2_integration
aws_apigatewayv2_model

@ebarault
Copy link

ebarault commented Apr 10, 2020

hi @ewbankkit, @maryelizbeth,

the module aws_apigatewayv2_api creates 3 routes by default (they actually get created automatically by aws)
$default
$connect
$disconnect

but the module does not export in its outputs the RouteId key for each of those routes, and we don't have a data source to retrieve them

Hence, when the module aws_apigatewayv2_route will be released, we won't be able to update the default routes with their target integrations.

How would you see the next step here?

  • A data source to get the routes by name?
  • Adding the default routes ids as outputs of the api module ?

@ewbankkit
Copy link
Contributor

@ebarault When a WebSocket API is created via Terraform those 3 routes aren't created implicitly:

$ terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  + aws_apigatewayv2_api.test
      id:                           <computed>
      api_endpoint:                 <computed>
      api_key_selection_expression: "$request.header.x-api-key"
      arn:                          <computed>
      execution_arn:                <computed>
      name:                         "example-ws-api"
      protocol_type:                "WEBSOCKET"
      route_selection_expression:   "$request.body.action"


Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_apigatewayv2_api.test: Creating...
  api_endpoint:                 "" => "<computed>"
  api_key_selection_expression: "" => "$request.header.x-api-key"
  arn:                          "" => "<computed>"
  execution_arn:                "" => "<computed>"
  name:                         "" => "example-ws-api"
  protocol_type:                "" => "WEBSOCKET"
  route_selection_expression:   "" => "$request.body.action"
aws_apigatewayv2_api.test: Creation complete after 1s (ID: p5axu0jzmb)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
kit@ub18043x64-dev:~/tmp/apigatewayv2$ aws --region us-west-2 apigatewayv2 get-routes --api-id p5axu0jzmb
{
    "Items": []
}

but they do show up in the AWS console (albeit subtly grayed out) and no doubt there will be many users who click on those routes, which does cause their implicit creation (and also additional integrations etc.). So, yes we should add data sources for all corresponding the API Gateway v2 resources - Phase 2 😄.

@Ludonope
Copy link

I find the name credentials_arn confusing in aws_apigatewayv2_integration.
Shouldn't it be execution_role instead?

@ebarault
Copy link

@ewbankkit ohhhh that's twisted! i just destroyed my apigw_v2, recreated it, and a call to aws apigatewayv2 get-routes --api-id xxxxxxxxx confirms that there is no route created by default.

As soon as i click on one of those + signs, a route gets created:
image

@ebarault
Copy link

@Ludonope the name comes from aws:
https://docs.aws.amazon.com/cli/latest/reference/apigatewayv2/create-integration.html

@ewbankkit
Copy link
Contributor

@Ludonope As @ebarault mentions, we aim to maintain fidelity with the underlying AWS API. If you feel the documentation can be clearer, please open a linked issue. Thanks.

@gdavison gdavison added this to the v2.59.0 milestone Apr 17, 2020
@christhomas
Copy link

When I create a new "aws_apigatewayv2_api" and "aws_apigatewayv2_domain_name" I'm not given any hosted zone or domain name information like I do with version 1.

How am I supposed to connect this api to a route53 record and use it? There doesn't appear to be any information in the documentation about how I could do this either.

@ewbankkit
Copy link
Contributor

@christhomas Thanks for raising this - Route 53 hosted zone and API Gateway domain name are available from the underlying AWS GetDomainName API.
Could you please open a separate issue for this and we should be able to address promptly.

@ebarault
Copy link

cross-referencing the aforementioned issue: #12892

@christhomas
Copy link

I also think this issue should be cross-referenced too: #12894

@ewbankkit
Copy link
Contributor

#9461 was the final PR for new resources. I think we'll need data sources corresponding to some of the API Gateway v2 resources, but @bflad, @maryelizbeth do you want to close this issue now and open separate issues for additional work?

@gdavison
Copy link
Contributor

Hello everyone,

All of the functionality linked to this Issue has either been released, or will be released as part of v2.59.0 later this week. Namely, the resource types

  • aws_apigatewayv2_api
  • aws_apigatewayv2_api_mapping
  • aws_apigatewayv2_authorizer
  • aws_apigatewayv2_deployment
  • aws_apigatewayv2_domain_name
  • aws_apigatewayv2_integration
  • aws_apigatewayv2_integration_response
  • aws_apigatewayv2_model
  • aws_apigatewayv2_route
  • aws_apigatewayv2_route_response
  • aws_apigatewayv2_stage

which support ApiGateway v2 WebSocket APIs. Follow #11148 for the enhancements needed for HTTP APIs.

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

@jacktkeys
Copy link

I have had a couple of observations the last couple of days trying to implement API Gateway V2 in Terraform.

  1. aws_apigatewayv2_api is missing the CORS configuration block
  2. There is no implementation of a VPC link for v2.

I created a functioniong API gateway in the console pointing to an internal ALB. I went to list all of the resources in the AWS cli. Everything was there except for the VPC link. I upgraded AWS cli to verison 1.18.41 and now the apigatewayv2 subcommand has references to vpc link.

@ewbankkit
Copy link
Contributor

ewbankkit commented Apr 21, 2020

@jacktkeys aws_apigatewayv2_api CORS support has been implemented in #12452 and new resource aws_apigatewayv2_vpc_link has been implemented in #12577.
Both PRs have been merged and will be released with provider v2.59.0.

@jacktkeys
Copy link

@ewbankkit Thanks for pointing me to those. I look forward to the next release then.

@christhomas
Copy link

christhomas commented Apr 22, 2020

I really really really want api_mapping right now, it's what is causing my final problem on this ticket: #12892

When is the release date?

@christhomas
Copy link

There is an issue with deployments that I've found, it's a bit tricky to explain, I've created a ticket to try to get what I think is happening across: #12961

@ghost
Copy link

ghost commented Apr 24, 2020

This has been released in version 2.59.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 21, 2020

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 and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource Introduces a new resource. service/apigatewayv2 Issues and PRs that pertain to the apigatewayv2 service.
Projects
None yet
Development

No branches or pull requests