Cleanup Costly Resources #888
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Nimbus | |
# Terraform | |
# Cleanup Costly Resources | |
# | |
name: "Cleanup Costly Resources" | |
on: | |
# UTC 1500 - 11pm in SGT | |
schedule: [cron: "00 15 * * *"] | |
jobs: | |
cleanup-terraform: | |
name: "Apply lean Terraform deployment" | |
runs-on: ubuntu-20.04 | |
defaults: | |
run: | |
working-directory: terraform | |
steps: | |
- uses: actions/checkout@v3 | |
- name: "Setup Terraform CLI" | |
uses: hashicorp/setup-terraform@v2 | |
with: | |
terraform_version: 1.9.7 | |
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} | |
- name: "Terraform Init" | |
run: terraform init | |
- name: "Terraform Apply" | |
if: ${{ github.ref == 'refs/heads/main' }} | |
env: | |
TF_VAR_has_warp_vm: false | |
run: terraform apply -auto-approve | |
# Packer sometimes fails to clean up GCE persistent disks it creates when | |
# the box build fails. Routinely clean up any disks that disks left by packer. | |
cleanup-orphan-gcp-pd: | |
name: "Cleanup orphaned GCE Persistent Disks" | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: "google-github-actions/auth@v2" | |
with: | |
credentials_json: "${{ secrets.GCP_NIMBUS_CI_KEY }}" | |
- name: "Set up Cloud SDK" | |
uses: google-github-actions/setup-gcloud@v2 | |
- name: "Delete orphaned GCE PDs" | |
shell: bash | |
env: | |
CLOUDSDK_CORE_PROJECT: mrzzy-sandbox | |
CLOUDSDK_COMPUTE_ZONE: asia-southeast1-c | |
run: | | |
ORPHANED_DISKS=$( | |
gcloud compute disks list --quiet \ | |
--filter="-users:*" \ | |
--filter="name~'packer-.*'" \ | |
--format "value(name)") | |
if [ -n "$ORPHANED_DISKS" ] | |
then | |
gcloud compute disks delete $ORPHANED_DISKS | |
fi |