Terraform:aws_iam_policy_document中的条件语句块?



有没有办法有条件地在aws_iam_policy_document中添加statement块?我正在寻找类似的东西:

data "aws_iam_policy_document" "policy" {
statement {
sid = "PolicyAlways"
...
}
if (var.enable_optional_policy) {
statement {
sid = "PolicySometimes"
...
}
}
}

是的。您可以将dynamic块与布尔值一起使用,以选择性地包含该块。

data "aws_iam_policy_document" "policy" {
statement {
sid = "PolicyAlways"
...
}
dynamic "statement" {
# The contents of the list below are arbitrary, but must be of length one. 
# It is only used to determine whether or not to include this statement.
for_each = var.enable_optional_policy ? [1] : []
content {
sid = "PolicySometimes"
...
}
}
}

相关内容

  • 没有找到相关文章

最新更新