I am trying to configure the Disaster Recovery of our azure Windows Virtual Machines in "West Europe" to "North Europe" region using terraform. And we are using azurerm_site_recovery_replicated_vm for that, but I am getting problem in encryption part.
- On our windows VM configuration, we are using azurem_virtual_machine_extension "AzureDiskEncryption" for the encryption of disks.
### azurem_virtual_machine_extension
win_s_01_ext04 = {
name = "AzureDiskEncryption"
virtual_machine_id = module.virtual_machine_servers.0.windows_virtual_machines["win_s_01"].id
publisher = "Microsoft.Azure.Security"
type = "AzureDiskEncryption"
type_handler_version = "2.2"
auto_upgrade_minor_version = true
automatic_upgrade_enabled = null
settings = <<SETTINGS
{
"EncryptionOperation": "EnableEncryption",
"KeyVaultURL": "${data.azurerm_key_vault.enc_kv.vault_uri}",
"KeyVaultResourceId": "${data.azurerm_key_vault.enc_kv.id}",
"KeyEncryptionKeyURL": "${data.azurerm_key_vault_key.enc_kv.id}",
"KekVaultResourceId": "${data.azurerm_key_vault.enc_kv.id}",
"KeyEncryptionAlgorithm": "RSA-OAEP",
"VolumeType": "All"
}
SETTINGS
protected_settings = null
tags = module.tagging.module_tags
depends_on = [
module.virtual_machine_servers.0.windows_virtual_machines["win_s_01"].id
]
}
- When I tried to create azurerm_site_recovery_replicated_vm there is a required parameter for "Key vault Secret URL" and it needs to be the exact one used to encrypt on the original disks in "West Europe".And the problem is there are no option to specify what "keyvault secret URL" to be used when creating the VM and disk using the "AzureDiskEncryption" extension so it created/used random secret URL like this "secretUrl": "https://we-kv-prod-01.vault.azure.net/secrets/016CFB82-C29B-4542-A887-9B1F0BFD985A/2de208f261ee4e24a445669ae86a63f4".
For the meantime, I tried to copy manually the Keyvault secret URL in "West Europe" to "North Europe" that is being used by the os disk VM encryption and call it using data so the secret url in North Europe will be like this ""secretUrl": "https://we-kv-prod-01-asr.vault.azure.net/secrets/016CFB82-C29B-4542-A887-9B1F0BFD985A/2de208f261ee4e24a445669ae86a63f4"".
### DATA
data "azurerm_key_vault_secret" "asr_enc_kv" {
provider = azurerm.APPS_EU_PROD
name = "2506512E-84FA-464C-A802-2E64F16DB384"
key_vault_id = data.azurerm_key_vault.asr_enc_kv.id
}
### azurerm_site_recovery_replicated_vm
managed_disk = [
{
disk_id = data.azurerm_managed_disk.osdisk_01.id
staging_storage_account_id = data.azurerm_storage_account.rsv.id
target_resource_group_id = module.resource_group_asr.0.resource_groups["rg_asr_01"].id
target_disk_type = "Standard_LRS"
target_replica_disk_type = "Standard_LRS"
target_disk_encryption_set_id = null
target_disk_encryption = [
{
disk_encryption_key = [
{
secret_url = data.azurerm_key_vault_secret.asr_enc_kv.id
vault_id = data.azurerm_key_vault.asr_enc_kv.id
}
]
key_encryption_key = [
{
key_url = data.azurerm_key_vault_key.asr_enc_kv.id
vault_id = data.azurerm_key_vault.asr_enc_kv.id
}
]
}
]
}
Does anyone know how can I replicate the "Key vault secret URL" in "North Europe" region using terraform and without doing any manual configuration. Or maybe give me some idea on how to handle the encryption for azurerm_site_recovery_replicated_vm?
Thanks in advance!