|
| 1 | +resource "aws_api_gateway_method" "cors_method" { |
| 2 | + rest_api_id = "${var.api}" |
| 3 | + resource_id = "${var.resource}" |
| 4 | + http_method = "OPTIONS" |
| 5 | + authorization = "NONE" |
| 6 | +} |
| 7 | + |
| 8 | +resource "aws_api_gateway_integration" "cors_integration" { |
| 9 | + rest_api_id = "${var.api}" |
| 10 | + resource_id = "${var.resource}" |
| 11 | + http_method = "${aws_api_gateway_method.cors_method.http_method}" |
| 12 | + type = "MOCK" |
| 13 | + request_templates { |
| 14 | +"application/json" = <<EOF |
| 15 | +{ "statusCode": 200 } |
| 16 | +EOF |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +resource "aws_api_gateway_method_response" "cors_method_response" { |
| 21 | + rest_api_id = "${var.api}" |
| 22 | + resource_id = "${var.resource}" |
| 23 | + http_method = "${aws_api_gateway_method.cors_method.http_method}" |
| 24 | + |
| 25 | + status_code = "200" |
| 26 | + |
| 27 | + response_models { |
| 28 | + "application/json" = "Empty" |
| 29 | + } |
| 30 | + |
| 31 | + response_parameters { |
| 32 | + "method.response.header.Access-Control-Allow-Headers" = true, |
| 33 | + "method.response.header.Access-Control-Allow-Methods" = true, |
| 34 | + "method.response.header.Access-Control-Allow-Origin" = true |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +resource "aws_api_gateway_integration_response" "cors_integration_response" { |
| 39 | + rest_api_id = "${var.api}" |
| 40 | + resource_id = "${aws_api_gateway_method.cors_method.resource_id}" |
| 41 | + http_method = "${aws_api_gateway_method.cors_method.http_method}" |
| 42 | + |
| 43 | + status_code = "${aws_api_gateway_method_response.cors_method_response.status_code}" |
| 44 | + |
| 45 | + response_parameters = { |
| 46 | + "method.response.header.Access-Control-Allow-Headers" = "'${local.headers}'", |
| 47 | + "method.response.header.Access-Control-Allow-Methods" = "'${local.methods}'", |
| 48 | + "method.response.header.Access-Control-Allow-Origin" = "'${local.origins}'" |
| 49 | + } |
| 50 | +} |
0 commit comments