0

下面是我陷入捕获function_idaws_appsync_function.appsync_functions引用创建的代码aws_appsync_resolver

#---- Create AppSync Functions -----
resource "aws_appsync_function" "appsync_functions" {
  for_each                  = var.appsync_function
  name                      = each.value.name
  api_id                    = aws_appsync_graphql_api.appsync.id
  data_source               = each.value.data_source
  request_mapping_template  = file(each.value.request_template_path)
  response_mapping_template = file(each.value.response_template_path)
  description               = each.value.description
  }


#---- Create AppSync Resolvers -----
resource "aws_appsync_resolver" "appsync_pipeline_resolver" {
  type              = "Query"
  api_id            = aws_appsync_graphql_api.appsync.id
  field             = var.appsync_resolver.trailheadItemById.name
  request_template  = file(var.appsync_resolver.trailheadItemById.request_template_path)
  response_template = file(var.appsync_resolver.trailheadItemById.response_template_path)
  kind              = "PIPELINE"
  for_each                  = var.appsync_function
  pipeline_config {
    functions = aws_appsync_function.appsync_functions[each.key].name==var.appsync_resolver.trailheadItemById.name ? aws_appsync_function.appsync_functions["trailheadItemById"].function_id : ""
  }
}

上面的代码捕获了我放在 pipeline_config 下的所有 function_id 和条件不起作用!我可以获得语法方面的帮助来完成这项工作吗?

谢谢你。

4

2 回答 2

1

functions是一个列表,而不是string. 它应该是:

  pipeline_config {
    functions = [aws_appsync_function.appsync_functions[each.key].name==var.appsync_resolver.trailheadItemById.name ? aws_appsync_function.appsync_functions["trailheadItemById"].function_id : ""]
  }

但可能必须使用动态块使其成为可选:

  dynamic "pipeline_config" {
     for_each = aws_appsync_function.appsync_functions[each.key].name==var.appsync_resolver.trailheadItemById.name ? [1]: []
     content {
        functions = [aws_appsync_function.appsync_functions["trailheadItemById"].function_id]     
     }
  }
于 2021-10-26T08:05:38.177 回答
0

这个有效... !! 欢呼

我正在做的错误是提到

for_each = var.appsync_functionresource "aws_appsync_resolver"

#---- Create AppSync Functions -----
resource "aws_appsync_function" "sfdc_appsync_functions" {
  for_each                  = var.appsync_function
  name                      = each.value.name
  api_id                    = aws_appsync_graphql_api.sfdc_appsync.id
  data_source               = each.value.data_source
  request_mapping_template  = file(each.value.request_template_path)
  response_mapping_template = file(each.value.response_template_path)
  description               = each.value.description
  depends_on = [aws_appsync_graphql_api.sfdc_appsync, aws_appsync_datasource.sfdc_appsync_datasource]
  }

#---- Create AppSync Resolvers -----
# PIPELINE type resolver
resource "aws_appsync_resolver" "sfdc_appsync_pipeline_resolver" {
  for_each          = var.appsync_resolver
  type              = "Query"
  api_id            = aws_appsync_graphql_api.sfdc_appsync.id
  field             = each.value.name
  request_template  = file(var.appsync_resolver.trailheadItemById.request_template_path)
  response_template = file(var.appsync_resolver.trailheadItemById.response_template_path)
  kind              = "PIPELINE"
  pipeline_config {
        functions = [aws_appsync_function.sfdc_appsync_functions["GetContentById"].function_id]
  }
  depends_on = [aws_appsync_graphql_api.sfdc_appsync, aws_appsync_datasource.sfdc_appsync_datasource, aws_appsync_function.sfdc_appsync_functions]
}

抄送:@Marcin

于 2021-10-27T10:58:46.783 回答