0

我正在尝试创建备份策略并启用备份,同时使用 terraform(Terraform 版本 - 1.1.13,Azure Provider - 2.90.0)预配 Azure VM。Terraform 无法启用备份并出现以下错误。

 Error: waiting for the Azure Backup Protected VM "VM;iaasvmcontainerv2;Test-product-cloud-infra;arulazurebkup-vm" to be true (Resource Group "Test-Product-Cloud-Infra") to provision: context deadline exceeded
│
│   with azurerm_backup_protected_vm.backup,
│   on main.tf line 176, in resource "azurerm_backup_protected_vm" "backup":
│  176: resource "azurerm_backup_protected_vm" "backup" {
│

地形脚本

resource "azurerm_backup_policy_vm" "example" {
  name                = "Test-backup-policy"
  resource_group_name = "Test-Product-Cloud-Infra"
  recovery_vault_name = "backuptest"

  backup {
    frequency = "Daily"
    time      = "23:00"
  }

  retention_daily {
    count = 7
  }
}

resource "azurerm_backup_protected_vm" "backup" {
  resource_group_name = "Test-Product-Cloud-Infra"
  recovery_vault_name = "backuptest"
  source_vm_id        = azurerm_virtual_machine.example.id
  backup_policy_id    = azurerm_backup_policy_vm.example.id

  depends_on = [azurerm_virtual_machine.example,
                azurerm_virtual_machine_extension.example,
                azurerm_backup_policy_vm.example]

}

当我在 Azure 门户中检查备份作业的错误时,我发现以下条目 门户错误

在 CLI 中启用备份时获得以下进一步故障排除。 在此处输入图像描述

4

1 回答 1

0

当您使用与 VM 不在同一位置的恢复库时,您会收到错误消息。

我测试如下:

我在美国西部创建了 VM,现有的恢复服务库位于美国东部。所以,我得到了以下错误:

在此处输入图像描述

在此处输入图像描述

要解决此问题,您必须对所有资源使用与恢复服务保管库相同的位置,即在我的情况下与资源组(美国东部)相同

resource "azurerm_virtual_machine" "main" {
  name                  = "ansuman-vm"
  location              = data.azurerm_resource_group.example.location
  resource_group_name   = data.azurerm_resource_group.example.name
  network_interface_ids = [azurerm_network_interface.example.id]
  vm_size               = "Standard_DS1_v2"

  # Uncomment this line to delete the OS disk automatically when deleting the VM
  # delete_os_disk_on_termination = true

  # Uncomment this line to delete the data disks automatically when deleting the VM
  # delete_data_disks_on_termination = true

  storage_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "16.04-LTS"
    version   = "latest"
  }
  storage_os_disk {
    name              = "myosdisk1"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"
  }
  os_profile {
    computer_name  = "hostname"
    admin_username = "testadmin"
    admin_password = "Password1234!"
  }
  os_profile_linux_config {
    disable_password_authentication = false
  }
}
data "azurerm_recovery_services_vault" "example" {
  name                = "recoveryvaultansuman"
  resource_group_name = data.azurerm_resource_group.example.name
}
resource "azurerm_backup_policy_vm" "example" {
  name                = "ansuman-recovery-vault-policy"
  resource_group_name = data.azurerm_resource_group.example.name
  recovery_vault_name = data.azurerm_recovery_services_vault.example.name

  backup {
    frequency = "Daily"
    time      = "23:00"
  }
  retention_daily {
    count = 7
  }
}

resource "azurerm_backup_protected_vm" "vm1" {
  resource_group_name = data.azurerm_resource_group.example.name
  recovery_vault_name = data.azurerm_recovery_services_vault.example.name
  source_vm_id        = azurerm_virtual_machine.main.id
  backup_policy_id    = azurerm_backup_policy_vm.example.id
}

输出:

在此处输入图像描述

于 2022-01-18T07:23:00.147 回答