terraform 只有偶数的名字

terraform only name in even numbers

我使用 Terraform 已有一段时间了,但我对代码毫无经验。我一直在使用以下块为我的主机生成描述。

resource "vra_deployment" "test_instance" {
  count             = var.instance_count
  catalog_item_name = var.catalog_item_name
  description = "${var.hostname_prefix}${format("%02d", count.index+2)}-${replace(lower(var.region), "-","")}"

这将为我提供一个描述类似于 host02-region 的主机。目前,我只在计数变量设置为 1 的情况下使用它。

我想这样做,如果我将计数变量设置为 2,它将构建 2 个描述仅为偶数的主机,即 host02-region 和 host04-region。

谁能告诉我怎么做?

这只是一道基础数学题。我会将 count.index+2 更改为 (count.index + 1) * 2

(0 + 1) * 2 = 2
(1 + 1) * 2 = 4
(2 + 1) * 2 = 6
(3 + 1) * 2 = 8