terraform-aws-modules / terraform-aws-apigateway-v2

Terraform module to create AWS API Gateway v2 (HTTP/WebSocket) 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/apigateway-v2/aws
Apache License 2.0
144 stars 188 forks source link

Allow Module manage existing API Gateway #39

Closed fdmsantos closed 2 years ago

fdmsantos commented 3 years ago

Is your request related to a new offering from AWS?

No.

Is your request related to a problem? Please describe.

I Would like have the possibility to manage the Routes/Integrations separately from API Gateway Creation. Example, I have 3 ECS different services, managed in different terraform tfstates. All these 3 ECS services will integrate with the Same API Gateway. So i would like create API Gateway, and in ECS Services reference the API Gateway ID and create the integration. If i want delete one ECS service, the only thing I need to do is terraform destroy in ECS service stack and the API Route/Integration will be removed, but the API Gateway and the other 2 Route/Integrations continues existing. Without this, if i want remove an ECS service, i need to do terraform destroy in ECS Service stack and remove the Route/Integration from API Gateway Terraform code run an update in the API Gateway stack.

Describe the solution you'd like.

Have a new variable api_gw_id. If the create_api_gateway is equal to false, and create_routes_and_integrations is equal true, the module will use api_gw_id variable to create the route integrations.

Describe alternatives you've considered.

N/A

Additional context

N/A

If this makes sense for you, i can submit a pull request with this feature.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

github-actions[bot] commented 2 years ago

This issue was automatically closed because of stale in 10 days

CumpsD commented 1 year ago

Looking for this as well

CumpsD commented 1 year ago

Solved it right now with

resource "aws_apigatewayv2_integration" "this" {
  for_each = var.create_routes_and_integrations ? var.integrations : {}

  api_id      = !var.create && var.create_routes_and_integrations ? var.apigateway_id : aws_apigatewayv2_api.this[0].id

and similar changes on other places

antonbabenko commented 1 year ago

It sounds like a good idea, but maintaining this feature as part of the resource module is a very large amount of work that we don't want to do. Almost all terraform-aws-modules create at least the core resources (API GW, in the case of this module) and attach other resources to it (optionally).

Terraform does not allow us to write really flexible code that will support use-cases like this that we can easily maintain.

CumpsD commented 1 year ago

Isn't it just the above change to support it? for the integrations, routes and authorizers + the variable itself

antonbabenko commented 1 year ago

Yes, it is a start, but then someone would like to reuse the externally created resources, like domain name (aws_apigatewayv2_domain_name) or other resources. The code will have to grow rather quickly.

CumpsD commented 1 year ago

Ok, I'll just update my local copy each time ;)

github-actions[bot] commented 1 year ago

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.