Skip to content

Instantly share code, notes, and snippets.

@rudolfolah
Last active June 26, 2023 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rudolfolah/4e1440e1a7262ec8c7af0517df0aa2fe to your computer and use it in GitHub Desktop.
Save rudolfolah/4e1440e1a7262ec8c7af0517df0aa2fe to your computer and use it in GitHub Desktop.
Code for checking Terraform configuration: runs the formatter, validator, linting and security checks
# Install:
# brew install tflint
# brew install tfsec
# brew install terraform
# nano /path/to/check_tf.sh
# chmod +x /path/to/check_tf.sh
#
# Usage:
# cd /path/to/terraform/tf_files
# tflint --init
# TFLINT_CONFIG=$(realpath ./.tflint.hcl) ./check_tf.sh
# TFLINT_CONFIG=/path/to/.tflint.hcl /path/to/check_tf.sh
if [ "$TFLINT_CONFIG" = '' ]; then
echo 'the TFLINT_CONFIG environment variable must be set'
exit 1
fi
echo "Checking Terraform configuration..."
echo "Formatting..."
terraform fmt
echo "Linting..."
tflint --config="$TFLINT_CONFIG" --recursive
echo "Checking security..."
tfsec
echo "Validating..."
terraform validate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment