我读过几篇文章说没有直接的方法可以使用 terraform 来做到这一点,所以我使用下面的方法,但不确定是对还是错,有人可以帮我设置
PowerShell 脚本 (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 脚本 (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}"
}
}