# GCE Authentication 🔑

For the Google Compute Engine we firstly need to create a new project.

1. Head over to [Google Cloud Console](https://console.cloud.google.com/) and [create a new project](https://console.cloud.google.com/projectcreate). You can go with the default randomly generated project name or input your own and you can leave the location field on No organization. Then click create.

![Project Creation](../../images/gce/gce-1.png)

2. Then while being on the new project's dashboard, click the humburger menu and go to the [IAM & Admin](https://console.cloud.google.com/iam-admin/) [service accounts](https://console.cloud.google.com/iam-admin/serviceaccounts) section and create a new service account. Enter a name for the new service account and click create and continue. Give the service account the appropiate permissions such as Owner, Compute Engine Service Agent and Service Account User. Also include your account's email to the add admin roles section.

![Service Account Creation](../../images/gce/gce-2.png)
![Service Account Permissions](../../images/gce/gce-3.png)
![Service Account Access 1](../../images/gce/gce-4.png)
![Service Account Access 2](../../images/gce/gce-5.png)

3. Then while being on the service account we created, click on the manage keys you and then on the [Add Key](https://console.cloud.google.com/apis/credentials/serviceaccountkey) button and choose the JSON option for Key type. Download it to the same location as the project's source files

![Service Account Key 1](../../images/gce/gce-6.png)
![Service Account Key 2](../../images/gce/gce-7.png)

4. Finally go to the [APIs & Services](https://console.cloud.google.com/apis/dashboard) section and enable the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com)

![Compute Engine API](../../images/gce/gce-8.png)

6. Keep in mind you need to have billing information associated and enabled for your project.

In as few words as possible, here are the steps we followed:

* [Create Project](https://console.cloud.google.com/projectcreate)
* [Create Service Account](https://console.cloud.google.com/iam-admin/serviceaccounts)
* [Create Service Account Key](https://console.cloud.google.com/apis/credentials/serviceaccountkey)
* [Enable Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com)

There are three values needed for authentication with the Google Compute Engine API. The first is the project ID, which is the name of the project you created in the Google Cloud Console. The second is the service account email address, which is the email address of the service account you created in the Google Cloud Console. The third is the path to the JSON file (whose name and path are found by the script's internal logic by providing the private_key_id) that contains the private key for the service account. You can find these values in the JSON file you downloaded from the Google Cloud Console.

Those values are also located in the JSON file and are translate to the following environment variables:
* GCE_PROJECT_ID ➡️ project_id
* GCE_CLIENT_SECRET ➡️ private_key_id
* GCE_CLIENT_ID ➡️ client_email



