如何解决 azurerm_backup_protected_vm 中的超时错误?
How to resolve timeout error in azurerm_backup_protected_vm?
我正在尝试使用 terraform 创建 azurerm_backup_protected_vm 但在创建资源时出现超时错误,下面是我的 terraform 文件。
Terraform 版本 - v0.13.3
main.tf
resource "azurerm_resource_group" "example" {
name = "tfex-recovery_vault"
location = "West US"
}
resource "azurerm_recovery_services_vault" "example" {
name = "tfex-recovery-vault"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
sku = "Standard"
}
resource "azurerm_backup_policy_vm" "example" {
name = "tfex-recovery-vault-policy"
resource_group_name = azurerm_resource_group.example.name
recovery_vault_name = azurerm_recovery_services_vault.example.name
backup {
frequency = "Daily"
time = "23:00"
}
}
resource "azurerm_backup_protected_vm" "vm_backup" {
resource_group_name = azurerm_resource_group.example.name
recovery_vault_name = azurerm_recovery_services_vault.example.name
source_vm_id = azurerm_virtual_machine.example.id
backup_policy_id = azurerm_backup_policy_vm.example.id
}
当我 运行 terraform 应用命令 resource group
、recovery service vault
、backup policy
成功创建但在创建 [=35= 时出现以下错误]
module.vm-linux.azurerm_backup_protected_vm.vm_backup: Still creating... [1h19m20s elapsed]
module.vm-linux.azurerm_backup_protected_vm.vm_backup: Still creating... [1h19m30s elapsed]
module.vm-linux.azurerm_backup_protected_vm.vm_backup: Still creating... [1h19m40s elapsed]
module.vm-linux.azurerm_backup_protected_vm.vm_backup: Still creating... [1h19m50s elapsed]
module.vm-linux.azurerm_backup_protected_vm.vm_backup: Still creating... [1h20m0s elapsed]
Error: Error waiting for the Azure Backup Protected VM "VM;iaasvmcontainerv2;PZI-GXU2-N-RGP-SB000-D065;U2ZSB000WDLV032" to be true (Resource Group "PZI-GXU2-N-RGP-SB000-D065") to provision: timeout while waiting for state to become 'Found' (last state: 'NotFound', timeout: 1h20m0s)
on modules/vm-linux/main.tf line 76, in resource "azurerm_backup_protected_vm" "vm_backup":
76: resource "azurerm_backup_protected_vm" "vm_backup" {
在这种情况下,我建议在备份相关资源中添加 depends_on 元参数,以确保在配置 VM 后启用备份 VM。
resource "azurerm_recovery_services_vault" "example" {
#..
depends_on = [azurerm_virtual_machine.example]
}
resource "azurerm_backup_policy_vm" "example" {
#..
depends_on = [azurerm_virtual_machine.example]
}
resource "azurerm_backup_protected_vm" "vm_backup" {
#..
depends_on = [azurerm_virtual_machine.example]
}
Here是一个示例,供更多参考。
# This resource is defined to fix the timeout problem in the creation of 'azurerm_recovery_services_protected_vm.*' resources
resource "null_resource" "delay" {
provisioner "local-exec" {
command = "sleep 180"
}
depends_on = [
"azurerm_virtual_machine.portal",
"azurerm_virtual_machine.engine",
"azurerm_virtual_machine.gateway",
]
}
resource "azurerm_recovery_services_protected_vm" "portal" {
resource_group_name = "${data.azurerm_resource_group.default.name}"
recovery_vault_name = "${data.terraform_remote_state.shell.backup_vault_name}"
source_vm_id = "${azurerm_virtual_machine.portal.id}"
backup_policy_id = "${data.terraform_remote_state.shell.backup_policy_id}"
depends_on = ["null_resource.delay"]
}
resource "azurerm_recovery_services_protected_vm" "engine" {
count = "${var.number_of_engines}"
resource_group_name = "${data.azurerm_resource_group.default.name}"
recovery_vault_name = "${data.terraform_remote_state.shell.backup_vault_name}"
source_vm_id = "${element(azurerm_virtual_machine.engine.*.id, count.index)}"
backup_policy_id = "${data.terraform_remote_state.shell.backup_policy_id}"
depends_on = ["null_resource.delay"]
}
resource "azurerm_recovery_services_protected_vm" "gateway" {
count = "${var.number_of_gateways}"
resource_group_name = "${data.azurerm_resource_group.default.name}"
recovery_vault_name = "${data.terraform_remote_state.shell.backup_vault_name}"
source_vm_id = "${element(azurerm_virtual_machine.gateway.*.id, count.index)}"
backup_policy_id = "${data.terraform_remote_state.shell.backup_policy_id}"
depends_on = ["null_resource.delay"]
}
我正在尝试使用 terraform 创建 azurerm_backup_protected_vm 但在创建资源时出现超时错误,下面是我的 terraform 文件。
Terraform 版本 - v0.13.3
main.tf
resource "azurerm_resource_group" "example" {
name = "tfex-recovery_vault"
location = "West US"
}
resource "azurerm_recovery_services_vault" "example" {
name = "tfex-recovery-vault"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
sku = "Standard"
}
resource "azurerm_backup_policy_vm" "example" {
name = "tfex-recovery-vault-policy"
resource_group_name = azurerm_resource_group.example.name
recovery_vault_name = azurerm_recovery_services_vault.example.name
backup {
frequency = "Daily"
time = "23:00"
}
}
resource "azurerm_backup_protected_vm" "vm_backup" {
resource_group_name = azurerm_resource_group.example.name
recovery_vault_name = azurerm_recovery_services_vault.example.name
source_vm_id = azurerm_virtual_machine.example.id
backup_policy_id = azurerm_backup_policy_vm.example.id
}
当我 运行 terraform 应用命令 resource group
、recovery service vault
、backup policy
成功创建但在创建 [=35= 时出现以下错误]
module.vm-linux.azurerm_backup_protected_vm.vm_backup: Still creating... [1h19m20s elapsed]
module.vm-linux.azurerm_backup_protected_vm.vm_backup: Still creating... [1h19m30s elapsed]
module.vm-linux.azurerm_backup_protected_vm.vm_backup: Still creating... [1h19m40s elapsed]
module.vm-linux.azurerm_backup_protected_vm.vm_backup: Still creating... [1h19m50s elapsed]
module.vm-linux.azurerm_backup_protected_vm.vm_backup: Still creating... [1h20m0s elapsed]
Error: Error waiting for the Azure Backup Protected VM "VM;iaasvmcontainerv2;PZI-GXU2-N-RGP-SB000-D065;U2ZSB000WDLV032" to be true (Resource Group "PZI-GXU2-N-RGP-SB000-D065") to provision: timeout while waiting for state to become 'Found' (last state: 'NotFound', timeout: 1h20m0s)
on modules/vm-linux/main.tf line 76, in resource "azurerm_backup_protected_vm" "vm_backup":
76: resource "azurerm_backup_protected_vm" "vm_backup" {
在这种情况下,我建议在备份相关资源中添加 depends_on 元参数,以确保在配置 VM 后启用备份 VM。
resource "azurerm_recovery_services_vault" "example" {
#..
depends_on = [azurerm_virtual_machine.example]
}
resource "azurerm_backup_policy_vm" "example" {
#..
depends_on = [azurerm_virtual_machine.example]
}
resource "azurerm_backup_protected_vm" "vm_backup" {
#..
depends_on = [azurerm_virtual_machine.example]
}
Here是一个示例,供更多参考。
# This resource is defined to fix the timeout problem in the creation of 'azurerm_recovery_services_protected_vm.*' resources
resource "null_resource" "delay" {
provisioner "local-exec" {
command = "sleep 180"
}
depends_on = [
"azurerm_virtual_machine.portal",
"azurerm_virtual_machine.engine",
"azurerm_virtual_machine.gateway",
]
}
resource "azurerm_recovery_services_protected_vm" "portal" {
resource_group_name = "${data.azurerm_resource_group.default.name}"
recovery_vault_name = "${data.terraform_remote_state.shell.backup_vault_name}"
source_vm_id = "${azurerm_virtual_machine.portal.id}"
backup_policy_id = "${data.terraform_remote_state.shell.backup_policy_id}"
depends_on = ["null_resource.delay"]
}
resource "azurerm_recovery_services_protected_vm" "engine" {
count = "${var.number_of_engines}"
resource_group_name = "${data.azurerm_resource_group.default.name}"
recovery_vault_name = "${data.terraform_remote_state.shell.backup_vault_name}"
source_vm_id = "${element(azurerm_virtual_machine.engine.*.id, count.index)}"
backup_policy_id = "${data.terraform_remote_state.shell.backup_policy_id}"
depends_on = ["null_resource.delay"]
}
resource "azurerm_recovery_services_protected_vm" "gateway" {
count = "${var.number_of_gateways}"
resource_group_name = "${data.azurerm_resource_group.default.name}"
recovery_vault_name = "${data.terraform_remote_state.shell.backup_vault_name}"
source_vm_id = "${element(azurerm_virtual_machine.gateway.*.id, count.index)}"
backup_policy_id = "${data.terraform_remote_state.shell.backup_policy_id}"
depends_on = ["null_resource.delay"]
}