Score:0

With GCloud CLI -- how to list all instances associated with a particular schedule (i.e. resource-policy)?

cn flag

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.

Score:0
tr flag

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)'
CrashNeb avatar
cn flag
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.