Skip to content

azurermBackupProtectedVm

Manages Azure Backup for an Azure VM

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "tfex-recovery_vault",
  }
);
const dataAzurermVirtualMachineExample =
  new azurerm.dataAzurermVirtualMachine.DataAzurermVirtualMachine(
    this,
    "example_1",
    {
      name: "production",
      resource_group_name: azurermResourceGroupExample.name,
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
dataAzurermVirtualMachineExample.overrideLogicalId("example");
const azurermRecoveryServicesVaultExample =
  new azurerm.recoveryServicesVault.RecoveryServicesVault(this, "example_2", {
    location: azurermResourceGroupExample.location,
    name: "tfex-recovery-vault",
    resource_group_name: azurermResourceGroupExample.name,
    sku: "Standard",
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermRecoveryServicesVaultExample.overrideLogicalId("example");
const azurermBackupPolicyVmExample = new azurerm.backupPolicyVm.BackupPolicyVm(
  this,
  "example_3",
  {
    backup: [
      {
        frequency: "Daily",
        time: "23:00",
      },
    ],
    name: "tfex-recovery-vault-policy",
    recovery_vault_name: azurermRecoveryServicesVaultExample.name,
    resource_group_name: azurermResourceGroupExample.name,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermBackupPolicyVmExample.overrideLogicalId("example");
new azurerm.backupProtectedVm.BackupProtectedVm(this, "vm1", {
  backup_policy_id: azurermBackupPolicyVmExample.id,
  recovery_vault_name: azurermRecoveryServicesVaultExample.name,
  resource_group_name: azurermResourceGroupExample.name,
  source_vm_id: dataAzurermVirtualMachineExample.id,
});

Argument Reference

The following arguments are supported:

  • resourceGroupName - (Required) The name of the resource group in which to create the Recovery Services Vault. Changing this forces a new resource to be created.

  • recoveryVaultName - (Required) Specifies the name of the Recovery Services Vault to use. Changing this forces a new resource to be created.

  • sourceVmId - (Optional) Specifies the ID of the VM to backup. Changing this forces a new resource to be created.

\~> NOTE: After creation, the sourceVmId property can be removed without forcing a new resource to be created; however, setting it to a different ID will create a new resource. This allows the source vm to be deleted without having to remove the backup.

  • backupPolicyId - (Required) Specifies the id of the backup policy to use.

  • excludeDiskLuns - (Optional) A list of Disks' Logical Unit Numbers(LUN) to be excluded for VM Protection.

  • includeDiskLuns - (Optional) A list of Disks' Logical Unit Numbers(LUN) to be included for VM Protection.

Attributes Reference

The following attributes are exported:

  • id - The ID of the Backup Protected Virtual Machine.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 80 minutes) Used when creating the Backup Protected Virtual Machine.
  • update - (Defaults to 80 minutes) Used when updating the Backup Protected Virtual Machine.
  • read - (Defaults to 5 minutes) Used when retrieving the Backup Protected Virtual Machine.
  • delete - (Defaults to 80 minutes) Used when deleting the Backup Protected Virtual Machine.

Import

Recovery Services Protected VMs can be imported using the resourceId, e.g.

terraform import azurerm_backup_protected_vm.item1 "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.RecoveryServices/vaults/example-recovery-vault/backupFabrics/Azure/protectionContainers/iaasvmcontainer;iaasvmcontainerv2;group1;vm1/protectedItems/vm;iaasvmcontainerv2;group1;vm1"

Note the ID requires quoting as there are semicolons