【发布时间】:2021-04-19 10:01:49
【问题描述】:
-
我正在使用 terraform 0.13.5 创建 aws_iam 资源
-
我有 2 个 terraform 资源如下
module "calls_aws_iam_policy_attachment" { # This calls an external module to # which among other things creates a policy attachment # resource attaching the roles to the policy source = "" name = "xoyo" roles = ["rolex", "roley"] policy_arn = "POLICY_NAME" } resource "aws_iam_policy_attachment" "policies_attached" { # This creates a policy attachment resource attaching the roles to the policy # The roles here are a superset of the roles in the above module roles = ["role1", "role2", "rolex", "roley"] policy_arn = "POLICY_NAME" name = "NAME" # I was hoping that adding the depends on block here would mean this # resource is always created after the above module depends_on = [ module.calls_aws_iam_policy_attachment ] } -
第一个模块创建一个策略并附加一些角色。我无法编辑此模块
-
第二个资源将更多角色与其他策略一起附加到同一策略
-
第二个资源依赖于第一个资源,所以我希望第二个资源的政策附件总是覆盖第一个资源的政策附件
-
实际上,每个资源中的策略附件在每次连续构建时都会相互覆盖。因此,在第一次构建时,应用了第二个资源附件,在第二次构建时,应用了第一个资源附件,依此类推。
-
谁能告诉我为什么会这样? depends_on 是否不适用于相互覆盖的资源?
-
如果不将我的两个资源合并到同一个资源中,是否有一个简单的解决方法?
【问题讨论】:
-
为什么您的资源首先会相互覆盖,这会给您带来各种麻烦,您当然应该删除它。
-
谢谢@luk2302 好吧,其中一个是另一个的超集。所以我希望超集总是覆盖子集。这是一个巨大的不,不?我对 terraform 还很陌生,所以仍在掌握最佳实践
-
明确地说,子集创建了其他资源,而不仅仅是策略附件。因此,解决方案并不像将其全部删除那么简单。否则我不会在这里:)
标签: terraform terraform-provider-aws