#!/bin/bash # Load shared libraries SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/../lib/init.sh" # Script to help migrate projects to shared Terraform modules set -e echo "🏗️ Terraform Module Migration Helper" echo "" # Check if Terraform is installed if ! command -v terraform &> /dev/null; then echo "❌ Terraform not found. Please install Terraform first." exit 1 fi # Check if we're in a project directory with Terraform if [ ! -f "main.tf" ] && [ ! -d "terraform" ]; then echo "⚠️ No Terraform configuration found in current directory" echo " → Navigate to a project with Terraform files" exit 1 fi echo "📋 Migration Steps:" echo "" echo "1. Review current Terraform configuration" echo "2. Identify resources to migrate" echo "3. Update configuration to use shared modules" echo "4. Test migration with 'terraform plan'" echo "5. Apply changes with 'terraform apply'" echo "" echo "📚 Available modules:" echo " - infrastructure/terraform/modules/azure/networking" echo " - infrastructure/terraform/modules/azure/keyvault" echo " - infrastructure/terraform/modules/azure/storage" echo " - infrastructure/terraform/modules/kubernetes/namespace" echo "" echo "📖 See docs/TERRAFORM_MIGRATION_GUIDE.md for detailed instructions" echo "" # Check for existing modules if [ -d "../../infrastructure/terraform/modules" ]; then echo "✅ Shared modules found" echo "" echo "Available modules:" find ../../infrastructure/terraform/modules -type d -mindepth 2 -maxdepth 2 | sed 's|../../infrastructure/terraform/modules/||' | sort else echo "⚠️ Shared modules not found" echo " → Check path to infrastructure/terraform/modules" fi echo "" echo "💡 Tips:" echo " - Always test in dev/staging first" echo " - Review terraform plan carefully" echo " - Backup state before migration" echo " - Use version constraints for modules"