You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Terraform调用formatlist函数提示%s需字符串类型的报错原因

错误原因
  • formatlist的%s占位符仅支持传入字符串类型值,代码中azurerm_synapse_workspace.workspace.identity为对象类型(部分版本AzureRM Provider中为长度为1的对象列表),本身不是字符串,无法直接适配字符串格式化规则。
  • 由于var.workspace.acl.contributors是空列表,concat生成的local.merged_acl_contributors仅包含这一个非字符串元素,因此触发迭代到第0位元素时的类型不匹配报错。
解决方法

ACL规则通常需要填入身份对应的服务主体ID(principal_id),你需要先从identity属性中提取该字符串值再进行合并,修改后的代码参考如下:

locals {
    # 若你的AzureRM Provider版本中identity为单对象而非列表,去掉[0]即可
    merged_acl_contributors = concat(var.workspace.acl.contributors, [azurerm_synapse_workspace.workspace.identity[0].principal_id])
    contributors = formatlist("user:%s:rwx", local.merged_acl_contributors)
}
  • 若场景需要用到identity的其他属性,替换代码中的principal_id为对应字段名即可。

内容的提问来源于stack exchange,提问作者egrok

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 14:09:05