Skip to content

Commit 08ba84d

Browse files
committed
feat: update teardown workflow to delete resource group asynchronously with polling
1 parent bde9957 commit 08ba84d

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

.github/workflows/teardown.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,31 @@ jobs:
118118
az resource list --resource-group "$rg" \
119119
--query "[].{name:name, type:type, location:location}" -o table
120120
121-
- name: Delete resource group (synchronous)
121+
- name: Delete resource group (async + poll)
122122
run: |
123123
set -euo pipefail
124124
rg='${{ inputs.resource_group }}'
125125
if ! az group show --name "$rg" -o none 2>/dev/null; then
126126
echo "Resource group '$rg' already gone."
127127
exit 0
128128
fi
129-
echo "Deleting resource group '$rg' (this can take several minutes)..."
130-
az group delete --name "$rg" --yes
131-
echo "Resource group '$rg' deleted."
129+
# --no-wait avoids polling /subscriptions/<sub>/operationresults/...,
130+
# which would require subscription-scoped read permissions. With
131+
# only RG-scoped Contributor we instead poll `az group exists`,
132+
# which is an RG-scoped read.
133+
echo "Issuing async delete of resource group '$rg'..."
134+
az group delete --name "$rg" --yes --no-wait
135+
echo "Polling for completion (timeout 30 min)..."
136+
for i in $(seq 1 60); do
137+
if [ "$(az group exists --name "$rg")" = "false" ]; then
138+
echo "Resource group '$rg' deleted after ~$((i * 30))s."
139+
exit 0
140+
fi
141+
echo " [$i/60] still present, sleeping 30s..."
142+
sleep 30
143+
done
144+
echo "::error::Timed out waiting for resource group '$rg' to delete."
145+
exit 1
132146
133147
- name: Verify deletion
134148
run: |

0 commit comments

Comments
 (0)