» azurerm_recovery_replicated_vm

Manages a Azure recovery replicated vms (Azure to Azure). An replicated VM keeps a copiously updated image of the vm in another region in order to be able to start the VM in that region in case of a disaster.

» Example Usage

resource "azurerm_resource_group" "primary" {
  name     = "tfex-replicated-vm-primary"
  location = "West US"
}

resource "azurerm_resource_group" "secondary" {
  name     = "tfex-replicated-vm-secondary"
  location = "East US"
}

resource "azurerm_virtual_machine" "vm" {
  name                  = "vm"
  location              = "${azurerm_resource_group.primary.location}"
  resource_group_name   = "${azurerm_resource_group.primary.name}"
  vm_size               = "Standard_B1s"
  network_interface_ids = ["${azurerm_network_interface.vm.id}"]

  storage_image_reference {
    publisher = "OpenLogic"
    offer     = "CentOS"
    sku       = "7.5"
    version   = "latest"
  }

  storage_os_disk {
    name              = "vm-os-disk"
    os_type           = "Linux"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Premium_LRS"
  }

  os_profile {
    admin_username = "test-admin-123"
    admin_password = "test-pwd-123"
    computer_name  = "vm"
  }

  os_profile_linux_config {
    disable_password_authentication = false
  }
}

resource "azurerm_recovery_services_vault" "vault" {
  name                = "example-recovery-vault"
  location            = "${azurerm_resource_group.secondary.location}"
  resource_group_name = "${azurerm_resource_group.secondary.name}"
  sku                 = "Standard"
}

resource "azurerm_recovery_services_fabric" "primary" {
  name                = "primary-fabric"
  resource_group_name = "${azurerm_resource_group.secondary.name}"
  recovery_vault_name = "${azurerm_recovery_services_vault.vault.name}"
  location            = "${azurerm_resource_group.primary.location}"
}

resource "azurerm_recovery_services_fabric" "secondary" {
  name                = "secondary-fabric"
  resource_group_name = "${azurerm_resource_group.secondary.name}"
  recovery_vault_name = "${azurerm_recovery_services_vault.vault.name}"
  location            = "${azurerm_resource_group.secondary.location}"
}

resource "azurerm_recovery_services_protection_container" "primary" {
  name                 = "primary-protection-container"
  resource_group_name  = "${azurerm_resource_group.secondary.name}"
  recovery_vault_name  = "${azurerm_recovery_services_vault.vault.name}"
  recovery_fabric_name = "${azurerm_recovery_services_fabric.primary.name}"
}

resource "azurerm_recovery_services_protection_container" "secondary" {
  name                 = "secondary-protection-container"
  resource_group_name  = "${azurerm_resource_group.secondary.name}"
  recovery_vault_name  = "${azurerm_recovery_services_vault.vault.name}"
  recovery_fabric_name = "${azurerm_recovery_services_fabric.secondary.name}"
}

resource "azurerm_recovery_services_replication_policy" "policy" {
  name                                                 = "policy"
  resource_group_name                                  = "${azurerm_resource_group.secondary.name}"
  recovery_vault_name                                  = "${azurerm_recovery_services_vault.vault.name}"
  recovery_point_retention_in_minutes                  = "${24 * 60}"
  application_consistent_snapshot_frequency_in_minutes = "${4 * 60}"
}

resource "azurerm_recovery_services_protection_container_mapping" "container-mapping" {
  name                                      = "container-mapping"
  resource_group_name                       = "${azurerm_resource_group.secondary.name}"
  recovery_vault_name                       = "${azurerm_recovery_services_vault.vault.name}"
  recovery_fabric_name                      = "${azurerm_recovery_services_fabric.primary.name}"
  recovery_source_protection_container_name = "${azurerm_recovery_services_protection_container.primary.name}"
  recovery_target_protection_container_id   = "${azurerm_recovery_services_protection_container.secondary.id}"
  recovery_replication_policy_id            = "${azurerm_recovery_services_replication_policy.policy.id}"
}

resource "azurerm_storage_account" "primary" {
  name                     = "primaryrecoverycache"
  location                 = "${azurerm_resource_group.primary.location}"
  resource_group_name      = "${azurerm_resource_group.primary.name}"
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_virtual_network" "primary" {
  name                = "network1"
  resource_group_name = "${azurerm_resource_group.primary.name}"
  address_space       = ["192.168.1.0/24"]
  location            = "${azurerm_resource_group.primary.location}"
}

resource "azurerm_subnet" "primary" {
  name                 = "network1-subnet"
  resource_group_name  = "${azurerm_resource_group.primary.name}"
  virtual_network_name = "${azurerm_virtual_network.primary.name}"
  address_prefix       = "192.168.1.0/24"
}

resource "azurerm_network_interface" "vm" {
  name                = "vm-nic"
  location            = "${azurerm_resource_group.primary.location}"
  resource_group_name = "${azurerm_resource_group.primary.name}"

  ip_configuration {
    name                          = "vm"
    subnet_id                     = "${azurerm_subnet.primary.id}"
    private_ip_address_allocation = "Dynamic"
  }
}

resource "azurerm_recovery_replicated_vm" "vm-replication" {
  name                                      = "vm-replication"
  resource_group_name                       = "${azurerm_resource_group.secondary.name}"
  recovery_vault_name                       = "${azurerm_recovery_services_vault.vault.name}"
  source_recovery_fabric_name               = "${azurerm_recovery_services_fabric.primary.name}"
  source_vm_id                              = "${azurerm_virtual_machine.vm.id}"
  recovery_replication_policy_id            = "${azurerm_recovery_services_replication_policy.policy.id}"
  source_recovery_protection_container_name = "${azurerm_recovery_services_protection_container.primary.name}"

  target_resource_group_id                = "${azurerm_resource_group.secondary.id}"
  target_recovery_fabric_id               = "${azurerm_recovery_services_fabric.secondary.id}"
  target_recovery_protection_container_id = "${azurerm_recovery_services_protection_container.secondary.id}"

  managed_disk {
    disk_id                    = "${azurerm_virtual_machine.vm.storage_os_disk.0.managed_disk_id}"
    staging_storage_account_id = "${azurerm_storage_account.primary.id}"
    target_resource_group_id   = "${azurerm_resource_group.secondary.id}"
    target_disk_type           = "Premium_LRS"
    target_replica_disk_type   = "Premium_LRS"
  }
}

» Argument Reference

The following arguments are supported:


A managed_disk block supports the following:

» Attributes Reference

In addition to the arguments above, the following attributes are exported:

  • id - The resource ID.

» Import

Site recovery recovery vault fabric can be imported using the resource id, e.g.

terraform import azurerm_recovery_replicated_vm.vmreplication /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resource-group-name/providers/Microsoft.RecoveryServices/vaults/recovery-vault-name/replicationFabrics/fabric-name/replicationProtectionContainers/protection-container-name/replicationProtectedItems/vm-replication-name