Skip to content

Instantly share code, notes, and snippets.

@javatarz
Created August 26, 2019 13:48
Show Gist options
  • Save javatarz/1497470a61c9f06689deaaf19a1610e1 to your computer and use it in GitHub Desktop.
Save javatarz/1497470a61c9f06689deaaf19a1610e1 to your computer and use it in GitHub Desktop.
Checks tfvars for hyphens
#!/bin/bash
function parse_and_test_properties_entries() {
prop=$1
if [[ "$prop" == "" || $prop = \#* ]]; then
continue
fi
key="$(cut -d'=' -f1 <<<"$prop")"
if [[ $key =~ "-" ]]; then
echo "$filename contains \"$key\" which contains a hyphen"
exit 1
fi
}
function parse_file() {
filename=$1
OLD_IFS=$IFS
props=$(cat $filename)
IFS=$'\n'
for prop in ${props[@]}; do
parse_and_test_properties_entries $prop
done
IFS=$OLD_IFS
}
base_dir="config"
for sub_dir in $(find $base_dir -mindepth 1 -maxdepth 1 -type d); do
workspace_name=${sub_dir#"$base_dir/"}
for input_file in config/$workspace_name/*.tfvars; do
parse_file $input_file
done
echo "All variables are named correctly in config/$workspace_name"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment