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

New data source: aws_apigatewayv2_stage #12957

Open
ewbankkit opened this issue Apr 22, 2020 · 2 comments
Open

New data source: aws_apigatewayv2_stage #12957

ewbankkit opened this issue Apr 22, 2020 · 2 comments
Labels
new-data-source Introduces a new data source. service/apigatewayv2 Issues and PRs that pertain to the apigatewayv2 service.

Comments

@ewbankkit
Copy link
Contributor

ewbankkit commented Apr 22, 2020

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

Add a new data source for a single API Gateway v2 Stage (HTTP or WebSocket API).

Arguments could be:

  • api_id
  • stage_id
  • name
  • tags

New or Affected Resource(s)

  • aws_apigatewayv2_stage

Potential Terraform Configuration

data "aws_apigatewayv2_stage" "example" {
  api_id = "abcd1234"
  name   = "$default"
}

References

Related:

@ewbankkit ewbankkit added the enhancement Requests to existing resources that expand the functionality or scope. label Apr 22, 2020
@ghost ghost added the service/apigatewayv2 Issues and PRs that pertain to the apigatewayv2 service. label Apr 22, 2020
@jovana
Copy link

jovana commented Nov 23, 2021

Hi,

Running the aws_apigatewayv2_api_mapping to create a mapping is not possible anymore. Because we can not create or retrieve the $default stage. Because while running aws_apigatewayv2_api is already create the $default stage for you. So creating the mapping using your domain, stage and API id is not possible, without knowing the stage id.

So the below code failed (create API, Stage and Mapping):

resource "aws_apigatewayv2_api" "this" {
  name          = "${var.application_name}-${terraform.workspace}-api-gateway"
  protocol_type = "HTTP"
  description   = "API end point for ${var.application_name}-${terraform.workspace}"
  target        = aws_lambda_function.api_backend.invoke_arn
  cors_configuration {
    allow_headers = ["*"]
    allow_methods = ["*"]
    allow_origins = [
      "https://${var.prefix}${var.website_name}",
      replace("https://${format("${var.prefix}%s", trimprefix(var.website_name, "www."))}", "-", ".")
    ]
  }
}

resource "aws_apigatewayv2_stage" "this" {
  api_id      = aws_apigatewayv2_api.this.id
  name        = "$default"
  auto_deploy = true
}

resource "aws_apigatewayv2_api_mapping" "this" {
  api_id      = aws_apigatewayv2_api.this.id
  domain_name = aws_apigatewayv2_domain_name.this.id
  stage       = aws_apigatewayv2_stage.this.id
}

Error output:

│ Error: error creating API Gateway v2 stage: ConflictException: Stage already exists
│ 
│   on aws_api-gateway.tf line 27, in resource "aws_apigatewayv2_stage" "this":
│   27: resource "aws_apigatewayv2_stage" "this" {

The workaround for this is:

resource "aws_apigatewayv2_api_mapping" "this" {
  api_id      = aws_apigatewayv2_api.this.id
  domain_name = aws_apigatewayv2_domain_name.this.id
  stage       = "$default"
}

@DrFaust92 DrFaust92 added new-data-source Introduces a new data source. and removed enhancement Requests to existing resources that expand the functionality or scope. labels Feb 14, 2022
@TxusBlack
Copy link

Any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-data-source Introduces a new data source. service/apigatewayv2 Issues and PRs that pertain to the apigatewayv2 service.
Projects
None yet
Development

No branches or pull requests

4 participants