-
Notifications
You must be signed in to change notification settings - Fork 4
41 lines (35 loc) · 1.05 KB
/
delete-vm.yml
File metadata and controls
41 lines (35 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
name: Delete ephemeral GCE VM
on:
workflow_call:
inputs:
runner-label:
type: string
required: true
machine-zone:
type: string
required: true
secrets:
gcp_credentials:
required: true
jobs:
run:
runs-on: ubuntu-latest
name: Delete ephemeral GCE VM
steps:
- id: auth
name: Authenticate to Google Cloud
uses: google-github-actions/auth@3a3c4c57d294ef65efaaee4ff17b22fa88dd3c69 # v1
with:
credentials_json: ${{ secrets.gcp_credentials }}
- id: gcloud-auth
name: Destroy GCE VM
shell: bash
run: |
set -x
echo "Removing GCE VM..."
gcloud auth activate-service-account --key-file ${{ steps.auth.outputs.credentials_file_path }}
if [ -z "$(gcloud compute instances list | grep "${{ inputs.runner-label }}")" ]; then
# vm is gone
exit 0
fi
gcloud compute instances delete ${{ inputs.runner-label }} --quiet --zone ${{ inputs.machine-zone }}