@@ -66,7 +66,7 @@ resource "aws_apigatewayv2_stage" "default" {
6666 api_id = aws_apigatewayv2_api. this [0 ]. id
6767 name = " $default"
6868 auto_deploy = true
69-
69+ description = var . default_stage_description
7070 dynamic "access_log_settings" {
7171 for_each = var. default_stage_access_log_destination_arn != null && var. default_stage_access_log_format != null ? [true ] : []
7272
@@ -111,6 +111,8 @@ resource "aws_apigatewayv2_stage" "default" {
111111 }
112112}
113113
114+ # ## Api mappings
115+
114116# Default API mapping
115117resource "aws_apigatewayv2_api_mapping" "this" {
116118 count = var. create && var. create_api_domain_name && var. create_default_stage && var. create_default_stage_api_mapping ? 1 : 0
@@ -120,9 +122,20 @@ resource "aws_apigatewayv2_api_mapping" "this" {
120122 stage = aws_apigatewayv2_stage. default [0 ]. id
121123}
122124
125+ # Additional Api mappings
126+ resource "aws_apigatewayv2_api_mapping" "this_additional" {
127+ for_each = var. additional_default_stage_api_mappings
128+
129+ api_id = aws_apigatewayv2_api. this [0 ]. id
130+ domain_name = each. value [" domain_name" ]
131+ stage = aws_apigatewayv2_stage. default [0 ]. id
132+ api_mapping_key = each. value [" api_mapping_key" ]
133+ }
134+
135+
123136# Routes and integrations
124137resource "aws_apigatewayv2_route" "this" {
125- for_each = var. create && var. create_routes_and_integrations ? var. integrations : {}
138+ for_each = var. create && var. create_routes_and_integrations ? var. routes : {}
126139
127140 api_id = aws_apigatewayv2_api. this [0 ]. id
128141 route_key = each. key
@@ -134,7 +147,7 @@ resource "aws_apigatewayv2_route" "this" {
134147 model_selection_expression = try (each. value . model_selection_expression , null )
135148 operation_name = try (each. value . operation_name , null )
136149 route_response_selection_expression = try (each. value . route_response_selection_expression , null )
137- target = " integrations/${ aws_apigatewayv2_integration . this [each . key ]. id } "
150+ target = " integrations/${ aws_apigatewayv2_integration . this [coalesce ( each. value . integration_key , each . key ) ]. id } "
138151
139152 # Have been added to the docs. But is WEBSOCKET only(not yet supported)
140153 # request_models = try(each.value.request_models, null)
@@ -144,37 +157,37 @@ resource "aws_apigatewayv2_integration" "this" {
144157 for_each = var. create && var. create_routes_and_integrations ? var. integrations : {}
145158
146159 api_id = aws_apigatewayv2_api. this [0 ]. id
147- description = try ( each. value . description , null )
160+ description = each. value . description
148161
149- integration_type = try ( each. value . integration_type , try (each . value . lambda_arn , " " ) != " " ? " AWS_PROXY " : " MOCK " )
150- integration_subtype = try ( each. value . integration_subtype , null )
151- integration_method = try ( each. value . integration_method , try (each . value . integration_subtype , null ) == null ? " POST " : null )
152- integration_uri = try (each. value . lambda_arn , try ( each. value . integration_uri , null ) )
162+ integration_type = each. value . integration_type
163+ integration_subtype = each. value . integration_subtype
164+ integration_method = each. value . integration_method
165+ integration_uri = coalesce (each. value . lambda_arn , each. value . integration_uri )
153166
154- connection_type = try ( each. value . connection_type , " INTERNET " )
167+ connection_type = each. value . connection_type
155168 connection_id = try (aws_apigatewayv2_vpc_link. this [each . value [" vpc_link" ]]. id , try (each. value . connection_id , null ))
156169
157- payload_format_version = try ( each. value . payload_format_version , null )
158- timeout_milliseconds = try ( each. value . timeout_milliseconds , null )
159- passthrough_behavior = try ( each. value . passthrough_behavior , null )
160- content_handling_strategy = try ( each. value . content_handling_strategy , null )
161- credentials_arn = try ( each. value . credentials_arn , null )
170+ payload_format_version = each. value . payload_format_version
171+ timeout_milliseconds = each. value . timeout_milliseconds
172+ passthrough_behavior = each. value . passthrough_behavior
173+ content_handling_strategy = each. value . content_handling_strategy
174+ credentials_arn = each. value . credentials_arn
162175 request_parameters = try (jsondecode (each. value [" request_parameters" ]), each. value [" request_parameters" ], null )
163176
164177 dynamic "tls_config" {
165- for_each = flatten ([ try ( jsondecode ( each. value [" tls_config" ]), each . value [ " tls_config " ], [])])
178+ for_each = each. value [" tls_config" ] ? [ 1 ] : []
166179
167180 content {
168- server_name_to_verify = tls_config . value [" server_name_to_verify " ]
181+ server_name_to_verify = each . value [" tls_config_server_name_to_verify " ]
169182 }
170183 }
171184
172185 dynamic "response_parameters" {
173- for_each = flatten ([ try ( jsondecode ( each. value [" response_parameters" ]), each . value [ " response_parameters " ], [])])
186+ for_each = each. value [" response_parameters" ] ? [ 1 ] : []
174187
175188 content {
176- status_code = response_parameters . value [" status_code " ]
177- mappings = response_parameters . value [" mappings " ]
189+ status_code = each . value [" response_parameters_status_code " ]
190+ mappings = each . value [" response_parameters_mappings " ]
178191 }
179192 }
180193
0 commit comments