This workflow looks at all of the GCP instances in a given account and zone and selects a subset of those to terminate. The termination criteria are:
- Not labelled with a termination date or lifetime after 4 minutes
- The
termination_dateorlifetimelabels are present but cannot be parsed. - The
termination_dateorlifetimelabels indicate that the instance has expired.
An instance may be configured to never terminate if its lifetime label has
the special value indefinite. Other valid values for the lifetime label are
of the form <number><unit> where <number> is any integer and <unit> is a
time unit of w (weeks), h (hours), d (days) or m (months). So, as an
example, if the lifetime label for an instance has a value of 43w then it
should be terminated after it's 43 weeks old.
Before you run this workflow, you will need the following:
- A GCP account.
- An GCP service account with permissions to list and terminate GCP instances (if not run in dry run mode).
- One or more running GCP instances that are configured to use the
termination_dateorlifetimelabels.
Follow these steps to run the workflow:
-
Add your GCP service account credentials as a Connection:
-
Click Run workflow and wait for the workflow run page to appear.
-
Supply following parameters to the modal:
- KEY:
zone - VALUE: The GCP zone to run in.
- KEY:
terminationDateLabel - VALUE: The label to use for determining the termination date.
- KEY:
lifetimeLabel - VALUE: The label to use for determining the lifetime.
- KEY:
dryRun - VALUE: True if you dont want to actually delete the resources. Use this to test the workflow and ensure it is behaving as expected.
- KEY:
-
Warning: If you run the workflow with the
dryRunparameter set tofalse, instances not in compliance with this workflow policy will immediately be terminated.
Follow these steps to run this workflow on a schedule:
- Un-comment out the Trigger block in the workflow file:
TIP: If you're using the Relay code editor, highlight the
triggerssection and type⌘ + /(Mac) orCtrl + /(Windows) to uncomment.
# triggers:
# - name: schedule
# source:
# type: schedule
# schedule: '0 * * * *'
# binding:
# parameters:
# zone: us-central1-a
# terminationDateLabel: termination_date
# lifetimeLabel: lifetime
# dryRun: true- Configure the
scheduletrigger:- Supply the run interval in cron format.
- Configure the following parameter bindings:
- Specify the
zoneto run in. - Specify the
terminationLabelto use. - Specify the
lifetimeLabelto use. - Specify whether
dryRunshould be set totrueorfalse.
- Specify the
- Click Save changes