Last active
December 3, 2021 09:05
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
very helpful
Thanks a lot!
man, you rocket it!!! thanks a lot
Very helpful. Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot !!!