27 lines
775 B
Bash
Executable File
27 lines
775 B
Bash
Executable File
#! /usr/bin/env bash
|
|
|
|
function _tf-pre-plan() {
|
|
[ -z "$SZ_TF_NAME" ] \
|
|
&& echo "ERROR: SZ_TF_NAME isn't declared!" \
|
|
&& return 1
|
|
|
|
[[ "${*}" =~ .*--no-delete.* ]] || find . -name "_.gen.*" -delete
|
|
|
|
for TF_TMPL_FILE in $(bash -c 'shopt -s nullglob; echo *.sz_tmpl'); do
|
|
local OUT_FILE="${TF_TMPL_FILE%\.sz_tmpl}"
|
|
OUT_FILE="_.gen.${SZ_TF_NAME}.${OUT_FILE#_sz\.}"
|
|
|
|
echo "Generating ${OUT_FILE} file..."
|
|
printf "%s\n" \
|
|
"# DO NOT EDIT THIS FILE!!!! " \
|
|
"# This file was autogenerated by \`_tf-pre-plan\` from ${TF_TMPL_FILE}" \
|
|
"" \
|
|
"$( envsubst < "${TF_TMPL_FILE}" )" \
|
|
> "${OUT_FILE}"
|
|
done
|
|
printf "\n\n" >&2
|
|
}
|
|
|
|
_tf-pre-plan "${@}"
|
|
unset _tf-pre-plan
|