Skip to content

Clean up hcloud resources #550

Clean up hcloud resources

Clean up hcloud resources #550

Workflow file for this run

name: Clean up hcloud resources
# prevent mutliple concurrent workflow executions to avoid hcloud resources interfering with each other
concurrency: hcloud
on:
workflow_dispatch:
schedule:
- cron: "0 3 * * *"
# run the workflow after a packer build workflow is finished to clean up all images created by the workflow (and potentially also left-over servers)
workflow_run:
workflows: ["Packer build"]
types:
- completed
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: setup hcloud
run: |
curl -o hcloud-linux-amd64.tar.gz -L https://github.com/hetznercloud/cli/releases/download/v1.34.0/hcloud-linux-amd64.tar.gz
sudo tar xf hcloud-linux-amd64.tar.gz -C /usr/bin hcloud
sudo chmod +x /usr/bin/hcloud
- name: clean up resources
env:
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }}
run: |
for i in $(hcloud ssh-key list -o noheader -o columns=id); do hcloud ssh-key delete $i; done
for i in $(hcloud server list -o noheader -o columns=id); do hcloud server delete $i; done
for i in $(hcloud image list -t snapshot -o noheader -o columns=id); do hcloud image delete $i; done