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

尝试合并Terraform资源为单列表时遇属性值错误

问题解决:Terraform resources 属性类型错误

你的代码核心问题是外层多套了一层方括号,导致resources最终变成嵌套列表(列表的列表),而Terraform要求resources必须是一维字符串列表——此时元素0是整个concat生成的列表,而非单个字符串,因此触发"元素0需要字符串类型"的错误。

修正后的代码

resources = concat(
  [for b in concat(each.value.local_data_bucket_write, each.value.local_data_bucket_read) : "arn:aws:s3:::${b}"],
  [for b in concat(each.value.local_data_bucket_write, each.value.local_data_bucket_read) : "arn:aws:s3:::${b}/*"],
  ["arn:aws:sts:${var.aws_region}:${var.data_aws_account_id}:*"]
)

额外优化建议

你两次重复调用concat(each.value.local_data_bucket_write, each.value.local_data_bucket_read),可以提前定义局部变量简化代码,避免重复计算:

locals {
  combined_buckets = concat(each.value.local_data_bucket_write, each.value.local_data_bucket_read)
}

resources = concat(
  [for b in local.combined_buckets : "arn:aws:s3:::${b}"],
  [for b in local.combined_buckets : "arn:aws:s3:::${b}/*"],
  ["arn:aws:sts:${var.aws_region}:${var.data_aws_account_id}:*"]
)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 14:25:36