Skip to content

Commit 6899da5

Browse files
Update actions
1 parent f89df4f commit 6899da5

4 files changed

Lines changed: 79 additions & 0 deletions

File tree

.github/workflows/gcp-deploy.reusable.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ jobs:
9191
tagger_container_tag = "${{ github.sha }}"
9292
EOF
9393
94+
- name: Handle existing workflows
95+
run: |
96+
# Check for existing workflows and delete them if they exist
97+
# This is necessary because workflows can't be imported into terraform state
98+
chmod +x deployment/terraform/handle-existing-workflows.sh
99+
./deployment/terraform/handle-existing-workflows.sh "${{ vars.PROJECT_ID }}" "${{ vars.REGION }}" --delete || true
100+
94101
- name: Deploy infrastructure
95102
id: deploy_infra
96103
working-directory: deployment/terraform/infra

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ terraform-import:
244244
@echo "Importing existing resources into terraform state..."
245245
@cd deployment/terraform && ./import-existing.sh
246246

247+
terraform-handle-workflows:
248+
@echo "Checking and handling existing workflows..."
249+
@cd deployment/terraform && ./handle-existing-workflows.sh $(PROJECT_ID) $(TF_VAR_region)
250+
247251
terraform-destroy:
248252
@echo "⚠️ WARNING: This will destroy all terraform-managed resources!"
249253
@echo "Press Ctrl+C to cancel, or Enter to continue..."

deployment/DEPLOYMENT_GUIDE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ cp deployment/.env.example deployment/.env
1919
```bash
2020
# If you get "already exists" errors, run:
2121
make terraform-import
22+
23+
# For workflow errors specifically (workflows can't be imported):
24+
./deployment/terraform/handle-existing-workflows.sh $PROJECT_ID
25+
# To auto-delete existing workflows, add --delete flag:
26+
# ./deployment/terraform/handle-existing-workflows.sh $PROJECT_ID us-central1 --delete
2227
```
2328

2429
3. Deploy:
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
# Script to handle existing workflows before terraform deployment
3+
4+
set -e
5+
6+
# Get project ID from command line or environment
7+
PROJECT_ID="${1:-${TF_VAR_project_id}}"
8+
REGION="${2:-${TF_VAR_region:-us-central1}}"
9+
10+
if [ -z "$PROJECT_ID" ]; then
11+
echo "Usage: $0 <project_id> [region]"
12+
echo "Or set TF_VAR_project_id environment variable"
13+
exit 1
14+
fi
15+
16+
echo "Checking for existing workflows in project: $PROJECT_ID, region: $REGION"
17+
18+
# Check if workflows exist
19+
EXISTING_WORKFLOWS=$(gcloud workflows list --location="$REGION" --project="$PROJECT_ID" --format="value(name)" 2>/dev/null || true)
20+
21+
# Check for our specific workflows
22+
for workflow in "simulation-workflow" "wait-for-country-packages"; do
23+
if echo "$EXISTING_WORKFLOWS" | grep -q "$workflow"; then
24+
echo "Found existing workflow: $workflow"
25+
echo "Options:"
26+
echo " 1. Delete the workflow manually:"
27+
echo " gcloud workflows delete $workflow --location=$REGION --project=$PROJECT_ID"
28+
echo ""
29+
echo " 2. Or use terraform import (but this may not work with all configurations):"
30+
echo " cd deployment/terraform/infra"
31+
echo " terraform import google_workflows_workflow.$(echo $workflow | tr '-' '_') projects/$PROJECT_ID/locations/$REGION/workflows/$workflow"
32+
echo ""
33+
FOUND_EXISTING=true
34+
fi
35+
done
36+
37+
if [ "$FOUND_EXISTING" = true ]; then
38+
echo ""
39+
echo "⚠️ Existing workflows found. You have two options:"
40+
echo ""
41+
echo "Option A: Delete existing workflows and let terraform recreate them"
42+
echo " Run: $0 $PROJECT_ID $REGION --delete"
43+
echo ""
44+
echo "Option B: Keep existing workflows (may cause deployment to fail)"
45+
echo " Continue with deployment and handle errors manually"
46+
echo ""
47+
48+
# Check for --delete flag
49+
if [ "$3" = "--delete" ]; then
50+
echo "Deleting existing workflows..."
51+
for workflow in "simulation-workflow" "wait-for-country-packages"; do
52+
if echo "$EXISTING_WORKFLOWS" | grep -q "$workflow"; then
53+
echo "Deleting $workflow..."
54+
gcloud workflows delete "$workflow" --location="$REGION" --project="$PROJECT_ID" --quiet || true
55+
fi
56+
done
57+
echo "✅ Workflows deleted. You can now run terraform deployment."
58+
else
59+
exit 1
60+
fi
61+
else
62+
echo "✅ No conflicting workflows found. Safe to proceed with terraform deployment."
63+
fi

0 commit comments

Comments
 (0)