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

Terraform中aws_iam_policy_document的resources块遍历循环实现方法

实现方法

你可以直接在resources数组内使用Terraform的for表达式遍历整个local.accounts_to_protect列表,逐一生成对应ARN即可,示例如下:

resources = [
  for account_id in local.accounts_to_protect : "arn:aws:ec2::${account_id}:*"
]

如果需要在动态生成的ARN列表基础上额外添加固定的资源ARN,可以配合concat函数做列表拼接:

resources = concat(
  [for account_id in local.accounts_to_protect : "arn:aws:ec2::${account_id}:*"],
  # 可追加其他固定资源ARN
  ["arn:aws:ec2::123456789012:instance/*"]
)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 05:39:04