I have all my env vars in .env files. They get automatically loaded when I open my shell-terminal.
I normally render shell environment variables into my target files with envsubst. similar to the example below.
dotenv-file as well my template-file to a script which outputs the rendered result.Something like this:
aScript --input .env.production --template template-file.yml --output result.ymlI want to be able to parse different environment variables into my yaml. The output should be sealed via "Sealed secrets" and finally saved in the regarding kustomize folder
envsub.sh .env.staging templates/secrets/backend-secrets.yml | kubeseal -o yaml > kustomize/overlays/stagingI hope you get the idea.
example
.env.production-file:
FOO=bar PASSWROD=abc
content of template-file.yml
stringData:
foo: $FOO
password: $PASSWORDThen running this:
envsubst < template-file.yml > file-with-vars.ymlthe result is:
stringData:
foo: bar
password: abcMy approach so far does not work because Dotenv also supports different environments like .env, .env.production, .env.staging asf..
What about:
#!/bin/sh
# envsub - subsitute environment variables
env=$1
template=$2
sh -c "
. \"$env\"
cat <<EOF
$(cat "$template")
EOF"
Usage:
./envsub .env.production template-file.yaml > result.yamlEOF) expands variables, whilst preserving quotes, backslashes, and other shell sequences.sh -c is used like eval, to expand the command substitution, then run that output through a here-doc.For example, adding this:
EOF
echo malicous commandsBut it does get the result you want.