azurepowershellterraformazure-rmazure-backup-vault

Is there any way to configure Azure Backup alert using terraform?


I have read few articles which says there is no direct way to do this using terraform, so I am using below approach but not sure is that right or wrong, could someone help me to setup

PowerShell Script (Set-BackupAlert.ps1)

param(
    [string]$recoveryServiceVaultName,
    [string]$resourceGroupName
)

Install-Module AzureRM -AllowClobber -Force
Import-Module -Name Azurerm

$recovery_vault = Get-AzRecoveryServicesVault -Name $recoveryServiceVaultName -ResourceGroupName $resourceGroupName
Set-AzRecoveryServicesAsrVaultContext -Vault $recovery_vault
Set-AzRecoveryServicesAsrAlertSetting -CustomEmailAddress "test@thomasthornton.cloud" -EnableEmailSubscriptionOwner

Terraform Script (main.tf)

resource "azurerm_resource_group" "rg" {
  name     = "tfex-recovery_vault"
  location = "West Europe"
}

resource "azurerm_recovery_services_vault" "vault" {
  name                = "example_recovery_vault"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  sku                 = "Standard"

  soft_delete_enabled = true

  provisioner "local-exec"
  {
        command = "PowerShell -file ./Set-BackupAlert.ps1 -recoveryServiceVaultName ${azurerm_recovery_services_vault.vault.name} -resourceGroupName ${azurerm_resource_group.rg.name}"
  }
}

Solution

  • The Powershell Script what you are using needs some changes. Either you need to upgrade the module or you need to use commands for the respective module that you are using.

    Also, as per this document, we came to know that this feature is not supported as of this post.

    Limitation for Powershell