Skip to content

Instantly share code, notes, and snippets.

@twoixter
Created May 20, 2024 23:45
Show Gist options
  • Save twoixter/e97d829b6f46edce757f09fb8fb2d283 to your computer and use it in GitHub Desktop.
Save twoixter/e97d829b6f46edce757f09fb8fb2d283 to your computer and use it in GitHub Desktop.
Consul watch script to use templates with envsubst
#!/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