Skip to content

Instantly share code, notes, and snippets.

@artem-hatchenko
Created February 7, 2023 15:28
Show Gist options
  • Save artem-hatchenko/56a06e0fad892b03675953e7ee229937 to your computer and use it in GitHub Desktop.
Save artem-hatchenko/56a06e0fad892b03675953e7ee229937 to your computer and use it in GitHub Desktop.
# Get the list of ALL modules in the form: "./rds/common", "./rds/instance" etc.
MODULES="$(cd $TF_DIR/$MODULE_DIR; find . -type f -name '*.tf' -exec dirname {} \;)"
SORTED="$(echo $MODULES | sed -e $'s/ /\\\n/g' | sort | uniq)"
# Get the list of used modules from the INPUT_MODULE_LIST variable (i.e. "ecr,rds,eks", "s3")
IFS=',' read -ra INPUT_MODULE_LIST <<<"$INPUT_MODULE_LIST"
#If the modules used (INPUT_MODULE_LIST variable) are in the list of all modules (SORTED variable),
# then we call the "check_modules()" function and use the "tflint" command for the module being checked
if [ -n "${INPUT_MODULE_LIST}" ]; then
for INPUT_MODULE in "${INPUT_MODULE_LIST[@]}"; do
for MODULE in $SORTED; do
if [[ "$MODULE" == *"$INPUT_MODULE"* ]]; then
check_modules $MODULE
fi
done
done
else
for MODULE in $SORTED
do
check_modules $MODULE
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment