0

我正在尝试组合两个列表并将其设置为资源的属性,但出现错误。这是最小的复制:

  network_configuration {
    security_groups = "${concat([module.service_base.allow_lb_access_sg], [module.service_base.intraservice_communication_sg])}"
  }

我收到一个超级无用的错误

错误:加载模块时出错:模块 load_balanced_service:加载 .terraform/modules/188cf031fdce92d75131be4747cedad9/XXX.tf 时出错:读取 aws_ecs_service[ecs_service] 的配置时出错:在 1:10 解析错误:预期表达式但找到“[”

它声称第 1 行,但如果您删除该 security_groups 行,一切正常。

4

1 回答 1

0

好的,所以文档非常不清楚。我解决这个问题的方法是

security_groups = ["${concat(list(module.service_base.allow_lb_access_sg), list(module.service_base.intraservice_communication_sg))}"]

请注意,该list功能是强制性的。如果你使用[]它仍然会破裂。

但是,如果您的输入之一是列表,则您不想将其放入,list因为那样它将是包含您的列表的列表,例如您想要

security_groups = ["${concat(list(module.service_base.allow_lb_access_sg), var.my_list_type_variable)}"]

进一步阅读:https ://github.com/hashicorp/terraform/issues/6657

于 2019-05-20T18:58:28.863 回答