feat(actions): delete old GCP resources (#4598)

* feat(actions): delete old GCP resources

* fix(ci): delete old instances templates

* fix(actions): use correct date arguments and conversion

* fix(actions): missing command in gcloud

* fix(gcp): if an instance can't be deleted, continue

* refacor(action): cleanup and execute monthly
This commit is contained in:
Gustavo Valverde 2022-06-15 17:59:55 -04:00 committed by GitHub
parent a224550d8e
commit 8160b4c35a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,33 @@
name: Delete GCP resources
on:
schedule:
- cron: "0 0 1 * *"
workflow_dispatch:
jobs:
delete-resources:
name: Delete old GCP resources
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
# Setup gcloud CLI
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v0.8.0
with:
workload_identity_provider: 'projects/143793276228/locations/global/workloadIdentityPools/github-actions/providers/github-oidc'
service_account: 'github-service-account@zealous-zebra.iam.gserviceaccount.com'
token_format: 'access_token'
# Deletes all the instances template older than 30 days
- name: Delete old instance templates
run: |
TEMPLATES=$(gcloud compute instance-templates list --sort-by=creationTimestamp --filter="creationTimestamp < $(date --date='30 days ago' '+%Y%m%d')" --format='value(NAME)')
for TEMPLATE in $TEMPLATES
do
gcloud compute instance-templates delete ${TEMPLATE} --quiet || continue
done