Created
May 20, 2024 23:45
-
-
Save twoixter/e97d829b6f46edce757f09fb8fb2d283 to your computer and use it in GitHub Desktop.
Consul watch script to use templates with envsubst
This file contains 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
#!/bin/bash | |
# Create temporary file for setting up environment | |
TEMP_FILE="$(mktemp -q /tmp/consul.env.XXXXXXXXX)" || exit 1 | |
# Set trap to clean up file | |
trap 'rm -f -- "$TEMP_FILE"' EXIT | |
jq -rc '.[] | [(.Key | split("/") | last | ascii_upcase), (.Value | @base64d)] | "export " + join("=")' > $TEMP_FILE | |
source "$TEMP_FILE" | |
envsubst < test.consul.watch.template | |
# Clean up temporary file | |
rm -f -- "$TEMP_FILE" | |
# trap - EXIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment