Terraform Azure 配置 VM 备份策略失败
Terraform Azure Configure VM Backup Policy Fails
我正在尝试创建备份策略并启用备份,同时使用 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" {
│
Terraform 脚本
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 中启用备份时获取以下信息的进一步故障排除。
您收到错误是因为您使用的恢复保管库与 VM 不在同一位置。
我测试如下:
我在美国西部创建了 VM 并且 existing Recovery Services Vault 位于美国东部。所以,我收到以下错误:
要解决此问题,您必须对所有资源使用与恢复服务保管库相同的位置,即在我的情况下与资源组(美国东部)相同:
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
}
输出:
我正在尝试创建备份策略并启用备份,同时使用 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" {
│
Terraform 脚本
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 中启用备份时获取以下信息的进一步故障排除。
您收到错误是因为您使用的恢复保管库与 VM 不在同一位置。
我测试如下:
我在美国西部创建了 VM 并且 existing Recovery Services Vault 位于美国东部。所以,我收到以下错误:
要解决此问题,您必须对所有资源使用与恢复服务保管库相同的位置,即在我的情况下与资源组(美国东部)相同:
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
}
输出: