是否可以向terraform模块添加模板或循环

时间:2018-08-02 20:57:02

标签: terraform

如果我有Terraform模块:

module "name_1" {
  source = "../some_path"
  account_id = "name_1"
}

module "name_2" {
  source = "../some_path"
  account_id = "name_2"
}

module "name_3" {
  source = "../some_path"
  account_id = "name_3"
}

是否可以添加一些逻辑(循环)或模板,这样我就不必一次又一次地重复模块

类似的东西:

module "name_{num}" {
  source = "../some_path"
  account_id = "name_{num}"
}

1 个答案:

答案 0 :(得分:1)

到目前为止(Terraform 0.11),这是不可能的。由于更好的HCL解析器,即将发布的0.12版将带来很多改进。

here所述,存在以下语法的计划,在0.12以后将不再可用

resource "aws_subnet" "example" {
  for_each = var.subnet_numbers

  vpc_id            = aws_vpc.example.id
  availability_zone = each.key
  cidr_block        = cidrsubnet(aws_vpc.example.cidr_block, 8, each.value)
}

尽管如此,我想我们都对此充满期待。

相关问题