In order to enforce query params validation, we have to assign Request validator in the method request. In my case I want to enforce required validation to startDate and endDate query params (Validate query string parameters and headers).
In Terraform, it looks like I need to create a separate aws_api_gateway_request_validator resource and then attach its ID to the method:
resource "aws_api_gateway_resource" "demo_resource" {
parent_id = aws_api_gateway_resource.parent_resource.id
path_part = "demo"
rest_api_id = aws_api_gateway_rest_api.demo_api.id
depends_on = [aws_api_gateway_resource.parent_resource]
}
# Creating new validator.
resource "aws_api_gateway_request_validator" "validate_query_params" {
name = "validate-query-params"
rest_api_id = aws_api_gateway_rest_api.demo_api.id
validate_request_parameters = true
}
resource "aws_api_gateway_method" "demo_resource_get" {
rest_api_id = aws_api_gateway_rest_api.demo_api.id
resource_id = aws_api_gateway_resource.demo_resource.id
http_method = "GET"
authorization = "NONE"
api_key_required = true
request_parameters = {
"method.request.querystring.startDate" = true
"method.request.querystring.endDate" = true
}
# NOTE that we have to use id from a newly created validator. How can we just use the AWS provided option instead of creating new one?
request_validator_id = aws_api_gateway_request_validator.validate_query_params.id
depends_on = [aws_api_gateway_resource.demo_resource]
}
What I would like to do is avoid defining a new validator resource in Terraform for this, and instead just use the "AWS provided" option that appears in the API Gateway console (e.g. Validate query string parameters and headers). Ideally something like referencing a built-in validator by a known ID or name. Is there a way to achieve such thing with Terraform?
Docs:
