forked from asicsdigital/terraform-reference
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.envrc
31 lines (26 loc) · 911 Bytes
/
.envrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# shellcheck shell=bash
if [[ -f .env ]]; then
dotenv
fi
# auth against Vault if configured
if has vault; then
if [[ "$VAULT_ADDR" && "$VAULT_AUTH_GITHUB_TOKEN" ]]; then
log_status "vault: are we already authenticated?"
vault token lookup -format=json > /dev/null && vault token renew -format=json > /dev/null
if [[ "$?" == "0" ]]; then
log_status "vault: authenticated with existing token!"
else
log_status "vault: authenticate, since our token could not be refreshed"
vault login -method=github -no-print
log_status "vault: authenticated with new token!"
fi
fi
fi
function get_vault_kv {
vault_path=$1
vault_key=${2:-value}
if [[ "$VAULT_ADDR" ]]; then
VAULT_KV=$(curl -s -H "X-Vault-Token: $(cat ~/.vault-token )" -X GET $VAULT_ADDR/v1/${vault_path} | jq -r .data.${vault_key})
fi
}
# vim: set et fenc=utf-8 ff=unix ft=sh sts=2 sw=2 ts=2 :