0

Here is a picture of the WebUI for GCP, showing an "instance schedule" that has 3 instances currently associated with it:

GCP Instance Schedule

How can I list those same 3 instances using the GCloud CLI?

I found commands to add a VM to a schedule:

gcloud compute instances add-resource-policies ...

I found commands to remove a VM from a schedule:

gcloud compute instances remove-resource-policies ...

I tried "viewing" the schedule:

gcloud compute resource-policies describe ...

Or even the metadata you get with JSON format:

gcloud compute resource-policies list --format=json ...


So that is my question -- how to get that list of associated VM's given a particular schedule, or resource-policy.

Rubén
  • 117
  • 6
CrashNeb
  • 103
  • 2

1 Answers1

0

The policies are created, then you associate the compute resource with the policy.

You would need to query VMs for their association with that policy, for example to view all policies associated to all VMs in a project, you could use:

gcloud compute instances list --format='value(name,resourcePolicies)'
cachonfinga
  • 230
  • 1
  • 6
  • Thank you, that did it! :D If I tack on ` | grep resourcePolicies` it limits the output to only VM's that actually have a policy. I can play further with the filtering. – CrashNeb Jul 20 '23 at 17:06