This script allows keyvault secrets to be synced to local .env files.
- Enables local development and secret synchronization amongst multiple team members and devices.
- Keep development secrets centralised in Azure Keyvaults and out of git or floating around other platforms
- Protect sensitive information with Azures keyvault IAM (local dev secrets should be completely different from other environment keyvaults)
./azure-keyvault-env-file-sync.sh -k keyvault-name
Takes an argument -k for the name of an Azure Keyvault you want to sync environment variables from
- If the user is not already logged into azure using 'az login', they will be directed to login via their default browser
- The logged in user must have permission to list and pull the relevant secrets from the keyvault
- Each secret in the specified keyvault must have tags named EnvVariableName and EnvFilePath with the appropriate values otherwise it will be ignored
- The EnvFilePath tag value represents the relative file path from current working directory to the .env file without a leading /. e.g. tmp/test/.env
Below is an example of two tags that would be added to a keyvault secret
EnvVariableName = ENV_VAR_NAME
EnvFilePath = apps/api/.env
...will result in a file apps/api/.env
with the contents
ENV_VAR_NAME=<SECRET_VALUE>
Multiple comma delimited variable names and file paths can be provided for a single keyvault secret where both names and values will be synced to both files
EnvVariableName = ENV_VAR_NAME,ENV_VAR_NAME_ALT
EnvFilePath = apps/api/.env,apps/app/.env
File Format templates can be created in the same directory as destination filepaths with .template
suffix. These template files are safe to track with git if you don't mind having variable names tracked.
apps/api/.env
apps/api/.env.template