Terraform-provider-aws: How to enable HEAD method on API Gateway with Terraform?

Created on 2 Mar 2018  ยท  2Comments  ยท  Source: hashicorp/terraform-provider-aws

Hi there,

Terraform Version

Terraform v0.11.1

Affected Resource(s)

Please list the resources as a list, for example:

  • aws_api_gateway_method
  • aws_api_gateway_integration
  • aws_api_gateway_method_response

Terraform Configuration Files

resource "aws_api_gateway_method" "enable_head_request" {
  provider         = "aws.default"
  rest_api_id      = "${aws_api_gateway_rest_api.petshop.id}"
  resource_id      = "${aws_api_gateway_rest_api.petshop.root_resource_id}"
  http_method      = "HEAD"
  authorization    = "NONE"
#  api_key_required = "False"
}

resource "aws_api_gateway_integration" "enable_head_request" {
  provider                = "aws.default"
  rest_api_id             = "${aws_api_gateway_rest_api.petshop.id}"
  resource_id             = "${aws_api_gateway_rest_api.petshop.root_resource_id}"
  http_method             = "${aws_api_gateway_method.enable_head_request.http_method}"
  integration_http_method = "POST"
  type                    = "AWS_PROXY"
  uri                     = "${aws_lambda_function.petshop.invoke_arn}"
}

resource "aws_api_gateway_method_response" "200_for_head_request" {
  provider    = "aws.default"
  rest_api_id = "${aws_api_gateway_rest_api.petshop.id}"
  resource_id = "${aws_api_gateway_rest_api.petshop.root_resource_id}"
  http_method = "${aws_api_gateway_method.enable_head_request.http_method}"
  status_code = "200"
}

Expected Behavior

I should be able to make HEAD requests to my API Gateway endpoint.

Actual Behavior

After deploying on trying to make a HEAD request I get

curl --head https://test.com
HTTP/1.1 403 Forbidden
Date: Thu, 01 Mar 2018 18:47:07 GMT
Content-Type: application/json
Content-Length: 42
Connection: keep-alive
x-amzn-RequestId: f1811ce9-1d80-11e8-b15c-cf44af523470
x-amzn-ErrorType: MissingAuthenticationTokenException
question servicapigateway

Most helpful comment

The issue is that the deployment does not get redeployed. Here's how to trigger a redeployment whenever there's a change in the contents of the apigateway.tf file

resource "aws_api_gateway_deployment" "petshop" {
  provider    = "aws.default"
  stage_description = "${md5(file("apigateway.tf"))}"
  rest_api_id = "${aws_api_gateway_rest_api.petshop.id}"
  stage_name  = "prod"
}

All 2 comments

The issue is that the deployment does not get redeployed. Here's how to trigger a redeployment whenever there's a change in the contents of the apigateway.tf file

resource "aws_api_gateway_deployment" "petshop" {
  provider    = "aws.default"
  stage_description = "${md5(file("apigateway.tf"))}"
  rest_api_id = "${aws_api_gateway_rest_api.petshop.id}"
  stage_name  = "prod"
}

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

Was this page helpful?
0 / 5 - 0 ratings