Skip to content

Instantly share code, notes, and snippets.

@syedhassaanahmed
Last active December 3, 2021 09:05
Show Gist options
  • Select an option

  • Save syedhassaanahmed/b423dd38af2f6b53a454fe0f8c06d843 to your computer and use it in GitHub Desktop.

Select an option

Save syedhassaanahmed/b423dd38af2f6b53a454fe0f8c06d843 to your computer and use it in GitHub Desktop.
Copy secrets from one Azure Key Vault to another assuming they're both in the same Azure subscription
#!/bin/bash
set -euo pipefail
SOURCE_KV="<source_key_vault_name>"
DEST_KV="<destination_key_vault_name>"
SOURCE_SECRETS=$(az keyvault secret list --vault-name $SOURCE_KV --query "[].id" -o tsv | cut -d "/" -f5)
DEST_SECRETS=$(az keyvault secret list --vault-name $DEST_KV --query "[].id" -o tsv | cut -d "/" -f5)
MISSING_SECRETS=$(echo "${SOURCE_SECRETS} ${DEST_SECRETS}" | tr ' ' '\n' | sort | uniq -u)
for MISSING_SECRET in $MISSING_SECRETS
do
MISSING_VALUE=$(az keyvault secret show --vault-name $SOURCE_KV -n $MISSING_SECRET --query "value" -o tsv)
az keyvault secret set --vault-name $DEST_KV -n $MISSING_SECRET --value "$MISSING_VALUE"
done
@taomoh

taomoh commented Dec 3, 2021

Copy link
Copy Markdown

Very helpful. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment