gpt4 book ai didi

azure - 如何使用 terraform 模板将 Azure VM 添加到恢复服务保管库中?

转载 作者:行者123 更新时间:2023-12-03 01:40:02 26 4
gpt4 key购买 nike

我正在开发一个 terraform 模板,以自动将新建的 Azure VM 注册到 Azure 恢复服务保管库。我在 Azurerm 提供程序中可以找到的所有资源是

azurerm_recovery_services_protection_policy_vm

azurerm_recovery_services_protected_vm

azurerm_recovery_services_vault

似乎他们都无法将虚拟机注册到恢复服务保管库。 Terraform有这个功能吗?

最佳答案

您可以在 Terraform 中看到 azurerm_recovery_services_protected_vm,参数 source_vm_id 显示:

Specifies the ID of the VM to backup

它可以指您要在恢复服务保管库中备份的虚拟机。使用 azurerm_recovery_services_protection_policy_vm 创建策略,并使用 azurerm_recovery_services_vault 创建恢复服务保管库。

更新

您可以通过 Terraform 使用 azurerm_recovery_services_protected_vm 备份带有恢复保管库的虚拟机。代码如下:

data "azurerm_virtual_machine" "azurevm" {
name = "vm_name"
resource_group_name = "group_name"
}

resource "azurerm_resource_group" "rg" {
name = "recovery_group_name"
location = "eastus"
}

resource "azurerm_recovery_services_vault" "vault" {
name = "azurerecoveryvaulti1"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
sku = "Standard"
}

resource "azurerm_recovery_services_protection_policy_vm" "test" {
name = "azurerecoveryvaultpolicy1"
resource_group_name = "${azurerm_resource_group.rg.name}"
recovery_vault_name = "${azurerm_recovery_services_vault.vault.name}"

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

retention_daily = {
count = 1
}
}

resource "azurerm_recovery_services_protected_vm" "example" {
resource_group_name = "${azurerm_resource_group.rg.name}"
recovery_vault_name = "${azurerm_recovery_services_vault.vault.name}"
source_vm_id = "${data.azurerm_virtual_machine.azurevm.id}"
backup_policy_id = "${azurerm_recovery_services_protection_policy_vm.test.id}"
}

为了进行测试,我创建了新的恢复保管库。您可以将现有的数据与 data azurerm_recovery_services_vault 结合使用。创建一个新策略,然后使用 azurerm_recovery_services_protected_vm 创建备份虚拟机,如上所示。

关于azure - 如何使用 terraform 模板将 Azure VM 添加到恢复服务保管库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54564906/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com