#!/usr/bin/env bash
# Quick Terraform status checker

echo "=== Terraform Status Check ==="
echo ""

if ps aux | grep -q '[t]erraform apply'; then
  echo "✅ Terraform RUNNING"
  ps aux | grep '[t]erraform apply' | grep -v grep | head -1 | awk '{print "   PID: "$2", CPU: "$3"%, MEM: "$4"%"}'
else
  echo "⏳ Terraform IDLE/COMPLETE"
fi

echo ""
echo "Latest log file:"
ls -t /tmp/terraform-apply-*.log 2>/dev/null | head -1 | xargs -I {} sh -c 'echo "   {}" && tail -3 {}'

echo ""
echo "Cluster status:"
READY=$(az aks list --subscription fc08d829-4f14-413d-ab27-ce024425db0b --query "[?contains(name, 'az-p-') && provisioningState == 'Succeeded'].name" -o tsv 2>/dev/null | wc -l)
CREATING=$(az aks list --subscription fc08d829-4f14-413d-ab27-ce024425db0b --query "[?contains(name, 'az-p-') && provisioningState == 'Creating'].name" -o tsv 2>/dev/null | wc -l)
echo "   Ready: $READY/24"
echo "   Creating: $CREATING"
