2

Amazon released HTTP APIs for their api gateway product fairly recently, and I'd like to use Terraform to spin some up. I saw that Terraform has documentation for the aws_apigatewayv2_api resource, which will create the gateway itself, but I can't find documentation for routes, stages, or any other types of resources that I'll be needing in my gateway.

Are HTTP APIs just not fully supported by Terraform yet, or am I missing some documentation somewhere?

1
  • Wanted to do the same, seems it is not supported as posted by the user below. We have to use V1 with REST API's Commented Mar 31, 2020 at 17:26

2 Answers 2

5

Update:

Per the closing comment on issue #11148, the AWS API Gateway HTTP API resources were first generally supported in terraform-aws-provider starting in v3.3.0. Later releases have already added new functionality.

Historical answer:

Indeed, it looks like the Terraform AWS provider does not yet support all of the resources necessary for an API Gateway HTTP API.

The aws_apigatewayv2_api resource was released on March 12, 2020 in terraform-provider-aws 2.53.0, but implementations of resources such as aws_apigatewayv2_route, aws_apigatewayv2_stage, and aws_apigatewayv2_integration have yet to be merged.

terraform-provider-aws issue #11148 has links to pending pull requests for the new resources.

Sign up to request clarification or add additional context in comments.

1 Comment

Everything is now available! Anyone wanting to use the http v2 resources should see the answer below
2

Everything you need to use http v2 apis is now available in terraform. There is a good tutorial on creating them here.

Essentially, for a simple gateway+lambda combo you want something like this:

# Lambda function
resource "aws_lambda_function" "lambda" {
    # ...
}

# HTTP API
resource "aws_apigatewayv2_api" "api" {
    name          = "api-${random_id.id.hex}"
    protocol_type = "HTTP"
    target        = aws_lambda_function.lambda.arn
}

# Permission
resource "aws_lambda_permission" "apigw" {
    action        = "lambda:InvokeFunction"
    function_name = aws_lambda_function.lambda.arn
    principal     = "apigateway.amazonaws.com"

    source_arn = "${aws_apigatewayv2_api.api.execution_arn}/*/*"
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.