'how to use GCP Client python API Call to start/stop VM across projects?

I am trying to use the 'compute_v1' client library to START/STOP VMs in GCP. I need to do this across 'PROJECTS' so I am planning to use the IAM , RBAC approach for Service Accounts created with the “Service Account Token Creator Role” assigned.

How do I go about setting up the Credentials in my client.? right now I just use my 'login' related json key file as follows:

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path/xxxxxx.json"

The scope of this application is to STOP/START a list of VMs based on a project and do this on demand. All is well , now I want to use this in production across multiple projects.!

Any direction of how to Authenticate and impersonate the RBAC for each Service Account is much appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source