Last active
June 26, 2023 22:52
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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