I am using Terraform to create Azure Recovery Services Vault for File Shares. But it keeps reporting error:
Error: registering backup protection container StorageContainer;storage;fer-bpcm-d-rsg-commonsa;xxxbpcmpcgl (Vault fer-bpcm-p-euwe-rvt-golden): backup.ProtectionContainersClient#Register: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BMSUserErrorContainerIsAssociatedWithAnotherVault" Message="Container is associated with another vault. Please select the right vault to proceed with the container operation."
with module.recovery_services_vault.azurerm_backup_container_storage_account.protection_container["fer-bpcm-p-euwe-rvt-golden~xxxbpcmpcgl~data"],
on ../modules/LandingZone/BPCM/recovery_services_vault/main.tf line 75, in resource "azurerm_backup_container_storage_account" "protection_container":
75: resource "azurerm_backup_container_storage_account" "protection_container" {
The terraform snippet is as below:
resource "azurerm_recovery_services_vault" "fs_rsv_vaults" {
for_each = { for fs_rsv_vault in var.fileshare_recovery_vaults : fs_rsv_vault.name => fs_rsv_vault }
name = each.value.name
resource_group_name = each.value.resource_group_name
location = each.value.location
# sku, immutability, storage_mode_type, soft_delete_enabled
# public_network_access_enabled, cross_region_restore_enabled, tags,identity
}
resource "azurerm_backup_policy_file_share" "rsv_vault_policy" {
for_each = { for policy in local.rsv_vault_policy_list : "${policy.vault_name}~${policy.policy_name}" => policy }
name = each.value.policy_name
resource_group_name = azurerm_recovery_services_vault.fs_rsv_vaults[each.value.vault_name].resource_group_name
recovery_vault_name = azurerm_recovery_services_vault.fs_rsv_vaults[each.value.vault_name].name
# timezone, backup, retention_daily
}
resource "azurerm_backup_container_storage_account" "protection_container" {
for_each = { for fileshare in local.fileshare_list : "${fileshare.recovery_vault_name}~${fileshare.storage_account_name}~${fileshare.source_file_share_name}" => fileshare }
resource_group_name = azurerm_recovery_services_vault.fs_rsv_vaults[each.value.recovery_vault_name].resource_group_name
recovery_vault_name = each.value.recovery_vault_name
storage_account_id = data.azurerm_storage_account.storage_accounts[each.value.storage_account_name].id
}
I checked documetation But how to associate a unique protection container azurerm_backup_container_storage_account
to each of the storage account since there is no name
argument for protection container ? What is wrong I am doing?
I am passing list of Storage accounts like this:
fileshare_recovery_vaults = [
{
name = "myvault"
resource_group_name = "rsg-backup"
...
backup_policies = [
{
policy_name = "policy-filesh"
timezone = "UTC"
backup_frequency = "Daily"
backup_time = "00:00"
retention_daily_count = 30
}
]
fileshares = [
{
storage_account_name = "xxxbpcmpcga"
source_file_share_name = "data"
resource_group_name = "rsg-commonsa"
policy_name = "policy-filesh"
},
{
storage_account_name = "xxxbpcmpcgl"
source_file_share_name = "data"
resource_group_name = "rsg-commonsa"
policy_name = "policy-filesh"
}
]
..
}]
The error you're encountering,
BMSUserErrorContainerIsAssociatedWithAnotherVault
, indicates that the storage container you're trying to register with the Azure Recovery Services Vault is already associated with another vault. This is a common issue when reusing storage accounts or containers that were previously associated with a different vault.when I tired to link the a new Recovery service vault with a storage container which was already associated with another vault I faced the same Issue which you mentioned.
In Azure, a storage account container can only be associated with one Recovery Services vault at a time. If you try to associate it with a new vault without first disassociating it from the existing one, you'll encounter this error
My Terraform configuration:
variable.tf:
terraform.tfvars:
Output: