在Terraform中可以使用JSON格式的cors_rules列表来允许多个域名或正则表达式的cors origin。
代码示例:
resource "aws_api_gateway_rest_api" "example" {
name = "cors-test"
}
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 = "example"
}
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"
}
resource "aws_api_gateway_integration" "example" {
rest_api_id = aws_api_gateway_rest_api.example.id
resource_id = aws_api_gateway_method.example.resource_id
http_method = aws_api_gateway_method.example.http_method
integration_http_method = "GET"
type = "MOCK"
}
resource "aws_api_gateway_method_response" "example" {
rest_api_id = aws_api_gateway_rest_api.example.id
resource_id = aws_api_gateway_resource.example.id
http_method = aws_api_gateway_method.example.http_method
status_code = "200"
}
resource "aws_api_gateway_integration_response" "example" {
rest_api_id = aws_api_gateway_rest_api.example.id
resource_id = aws_api_gateway_method.example.resource_id
http_method = aws_api_gateway_method.example.http_method
status_code = aws_api_gateway_method_response.example.status_code
content_handling = "CONVERT_TO_TEXT"
integration_response_id = "\${aws_api_gateway_integration_response.example.id}"
}
resource "aws_api_gateway_method_settings" "example" {
rest_api_id = aws_api_gateway_rest_api.example.id
stage_name = aws_api_gateway_deployment.example.stage_name
method_path = "${aws_api_gateway_method.example.resource_id}/${aws_api_gateway_method.example.http_method}"
settings = jsonencode({
"loggingLevel" = "INFO",
"metricsEnabled" = true,
"loggingLevel" = "INFO",
"