/ infrastructure / setup_backend.sh
setup_backend.sh
1 #!/bin/bash 2 set -e 3 4 BUCKET_NAME="summer-project-smpte-copilot-tfstate" 5 REGION="us-east-1" 6 REPO_URL="https://github.com/qualabs/SMPTE-Copilot" 7 PROJECT="summer-project-smpte-copilot" 8 9 echo "Using Region: $REGION" 10 echo "Bucket Name: $BUCKET_NAME" 11 12 # 1. Create S3 Bucket 13 if aws s3api head-bucket --bucket "$BUCKET_NAME" --profile smpte-copilot 2>/dev/null; then 14 echo "Bucket $BUCKET_NAME already exists." 15 else 16 echo "Creating bucket $BUCKET_NAME..." 17 if [ "$REGION" == "us-east-1" ]; then 18 aws s3api create-bucket --bucket "$BUCKET_NAME" --region "$REGION" --profile smpte-copilot 19 else 20 aws s3api create-bucket --bucket "$BUCKET_NAME" --region "$REGION" --create-bucket-configuration LocationConstraint="$REGION" --profile smpte-copilot 21 fi 22 fi 23 24 # 2. Tag S3 Bucket 25 echo "Tagging bucket..." 26 aws s3api put-bucket-tagging --bucket "$BUCKET_NAME" --tagging "TagSet=[{Key=Project,Value=${PROJECT}},{Key=ManagedBy,Value=ManualScript},{Key=Repository,Value=${REPO_URL}}]" --profile smpte-copilot 27 28 # 3. Enable Versioning 29 echo "Enabling versioning on bucket..." 30 aws s3api put-bucket-versioning --bucket "$BUCKET_NAME" --versioning-configuration Status=Enabled --profile smpte-copilot 31 32 echo "Backend infrastructure ready."