Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vineethvijay7/ad62676b058c99e2b4a001301d7d1f22 to your computer and use it in GitHub Desktop.
Save vineethvijay7/ad62676b058c99e2b4a001301d7d1f22 to your computer and use it in GitHub Desktop.
Terraform pre commit hook
#!/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