Infra & Cloud bash Intermediate

Vault Secret Fetcher

Retrieve a secret from HashiCorp Vault using the CLI and export as environment variables.

bash
#!/bin/bash
VAULT_ADDR=${VAULT_ADDR:-http://vault:8200}
SECRET_PATH=${1:-secret/myapp/production}

vault login -method=aws 2>/dev/null

vault kv get -format=json $SECRET_PATH \
  | jq -r ".data.data | to_entries[] | \"export \(.key)=\(.value | @sh)\"" \
  > /tmp/secrets.sh

source /tmp/secrets.sh
rm -f /tmp/secrets.sh
echo "Secrets loaded from $SECRET_PATH"

Prerequisites

  • vault CLI
  • HashiCorp Vault
  • jq

Pro Tips

  • → Use Vault Agent for automatic secret renewal in containers.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
bash
Level
Intermediate
Read time
3 min
Published
Jun 2026
License
Commercial License

Newsletter

New modules every week, directly to your inbox.