1

We have multiple GCP Service account keys from different environment such as DEV,STAGING,..PROD.

I would like to run a command in my jenkins box which is there in Dev environment to create access DEV and Staging environments,

I don't want to run gcloud auth command every time, instead i'm expecting something like,

gcloud compute instances list --key-file=dev-sa.json

or

gsutil ls -l --key-file=dev-sa.json

Do we have anyways like this?

2

Approach the solution differently.

Instead of trying to use different service accounts, use one service account that has access (privileges) to each project.

Create a service account (or use the one that you created). Make note of the service account email address (this is its ID).

Go to IAM for each project and add this email address as a member. Assign the roles/ permissions that you want for this service account. Repeat for each project.

Now you can use this service account json file to setup gcloud, software applications, etc. All you need to do is specify the project when using the credentials.

gcloud auth activate-service-account test@development-123456.iam.gserviceaccount.com --key-file=test_google_account.json

You can set the default project with gcloud config set project PROJECT_ID. Or use the environment variable CLOUDSDK_CORE_PROJECT.

You can specify the project on the command line with --project PROJECT_ID

gcloud --project development-123456 compute instances list
  • Another alternative would be to go with direct API calls instead of gcloud. Then you'd have total freedom in terms of options to choose. – Gonçalo Lourenço Jan 23 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.