Terraform: Error when creating a new aws api gateway with a deployment

Created on 11 Jul 2016  路  7Comments  路  Source: hashicorp/terraform

Terraform Version

Terraform v0.6.16

Affected Resource(s):

  • aws_api_gateway_rest_api
  • aws_api_gateway_deployment

    Terraform Configuration Files

resource "aws_api_gateway_rest_api" "MyDemoAPI" {
  name = "MyDemoAPI"
  description = "This is my API for demonstration purposes"
}

resource "aws_api_gateway_resource" "MyDemoResource" {
  rest_api_id = "${aws_api_gateway_rest_api.MyDemoAPI.id}"
  parent_id = "${aws_api_gateway_rest_api.MyDemoAPI.root_resource_id}"
  path_part = "mydemoresource"
}

resource "aws_api_gateway_method" "MyDemoMethod" {
  rest_api_id = "${aws_api_gateway_rest_api.MyDemoAPI.id}"
  resource_id = "${aws_api_gateway_resource.MyDemoResource.id}"
  http_method = "GET"
  authorization = "NONE"
}

resource "aws_api_gateway_integration" "MyDemoIntegration" {
  rest_api_id = "${aws_api_gateway_rest_api.MyDemoAPI.id}"
  resource_id = "${aws_api_gateway_resource.MyDemoResource.id}"
  http_method = "${aws_api_gateway_method.MyDemoMethod.http_method}"
  type = "MOCK"
}

resource "aws_api_gateway_method_response" "200" {
  rest_api_id = "${aws_api_gateway_rest_api.MyDemoAPI.id}"
  resource_id = "${aws_api_gateway_resource.MyDemoResource.id}"
  http_method = "${aws_api_gateway_method.MyDemoMethod.http_method}"
  status_code = "200"
}

resource "aws_api_gateway_integration_response" "MyDemoIntegrationResponse" {
  rest_api_id = "${aws_api_gateway_rest_api.MyDemoAPI.id}"
  resource_id = "${aws_api_gateway_resource.MyDemoResource.id}"
  http_method = "${aws_api_gateway_method.MyDemoMethod.http_method}"
  status_code = "${aws_api_gateway_method_response.200.status_code}"
}

resource "aws_api_gateway_deployment" "MyDemoDeployment" {

  rest_api_id = "${aws_api_gateway_rest_api.MyDemoAPI.id}"
  stage_name = "api"
  variables = {
    "answer" = "42"
  }
}

Debug Output

gist

Panic Output

Console Output

Error applying plan:

1 error(s) occurred:

* aws_api_gateway_deployment.MyDemoDeployment: Error creating API Gateway Deployment: BadRequestException: The REST API doesn't contain any methods
    status code: 400, request id: 8b5a1dc1-47aa-11e6-9cb2-853ff7a02b06

Expected Behavior

The api should have been created with a stage and deployment.

Actual Behavior

The api is created without a stage or deployment until a second terraform apply is performed.

Steps to Reproduce

  1. Add the hcl above to a .tf file
  2. terraform apply
  3. View the error message from terraform and the api created without the deployment in aws
  4. terraform apply
  5. The api is created with the deployment upon the second terraform apply

    Important Factoids

none

References

Discovered while updating documentation GH-7586

bug provideaws

Most helpful comment

How should this be avoided when defining the API with a Swagger document? I have no terraform object to depend on.

All 7 comments

This is due to a missing required depends_on = ["aws_api_gateway_method.MyDemoMethod"] in the aws_api_gateway_deployment.

See:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-deployment.html

How should this be avoided when defining the API with a Swagger document? I have no terraform object to depend on.

Having the same issue as @robyoung. I'm trying to create a new stage in my api-gateway using deployment. The deployment looks for an integration in the "depends_on" field, and the integration in turn looks for a method to reference, but all my methods are defined in other folders within the gateway, so I don't have a method in my main terraform file to reference .

I have the same issue as @robyoung, would be nice to find a workaround for this.

I got around this by depending on the aws_api_gateway_rest_api resource itself.

In case the stage name had space .. :+1:

Hi all,

Because this closed issue is generating notifications for subscribers, I am going to lock it and encourage anyone experiencing issues with the aws provider to open tickets there.

Please continue to open issues here for any other terraform issues you encounter, and thanks!

Was this page helpful?
0 / 5 - 0 ratings