@@ -221,16 +221,44 @@ resource "aws_appsync_resolver" "this" {
221221
222222# Functions
223223resource "aws_appsync_function" "this" {
224- for_each = var . create_graphql_api ? var. functions : { }
224+ for_each = { for k , v in var . functions : k => v if var . create_graphql_api == true }
225225
226226 api_id = aws_appsync_graphql_api. this [0 ]. id
227227 data_source = lookup (each. value , " data_source" , null )
228228 name = each. key
229229 description = lookup (each. value , " description" , null )
230- function_version = lookup (each. value , " function_version" , " 2018-05-29" )
230+ function_version = lookup (each. value , " function_version" , try (each. value . code == null , false ) ? " 2018-05-29" : null )
231+ max_batch_size = lookup (each. value , " max_batch_size" , null )
231232
232- request_mapping_template = lookup (each. value , " request_mapping_template" , null )
233- response_mapping_template = lookup (each. value , " response_mapping_template" , null )
233+ request_mapping_template = lookup (each. value , " request_mapping_template" , try (each. value . runtime . name == " APPSYNC_JS" , false ) ? null : " {}" )
234+ response_mapping_template = lookup (each. value , " response_mapping_template" , try (each. value . runtime . name == " APPSYNC_JS" , false ) ? null : " {}" )
235+
236+ code = try (each. value . code , null )
237+
238+ dynamic "sync_config" {
239+ for_each = try ([each . value . sync_config ], [])
240+
241+ content {
242+ conflict_detection = try (sync_config. value . conflict_detection , " NONE" )
243+ conflict_handler = try (sync_config. value . conflict_handler , " NONE" )
244+
245+ dynamic "lambda_conflict_handler_config" {
246+ for_each = try ([each . value . sync_config . lambda_conflict_handler_config ], [])
247+ content {
248+ lambda_conflict_handler_arn = try (lambda_conflict_handler_config. value . lambda_conflict_handler_arn , null )
249+ }
250+ }
251+ }
252+ }
253+
254+ dynamic "runtime" {
255+ for_each = try ([each . value . runtime ], [])
256+
257+ content {
258+ name = runtime. value . name
259+ runtime_version = try (runtime. value . runtime_version , " 1.0.0" )
260+ }
261+ }
234262
235263 depends_on = [aws_appsync_datasource . this ]
236264}
0 commit comments