Key Vault: Move Between Resource Groups
Overview
Moving an Azure Key Vault to a different resource group does not break web app access. The vault’s DNS URI (https://{vault-name}.vault.azure.net/) does not change, and all access policies and RBAC role assignments travel with the vault.
Use this runbook when reorganising resource groups or consolidating eSHARS infrastructure layout.
What Moves With the Vault
- All secrets, keys, and certificates
- Managed identity access policies
- RBAC role assignments scoped to the vault
- Soft-delete and purge protection settings
- Diagnostic settings do not move — see post-move steps
What Web Apps Are Affected By
Web apps connect via Key Vault references in App Settings:
@Microsoft.KeyVault(SecretUri=https://{vault-name}.vault.azure.net/secrets/{secret-name}/)The vault name is the only identifier used. Moving between RGs does not change the vault name, so app settings require no changes.
Prerequisites
- Azure CLI authenticated to the HISD tenant
Contributorrole on both the source and destination resource groups- If the vault has private endpoints: review the private endpoints runbook before proceeding
Before Moving
1. Check for private endpoints
az keyvault show \ --name {vault-name} \ --query "properties.privateEndpointConnections" \ -o tableIf any private endpoints exist, they must be deleted before the move and recreated afterward.
2. Check Terraform state
cd {path-to-eshars-ops}/infrastructuretofu state list | grep keyvaultNote the state address for reference. After the Azure move, update the Key Vault resource_group_name in OpenTofu/Terraform and run tofu plan / tofu apply.
You only need to run tofu state mv if the OpenTofu/Terraform resource address changes (for example, during a module refactor or resource rename), not just because the vault moved to a different resource group.
3. Note existing diagnostic settings
az monitor diagnostic-settings list \ --resource $(az keyvault show --name {vault-name} --query id -o tsv) \ -o tableSave the output — diagnostic settings must be reapplied after the move.
Performing the Move
The vault is locked for approximately 10 seconds during the move. No secrets or keys are affected.
# Get the vault resource IDVAULT_ID=$(az keyvault show --name {vault-name} --query id -o tsv)
# Move to the destination resource groupaz resource move \ --destination-group {destination-rg} \ --ids $VAULT_IDVerify:
az keyvault show --name {vault-name} --query resourceGroup -o tsvAfter Moving
1. Update Terraform state
Moving a Key Vault between resource groups does not change its Terraform resource address — tofu state mv is not needed. Simply update the resource_group_name argument in the relevant .tf file:
resource "azurerm_key_vault" "main" { name = "kv-eshars-prod" resource_group_name = "rg-eshars-core-prod" # ← update to new RG ...}Then run tofu plan to confirm Terraform sees no unintended changes (it should show zero diff beyond the RG name).
2. Reapply diagnostic settings
Recreate diagnostic settings using the saved output from the pre-move step, or via Terraform if managed there.
3. Update Azure Monitor alert rules
Alert rules scoped to the old resource ID stop working after a move. Check for KV-specific alerts:
az monitor alert list --resource-group {old-rg} -o tableUpdate or recreate any that reference the vault.
4. Verify web app access
Check that app services can still resolve secrets:
- Open the App Service in the portal
- Go to Configuration → verify KV references show a green tick (resolved)
- If not resolved within a few minutes, restart the app service
Rollback
The move cannot be automatically undone, but you can move the vault back to the original RG using the same az resource move command with the original RG as --destination-group.