小编Sim*_*nSK的帖子

带模块的 Terraform 计数方法

我正在使用 terraform 并通过模块配置资源。在某些环境中我想创建一个模块,在其他环境中则不想,最好的方法是什么?尝试使用计数方法:

module "module_name" {
  create                   = var.create_module
  source                   = "../../modules/module" 
}
Run Code Online (Sandbox Code Playgroud)

模块内部当然包含检查是否创建资源的资源:

resource "some resource" "main" {
  count = var.create  == true ? 1 : 0
Run Code Online (Sandbox Code Playgroud)

由于我在模块内使用 count,我在模型中的所有资源(数十个)上收到以下错误:

Because some_resource.main has "count" set, its attributes must
be accessed on specific instances.

For example, to correlate with indices of a referring resource, use:
    some_resource.main[count.index]
Run Code Online (Sandbox Code Playgroud)

有没有办法在模块或根内部使用 count,而不重构 [count.index] 的整个代码(谁知道可能会导致许多其他问题)?

terraform terraform-provider-aws

1
推荐指数
1
解决办法
9889
查看次数

标签 统计

terraform ×1

terraform-provider-aws ×1