|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Terraform deployment script for DevColor Backend |
| 4 | + |
| 5 | +echo "🚀 Starting Terraform deployment for DevColor Backend..." |
| 6 | + |
| 7 | +# Check if terraform.tfvars exists |
| 8 | +if [ ! -f "terraform.tfvars" ]; then |
| 9 | + echo "❌ terraform.tfvars not found!" |
| 10 | + echo "📝 Please copy terraform.tfvars.example to terraform.tfvars and update with your values:" |
| 11 | + echo " cp terraform.tfvars.example terraform.tfvars" |
| 12 | + echo " # Then edit terraform.tfvars with your database details" |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | + |
| 16 | +# Initialize Terraform |
| 17 | +echo "🔧 Initializing Terraform..." |
| 18 | +terraform init |
| 19 | + |
| 20 | +if [ $? -ne 0 ]; then |
| 21 | + echo "❌ Terraform init failed!" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +# Validate configuration |
| 26 | +echo "✅ Validating Terraform configuration..." |
| 27 | +terraform validate |
| 28 | + |
| 29 | +if [ $? -ne 0 ]; then |
| 30 | + echo "❌ Terraform validation failed!" |
| 31 | + exit 1 |
| 32 | +fi |
| 33 | + |
| 34 | +# Plan deployment |
| 35 | +echo "📋 Planning Terraform deployment..." |
| 36 | +terraform plan -out=tfplan |
| 37 | + |
| 38 | +if [ $? -ne 0 ]; then |
| 39 | + echo "❌ Terraform plan failed!" |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +# Ask for confirmation |
| 44 | +echo "" |
| 45 | +echo "🤔 Do you want to apply this plan? (y/N)" |
| 46 | +read -r response |
| 47 | + |
| 48 | +if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then |
| 49 | + echo "🚀 Applying Terraform configuration..." |
| 50 | + terraform apply tfplan |
| 51 | + |
| 52 | + if [ $? -eq 0 ]; then |
| 53 | + echo "" |
| 54 | + echo "✅ Deployment completed successfully!" |
| 55 | + echo "" |
| 56 | + echo "📊 Important outputs:" |
| 57 | + echo "ECR Repository URL:" |
| 58 | + terraform output ecr_repository_url |
| 59 | + echo "" |
| 60 | + echo "App Runner Service URL:" |
| 61 | + terraform output apprunner_service_url |
| 62 | + echo "" |
| 63 | + echo "App Runner Service ARN (for GitHub secrets):" |
| 64 | + terraform output apprunner_service_arn |
| 65 | + echo "" |
| 66 | + echo "🔑 Next steps:" |
| 67 | + echo "1. Add the App Runner Service ARN to your GitHub secrets as 'APPRUNNER_SERVICE_ARN'" |
| 68 | + echo "2. Push to main branch to trigger deployment" |
| 69 | + else |
| 70 | + echo "❌ Terraform apply failed!" |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | +else |
| 74 | + echo "❌ Deployment cancelled by user" |
| 75 | + rm -f tfplan |
| 76 | + exit 0 |
| 77 | +fi |
0 commit comments