#!/bin/bash source ~/.bashrc # Start Deployment Script # Guides through initial VM creation and setup set -e # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' CYAN='\033[0;36m' NC='\033[0m' log_info() { echo -e "${GREEN}[INFO]${NC} $1" } log_warn() { echo -e "${YELLOW}[WARN]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } log_step() { echo -e "${BLUE}[STEP]${NC} $1" } log_header() { echo -e "${CYAN}========================================${NC}" echo -e "${CYAN}$1${NC}" echo -e "${CYAN}========================================${NC}" } # Load environment variables if [ -f .env ]; then set -a source <(grep -v '^#' .env | grep -v '^$' | sed 's/#.*$//' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | grep '=') set +a else log_error ".env file not found!" log_info "Copy .env.example to .env and configure it" exit 1 fi log_header "Azure Stack HCI Deployment - Starting" log_step "Step 1: Verifying Prerequisites" echo "" # Test Proxmox connections log_info "Testing Proxmox connections..." if ./scripts/utils/test-proxmox-connection.sh > /dev/null 2>&1; then log_info "✓ Proxmox connections verified" else log_error "Proxmox connection failed. Please check your .env file" exit 1 fi echo "" log_step "Step 2: VM Creation Options" echo "" log_info "You have 3 options to create VMs:" echo "" echo " ${CYAN}Option 1: Proxmox Web UI (Recommended for first-time)${NC}" echo " - Access: https://192.168.1.206:8006" echo " - Login: root@pam / (password from PVE_ROOT_PASS)" echo " - See CREATE_VMS.md for detailed instructions" echo "" echo " ${CYAN}Option 2: Terraform${NC}" echo " - Requires VM templates to be created first" echo " - cd terraform/proxmox && terraform init && terraform apply" echo "" echo " ${CYAN}Option 3: Manual API (Advanced)${NC}" echo " - Use scripts/proxmox/create-service-vms.sh" echo "" read -p "Which option do you want to use? (1/2/3) [1]: " choice choice=${choice:-1} case $choice in 1) log_info "Opening Proxmox Web UI instructions..." echo "" log_warn "Please create the following VMs manually:" echo "" echo " 1. Cloudflare Tunnel VM" echo " - VM ID: 100" echo " - Name: cloudflare-tunnel" echo " - IP: 192.168.1.60" echo " - Specs: 2 CPU, 4GB RAM, 40GB disk" echo "" echo " 2. K3s Master VM" echo " - VM ID: 101" echo " - Name: k3s-master" echo " - IP: 192.168.1.188" echo " - Specs: 4 CPU, 8GB RAM, 80GB disk" echo "" echo " 3. Git Server VM" echo " - VM ID: 102" echo " - Name: git-server" echo " - IP: 192.168.1.121" echo " - Specs: 4 CPU, 8GB RAM, 100GB disk" echo "" echo " 4. Observability VM" echo " - VM ID: 103" echo " - Name: observability" echo " - IP: 192.168.1.82" echo " - Specs: 4 CPU, 8GB RAM, 200GB disk" echo "" log_info "Proxmox URL: https://192.168.1.206:8006" log_info "See CREATE_VMS.md for detailed step-by-step instructions" echo "" read -p "Press Enter after you've created at least the Cloudflare Tunnel VM..." ;; 2) log_info "Initializing Terraform..." cd terraform/proxmox if [ ! -f terraform.tfvars ]; then log_error "terraform.tfvars not found. Please create it first." exit 1 fi terraform init log_info "Review the plan:" terraform plan read -p "Apply Terraform? (y/n) " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then terraform apply fi cd ../.. ;; 3) log_info "Using API-based creation..." ./scripts/proxmox/create-service-vms.sh ;; esac echo "" log_step "Step 3: Next Steps After VM Creation" echo "" log_info "After creating VMs, you need to:" echo "" echo " 1. Install Ubuntu 22.04 LTS on each VM" echo " 2. Configure static IP addresses" echo " 3. Run setup scripts:" echo " - scripts/setup-cloudflare-tunnel.sh (on Tunnel VM)" echo " - scripts/setup-k3s.sh (on K3s VM)" echo "" log_info "See QUICK_START.md for complete instructions" echo "" log_header "Deployment Started" log_info "Check DEPLOYMENT_CHECKLIST.md to track progress"