Created
November 4, 2025 20:11
-
-
Save eujuliu/0aa34b207b7ab9979e93dd0c90bca475 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # Usage: ./env-to-vault.sh path/to/.env secret/path/in/vault key/path/in/vault | |
| # Example: ./env-to-vault.sh .env secret/data/myapp envs | |
| set -e | |
| if [ "$#" -ne 3 ]; then | |
| echo "Usage: $0 <.env file> <vault secret path> <vault key path>" | |
| exit 1 | |
| fi | |
| ENV_FILE="$1" | |
| VAULT_PATH="$2" | |
| KEYS_PATH="$3" | |
| if [ ! -f "$ENV_FILE" ]; then | |
| echo "Error: $ENV_FILE not found!" | |
| exit 1 | |
| fi | |
| KV_ARGS="" | |
| while IFS='=' read -r key value; do | |
| [[ "$key" =~ ^#.*$ || -z "$key" ]] && continue | |
| value="${value%\"}" | |
| value="${value#\"}" | |
| value="${value%\'}" | |
| value="${value#\'}" | |
| KV_ARGS+="$key=\"$value\" " | |
| done < "$ENV_FILE" | |
| echo "docker exec vault vault kv put -mount=$VAULT_PATH $KEYS_PATH $KV_ARGS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment