activate-service-account to the GCP Project

Problem:

  1. Sometimes gcloud auth login doesn't work and you end up failing login to your GCP project via your terminal.

Solution:

  1. You must have the google account to run the K6 tests using cloud build. Refer here

  2. To interact with google cloud from the terminal, you need to interact with kubectl API servers. To make this work, need to install gcloud SDK. Refer here

  3. Note : make sure you have completed both the above steps, to proceed further.

  4. Login to the google cloud console , select your project and navigate to the IAM and Admin.

  5. Click on Service Accounts. This will list up the default service account created for your project.

  6. Right click on the 3 dots against the service account.

  7. Click on create key, select JSON format.

  8. Click create, this will automatically download the key to your machine.

  9. Go to you terminal and type based on the below format.

$ gcloud auth activate-service-account [ACCOUNT] --key-file=KEY_FILE

Sample Output -

$ gcloud auth activate-service-account 865123325422-compute@developer.gserviceaccount.com --key-file=/Users/username/Downloads/samplecontainerapplication-ff80fbacfb12.json

Activated service account credentials for: [865123325422-compute@developer.gserviceaccount.com]

$ gcloud projects list

API [cloudresourcemanager.googleapis.com] not enabled on project [865123325422]. Would you like to enable and retry (this will take a few minutes)? (y/N)? y

Enabling service [cloudresourcemanager.googleapis.com] on project [865123325422]...Operation "operations/acf.8744a585-c086-4b1a-a9e8-9fd5aeac14ed" finished successfully.

  1. Now you are logged in to your project and able to see you project details via terminal