0

我使用 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。

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

谁能告诉我如何做到这一点?

4

1 回答 1

1

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

(0 + 1) * 2 = 2
(1 + 1) * 2 = 4
(2 + 1) * 2 = 6
(3 + 1) * 2 = 8
于 2021-02-15T15:11:25.587 回答