0

我正在尝试使用 terraform 为 Azure VM 启动备份,但它没有采用 source_vm_id 参数。我把它列出如下

#https://www.terraform.io/docs/providers/azurerm/r/backup_protected_vm.html
resource "azurerm_backup_protected_vm" "BackupProtected_app_vm_01" {
  resource_group_name = "${azurerm_resource_group.resource_group.name}"
  recovery_vault_name = "z1-r-op-rsv-01"
  #source_vm_id        = "${azurerm_virtual_machine.app_vm_01[count.index].id}"
  source_vm_id       = [element(azurerm_virtual_machine.app_vm_01.*.id, count.index)]
  backup_policy_id    = "${azurerm_backup_policy_vm.BackupPolicy_app_vm_01.id}"
}

我收到以下错误:错误:在非计数上下文中引用“计数”

在 AGC.tf 第 264 行,在资源“azurerm_backup_protected_vm”“BackupProtected_app_vm_01”中:264:source_vm_id = [element(azurerm_virtual_machine.app_vm_01.*.id, count.index)]

“count”对象只能在“resource”和“data”块中使用,并且只能在设置了“count”参数时使用。

我试图在不使用“元素”的情况下更改它,但它仍然抛出错误。

这是我为 VM 定义的内容:

resource "azurerm_virtual_machine" "app_vm_01" {
  count                            = var.app_vm_01_count
  name                             = "${var.reg}${var.dash}${var.env}${var.dash}${var.app}${var.dash}${var.app_vm_01}${var.dash}${format("%02d", count.index+1)}"
  location                         = var.location
  resource_group_name              = azurerm_resource_group.resource_group.name
  network_interface_ids            = [element(azurerm_network_interface.app_vm_01.*.id, count.index)]
  availability_set_id              = azurerm_availability_set.app_vm_01.id
  vm_size                          = "Standard_D2s_v3"
  license_type                     = "Windows_Server"
  delete_os_disk_on_termination    = true
  delete_data_disks_on_termination = true

  boot_diagnostics {
    enabled     = "true"
    storage_uri = var.dia_uri
  }
4

1 回答 1

0

我在没有括号的情况下实现了它

source_vm_id        = element(azurerm_virtual_machine.vm.*.id, count.index)
于 2020-07-01T16:09:31.733 回答