DBtake3
DBtake3

Reputation: 126

Terraform: How to set a method's Request Validator on an API Gateway which is created via body import of a open api yaml file

I'm creating AWS API Gateway via Terraform via importing an Open API yaml file. The import works fine but the issue I'm trying to resolve is that my required fields are not being enforced.

If I was creating the API entirely via Terraform I would set the request_validator_id attribute on a aws_api_gateway_method resource and be all set, but how do I do what when the aws_api_gateway_method resource was created automatically via the aws_api_gateway_rest_api resource?

Visually what I'm trying to do is select 'Validate Body' for a POST request.

What I would select if I was doing this manually

My Terraform resource to create the api;

resource "aws_api_gateway_rest_api" "api" {
  name        = "Users API - ${var.Environment}"
  body        = file("../api/${var.Environment}.test.org.yaml")
  endpoint_configuration {
    types = ["REGIONAL"]
  }
}

Upvotes: 0

Views: 939

Answers (1)

Ali Hasan
Ali Hasan

Reputation: 592

You can do something like this in your open-api docs in body:

"x-amazon-apigateway-request-validator": "Validate Body"

This will add the validation for your request for POST method. This syntax is for json, yaml would be same as per formatting provide.

Upvotes: 1

Related Questions