diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 675f0e5..8f48276 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -52,13 +52,11 @@ jobs: terraform init terraform apply -auto-approve - - name: Decrypt tfvars file, Initialize and Plan Terraform + - name: Decrypt tfvars file and Initialize Terraform working-directory: ./terraform run: | gpg --quiet --batch --yes --decrypt --passphrase="$SECRET_PASSPHRASE" --output variables.tfvars variables.tfvars.gpg terraform init -reconfigure - terraform plan -out=tfplan -var-file="variables.tfvars" -refresh-only - terraform show -json tfplan | jq '.resource_changes | length' env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} @@ -66,9 +64,8 @@ jobs: SECRET_PASSPHRASE: ${{ secrets.SECRET_PASSPHRASE }} - name: Apply Terraform changes - if: steps.tfplan.outputs.change_count != '0' working-directory: ./terraform - run: terraform apply -auto-approve "tfplan" + run: terraform apply -auto-approve -var-file="variables.tfvars" env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/terraform/scripts/empty_bucket.sh b/terraform/scripts/empty_bucket.sh index b636389..055f542 100755 --- a/terraform/scripts/empty_bucket.sh +++ b/terraform/scripts/empty_bucket.sh @@ -6,6 +6,12 @@ set -e BUCKET_NAME="$1" AWS_REGION="$2" +# Check if the bucket exists +if ! aws s3api head-bucket --bucket "$BUCKET_NAME" --region "$AWS_REGION" 2>/dev/null; then + echo "Error: Bucket $BUCKET_NAME does not exist in region $AWS_REGION." + exit 1 +fi + echo "Deleting all objects and versions from bucket $BUCKET_NAME in region $AWS_REGION" # Delete all objects