Terraform-provider-aws: Request Validator support in terraform.

Created on 5 Dec 2017  ·  9Comments  ·  Source: hashicorp/terraform-provider-aws

_This issue was originally opened by @SomnathDange as hashicorp/terraform#16842. It was migrated here as a result of the provider split. The original body of the issue is below._


Terraform v0.9.11
Hello,

is there any way in terraform i can modify the Request Validator value in the API GATEWAY => Method Request => Request Validator.

documentation servicapigateway

Most helpful comment

The resource aws_api_gateway_request_validator is not in the official documentation. Could we add it there? Based on the code posted above, are those all the arguments/attributes reference?

All 9 comments

Hi @SomnathDange, it turns out we actually might, however the documentation for this resource was never added. 🙁

What I'm referring to is available as of Terraform 0.10+ and AWS provider 0.1.3+: https://github.com/terraform-providers/terraform-provider-aws/pull/1064

According to the acceptance testing, it should be usable via:

resource "aws_api_gateway_rest_api" "example" {
  name = "example"
}

resource "aws_api_gateway_resource" "example" {
  rest_api_id = "${aws_api_gateway_rest_api.example.id}"
  parent_id = "${aws_api_gateway_rest_api.example.root_resource_id}"
  path_part = "test"
}

resource "aws_api_gateway_request_validator" "example" {
  name = "example"
  rest_api_id = "${aws_api_gateway_rest_api.example.id}"
  validate_request_body = true
  validate_request_parameters = true
}

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

  request_models = {
    "application/json" = "Error"
  }

  request_parameters = {
    "method.request.header.Content-Type" = false,
      "method.request.querystring.page" = true
  }

  request_validator_id = "${aws_api_gateway_request_validator.example.id}"
}

Let us know if this works or is not what you're looking for. Thanks.

Thanks for this this is what i am looking,
But is there any way i can use the already available request validators's ID
Below validators are already available
1) Validate body
2) Validate body, query string parameters, and headers
3) Validate query string parameters and headers

with the above code it creates a new validator and assign it to the request method.

@SomnathDange Did you ever find a workaround for this issue? I'm struggling with it myself.

Yes as shown in the above example I have created one resource "aws_api_gateway_request_validator"
new validator and assigned this validator to the method. (This will create the new validator)

The resource aws_api_gateway_request_validator is not in the official documentation. Could we add it there? Based on the code posted above, are those all the arguments/attributes reference?

I need to know how i can assign Validate body to the request validators option in the API Gateway? Is that possible?

I was wondering the same as some of the questions above around using the request validators shown in the API Gateway UI.

From calling the get-request-validators API it looks like the validators defined on the API Gateway UI don't exist until they are used, here is how to define them in Terraform:

resource "aws_api_gateway_request_validator" "request_validator" {
  name = "Validate body"
  rest_api_id = "${aws_api_gateway_rest_api.example.id}"
  validate_request_body = true
  validate_request_parameters = false
}

resource "aws_api_gateway_request_validator" "request_validator" {
  name = "Validate body, query string parameters, and headers"
  rest_api_id = "${aws_api_gateway_rest_api.example.id}"
  validate_request_body = true
  validate_request_parameters = true
}

resource "aws_api_gateway_request_validator" "request_validator" {
  name = "Validate query string parameters and headers"
  rest_api_id = "${aws_api_gateway_rest_api.example.id}"
  validate_request_body = false
  validate_request_parameters = true
}

The resource documentation page will be released with version 1.27.0 of the AWS provider, likely middle of next week.

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