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

Import an API into API Gateway from a Swagger #11034

Closed
n-my opened this issue Jan 4, 2017 · 9 comments
Closed

Import an API into API Gateway from a Swagger #11034

n-my opened this issue Jan 4, 2017 · 9 comments

Comments

@n-my
Copy link

n-my commented Jan 4, 2017

Context

The AWS API let us import an API from a JSON Swagger (v2.0) (see here and here)

It would be nice to support this feature in Terraform. This has been already asked in #3675 but it was not the original request of the issue.

As a note :
The API Gateway extensions to the Swagger specification support the AWS-specific authorization and API Gateway-specific API integrations (see here)

Potential solutions

We could either use directly JSON files or use a data source aws_api_swagger to store to swagger.
Then we could update the resource aws_api_gateway_rest_api to specifiy a swagger.

@n-my n-my changed the title Import an API into API Gateway from a swagger file Import an API into API Gateway from a Swagger Jan 4, 2017
@MarechJ
Copy link

MarechJ commented Jan 16, 2017

+1

@9bryan
Copy link

9bryan commented Feb 2, 2017

+1
Is there a way to find out if this is on the roadmap?

@richarddevers
Copy link

+1

@Vinnl
Copy link

Vinnl commented Feb 25, 2017

I stumbled into this while looking for something unrelated, but it looks like #6175 is looking to implement this.

(As for the other commenters: you can press the Thumbs Up on the original post to +1, that saves some redundant emails.)

@stack72
Copy link
Contributor

stack72 commented Mar 29, 2017

Hi @n-my

Hi @timmytofu

Thanks so much for the request!

Sorry we took so long to get back to you. While we'd love to see something like this, we don't currently have any plans to implement this ourselves. Until then, this issue is unlikely to see any movement and remain stale. We're trying to prune the stale issues (that aren't going to be addressed anytime soon) by closing them. Note that we only do this for enhancement requests and not bugs.

If you are still interested in this feature being part of Terraform, then we would gladly review a Pull Request.

Thanks

@stack72

@stack72 stack72 closed this as completed Mar 29, 2017
@combinatorist
Copy link

combinatorist commented Jun 14, 2017

I spent a couple weeks trying to get this to work before I found out terraform isn't supporting it. IMO, terraform needs a "doesn't really support API Gateway" on the front page / README.

If anyone has found a way to actually use API Gateway from terraform in production (without lots of manual setup), I'd love to pick your brain. Right now, I'm forced to consider alternatives like serverless, Zappa, or CloudFormation.

@gtmtech
Copy link

gtmtech commented Jun 28, 2017

@combinatorist , you could use a null resource with an aws cli call to upload swagger json as a workaround - I think that's what I'll try, I just came across this issue too. Also in the worst case, you could use a cloudformation template from within terraform.

@combinatorist
Copy link

combinatorist commented Jul 12, 2017

Thanks for the suggestion, @gtmtech. FWIW, I'm not as concerned about Swagger as I am about stateless support for AWS API Gateway (more below).

So, in case anyone else is curious, here's my more general solution to a more general problem. And please, if anyone knows better than I do, jump into correct me.

API State (and Swagger)

I got the impression terraform doesn't actually support AWS API Gateway, but the fundamental issue is that AWS API Gateway is stateful - i.e. it cannot report out its complete, exact current state to terraform, so terraform can't know whether it needs to be modified, rebuilt, or left alone. I suspect this may also be why you have to set some of your own manual terraform dependencies to work with API Gateway.

The biggest advantage of Swagger (for me) would be a complete stateless description of the API, but I don't think AWS is doing it's part, so there'd still be no way to know exactly how it connects to the rest of your AWS infrastructure (e.g. your lambda functions).

So, you may have to terraform taint your API every time you want to update it, but this is guesswork and it may have to rebuild the CloudFront Distribution (CDN) which AWS API Gateway hides under the hood (and this can take a long time). Finally, all the stages in a single AWS API Gateway share the same pre-deployment version of the API so you can't be sure what you're deploying when you make a new deployment (particularly if other team members change state).

But I really wanted separation of environments, so I don't let AWS API Gateway manage my "stages".

My solution

So, I actually create a separate AWS API per stage (which correspond to my terraform environments). Unfortunately, because AWS API Gateway silently includes its own CloudFront distribution, I ultimately have to have a separate subdomain for each environment / stage of the API like so:

  • api.example.com (prod)
  • dev.api.example.com
  • test.api.example.com

These are all variations of the same (logical) API, but they have different subdomains with different CloudFront distributions, built into separate AWS API Gateways, with separate variations of the same (logical) lambda functions and DynamoDB table.

@ghost
Copy link

ghost commented Apr 8, 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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants