pull/81/head
Muhammad Atif Ali 2 years ago
parent 279de5773f
commit 43ac2c67d9
No known key found for this signature in database

@ -64,7 +64,7 @@ resource "coder_script" "vault" {
VAULT_ADDR : var.vault_addr,
VAULT_TOKEN : data.coder_git_auth.vault.access_token,
VERSION : var.vault_cli_version,
SECRETS : replace(replace(jsonencode(var.secrets), "\"", "\\\""), "/", "::")
SECRETS : replace(replace(jsonencode(var.secrets), "\"", "\\\""), "/", "_")
})
run_on_start = true
}

@ -69,20 +69,18 @@ if [ "${SECRETS}" = "{}" ]; then
exit 0
fi
# Replace :: back to / in the SECRETS string
SECRETS=$(echo "${SECRETS}" | sed 's/::/\//g')
# Now process the SECRETS string as before...
printf "🔍 Fetching secrets ...\n\n"
for key in $(echo "$${SECRETS}" | jq -r "keys[]" ); do
secrets=$(echo "$${SECRETS}" | jq -r ".$key.secrets[]")
file=$(echo "$${SECRETS}" | jq -r ".$key.file")
printf "Fetching secrets from $${key} ...\n"
for key in $(echo "${SECRETS}" | jq -r "keys[]" ); do
formatted_key=$(echo "${key}" | tr '_' '/')
secrets=$(echo "${SECRETS}" | jq -r ".$key.secrets[]")
file=$(echo "${SECRETS}" | jq -r ".$key.file")
printf "Fetching secrets from $${formatted_key} ...\n"
for secret in $${secrets}; do
value=$(vault kv get -format=json $${key} | jq -r ".data.data.$${secret}")
value=$(vault kv get -format=json $${formatted_key} | jq -r ".data.data.$${secret}")
# create directory if it doesn't exist
mkdir -p $(dirname $${file})
printf "$${secret}=$${value}\n" >> $${file}
done
printf "\n"
done

Loading…
Cancel
Save