Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup gen_tf script to handle number type in CI #155

Merged
merged 2 commits into from
Oct 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions scripts/gen_tf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,37 @@ module_vars=$(cat <<-EOF
notifications = local.notifications
EOF
)
exclude_vars="[$(echo "$module_vars" | sed 's/^[[:space:]]*\([a-zA-z0-9_]*\)[[:space:]]*=.*$/"\1"/' | sed ':a;N;$!ba;s/\n/, /g')]"
env_vars=$(terraform-config-inspect $(dirname $0)/../test --json | jq -cr '.variables[] | select(.required) | .name')

for i in $(find ${TARGET} -type f -not -path "*/.terraform/*" -name 'detectors-*.tf'); do
dir=$(dirname $i)
vars_string=""
vars_list=$(terraform-config-inspect ${dir} --json | jq -cr '.variables[] | select(.required) | .name')
for var in ${vars_list}; do
vars_rendering=""
unset vars
declare -A vars
while IFS="=" read -r key value; do
vars[$key]="$value"
done < <(terraform-config-inspect ${dir} --json | jq --argjson ex "${exclude_vars}" -cr '.variables[] | select(.required) | select( .name as $a | $ex | index($a) | not ) | "\(.name)=\(.type)"')
for var in ${!vars[@]}; do
case ${vars[$var]} in
string)
val='"fillme"'
;;
number)
val=42
;;
*)
val=null
;;
esac
[[ ${env_vars} =~ (^|[[:space:]])$var($|[[:space:]]) ]] ||
echo "${module_vars}" | grep -q "^[[:space:]]*${var}" ||
vars_string="${vars_string}\n${var}=\"fillme\""
vars_rendering="${vars_rendering}\n${var}=$val"
done
cat <<-EOF > ${TMP}
module "signalfx-detectors-${dir//\//-}" {
source = "github.com/claranet/terraform-signalfx-detectors.git//${dir}?ref=${REF}"

${module_vars}$(echo -e ${vars_string})
${module_vars}$(echo -e ${vars_rendering})
}

EOF
Expand Down