@@ -120,6 +120,66 @@ resource "aws_api_gateway_integration_response" "default" {
120
120
content_handling = length (var. response_content_handlings ) > 0 ? element (var. response_content_handlings , count. index ) : null
121
121
}
122
122
123
+ resource "aws_api_gateway_method" "options_method" {
124
+ count = length (var. path_parts ) > 0 ? length (var. path_parts ) : 0
125
+ rest_api_id = aws_api_gateway_rest_api. default . * . id [0 ]
126
+ resource_id = aws_api_gateway_resource. default . * . id [count . index ]
127
+ http_method = " OPTIONS"
128
+ authorization = " NONE"
129
+ }
130
+
131
+ resource "aws_api_gateway_method_response" "options_200" {
132
+ count = length (aws_api_gateway_method. default . * . id )
133
+ rest_api_id = aws_api_gateway_rest_api. default . * . id [0 ]
134
+ resource_id = aws_api_gateway_resource. default . * . id [count . index ]
135
+ http_method = aws_api_gateway_method. options_method . * . http_method [count . index ]
136
+ status_code = " 200"
137
+
138
+ response_models {
139
+ " application/json" = " Empty"
140
+ }
141
+
142
+ response_parameters {
143
+ " method.response.header.Access-Control-Allow-Origin" = true
144
+ " method.response.header.Access-Control-Allow-Headers" = true
145
+ " method.response.header.Access-Control-Allow-Methods" = true
146
+ " method.response.header.Access-Control-Allow-Credentials" = true
147
+ }
148
+
149
+ depends_on = [" aws_api_gateway_method.options_method" ]
150
+ }
151
+
152
+ resource "aws_api_gateway_integration" "options_integration" {
153
+ count = length (aws_api_gateway_method. default . * . id )
154
+ rest_api_id = aws_api_gateway_rest_api. default . * . id [0 ]
155
+ resource_id = aws_api_gateway_resource. default . * . id [count . index ]
156
+ http_method = aws_api_gateway_method. options_method . * . http_method [count . index ]
157
+
158
+ type = " MOCK"
159
+ content_handling = " CONVERT_TO_TEXT"
160
+
161
+ depends_on = [" aws_api_gateway_method.options_method" ]
162
+ }
163
+
164
+ resource "aws_api_gateway_integration_response" "options_integration_response" {
165
+ count = length (aws_api_gateway_integration. options_integration . * . id )
166
+ rest_api_id = aws_api_gateway_rest_api. default . * . id [0 ]
167
+ resource_id = aws_api_gateway_resource. default . * . id [count . index ]
168
+ http_method = aws_api_gateway_method. options_method . * . http_method [count . index ]
169
+ status_code = aws_api_gateway_method_response. options_200 . * . status_code [count . index ]
170
+
171
+ response_parameters = {
172
+ " method.response.header.Access-Control-Allow-Origin" = " '*'"
173
+ " method.response.header.Access-Control-Allow-Headers" = " 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent'"
174
+ " method.response.header.Access-Control-Allow-Methods" = " 'OPTIONS,DELETE,GET,HEAD,PATCH,POST,PUT'"
175
+ }
176
+
177
+ depends_on = [
178
+ " aws_api_gateway_method_response.options_200" ,
179
+ " aws_api_gateway_integration.options_integration" ,
180
+ ]
181
+ }
182
+
123
183
# Module : Api Gateway Deployment
124
184
# Description : Terraform module to create Api Gateway Deployment resource on AWS.
125
185
resource "aws_api_gateway_deployment" "default" {
0 commit comments