Created
March 17, 2025 16:22
-
-
Save vineethvijay7/ad62676b058c99e2b4a001301d7d1f22 to your computer and use it in GitHub Desktop.
Terraform pre commit hook
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
#!/bin/bash | |
# Define colors | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[1;33m' | |
BLUE='\033[0;34m' | |
NC='\033[0m' # No Color | |
# Start message | |
echo -e "${BLUE}π Running pre-push checks...${NC}" | |
# Run Terraform fmt | |
echo -e "${YELLOW}β¨ Formatting Terraform files...${NC}" | |
terraform fmt -recursive | |
if [ $? -ne 0 ]; then | |
echo -e "${RED}β Terraform formatting failed! Please fix the formatting.${NC}" | |
exit 1 | |
fi | |
echo -e "${GREEN}β Terraform formatting successful!${NC}" | |
# Run Terraform validate | |
echo -e "${YELLOW}π Validating Terraform configuration...${NC}" | |
terraform validate | |
if [ $? -ne 0 ]; then | |
echo -e "${RED}β Terraform validation failed! Please fix the errors.${NC}" | |
exit 1 | |
fi | |
echo -e "${GREEN}β Terraform validation successful!${NC}" | |
# Success message | |
echo -e "${GREEN}π All pre-push checks passed! Pushing your changes..... ${NC}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment