Skip to content

Commit f5aaaf8

Browse files
committed
Alternative instructions with provided billing
In a number of countries, it is not possible to setup a GCP billing account as an individual. This commits adds instructions to allow students to use GCP in those cases.
1 parent c6e6377 commit f5aaaf8

File tree

7 files changed

+309
-0
lines changed

7 files changed

+309
-0
lines changed

GCP_alternative_students.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# Alternative GCP Account Setup Guide
2+
3+
In a number of countries, it is not possible to setup a GCP billing account as an individual.
4+
5+
If instructed by your teaching crew, follow the steps below to setup your GCP account.
6+
7+
## Creating and setting project & billing account
8+
9+
Visit the website console.cloud.google.com and create an account as in the picture below.
10+
11+
![GCP Website](images/gcp-create-account.png)
12+
13+
Click on **AGREE AND CONTINUE**.
14+
15+
16+
### Configuration
17+
18+
First, let's connect to GCP. Run the following command and follow the steps:
19+
20+
```bash
21+
gcloud auth login
22+
```
23+
24+
Run the command below to save your GitHub username in an environment variable that we'll use later:
25+
26+
```bash
27+
echo "export GITHUB_USERNAME='$(gh api user | jq -r .login)'" >> ~/.zshrc
28+
```
29+
30+
<br>
31+
32+
Next, we will save the Billing Account ID you were provided with in an environment variable. Change `BILLING_ACCOUNT_ID` into the ID you received 👇
33+
34+
```bash
35+
echo "export BILLING_ACCOUNT='BILLING_ACCOUNT_ID'" >> ~/.zshrc
36+
exec zsh
37+
```
38+
39+
Finally, let's also store a name for your project in an environment variable. The project name will be `lewagon-yourgithubusername-ds`. Run this command:
40+
41+
```bash
42+
echo "export MY_GPROJECT='lewagon-${(L)GITHUB_USERNAME}-ds'" >> ~/.zshrc
43+
exec zsh
44+
```
45+
46+
47+
48+
❌ Depending on your GitHub username, you may face an issue. If it's the case please contact a TA 🙋‍♂️
49+
50+
## Create the project, set up billing, and budget alerts
51+
52+
Run the commands below. ❌ If an error appears, call the BM / TA 🙋‍♂️
53+
54+
Create project:
55+
56+
```bash
57+
gcloud projects create "${MY_GPROJECT}"
58+
```
59+
60+
Set the project as your current project:
61+
62+
```bash
63+
gcloud config set project "${MY_GPROJECT}"
64+
```
65+
66+
Link the billing account:
67+
```bash
68+
gcloud billing projects link "${MY_GPROJECT}" --billing-account ${BILLING_ACCOUNT}
69+
```
70+
71+
Set budget alerts per 1$
72+
```bash
73+
gcloud billing budgets create \
74+
--billing-account="${BILLING_ACCOUNT}" \
75+
--display-name="${MY_GPROJECT}" \
76+
--filter-projects=projects/"${MY_GPROJECT}" \
77+
--budget-amount=5 \
78+
--threshold-rule=percent=0.20 \
79+
--threshold-rule=percent=0.40 \
80+
--threshold-rule=percent=0.60 \
81+
--threshold-rule=percent=0.80
82+
```
83+
84+
❌ If an error appeared, call the BM / TA 🙋‍♂️
85+
86+
87+
## Set up a Service Account
88+
89+
Last part of the setup, we need to create a service account and configure it on your computer so GCP can identify you and you are able to launch gcloud command from your machine ! 💻
90+
91+
Check the current project:
92+
93+
```bash
94+
gcloud config get-value project
95+
```
96+
97+
This command retrieves the currently set project ID in your gcloud configuration.
98+
It's important to ensure you're working in the correct project before proceeding with other commands. It should be `lewagon-yourgithubusername-ds`.
99+
100+
If at this point you have an error ❌, call a TA. 🙋‍♂️
101+
If the project is not the one you've set up, call a TA. 🙋‍♂️
102+
103+
Create a service account:
104+
105+
```bash
106+
gcloud iam service-accounts create my-service-account --display-name "My Service Account"
107+
```
108+
109+
This command creates a new service account named "my-service-account" with the display name "My Service Account".
110+
Service accounts are used to authenticate applications and services to Google Cloud resources.
111+
112+
Grant the `owner` role to the service account:
113+
114+
```bash
115+
gcloud projects add-iam-policy-binding ${MY_GPROJECT} --member="serviceAccount:my-service-account@${MY_GPROJECT}.iam.gserviceaccount.com" --role="roles/owner"
116+
```
117+
118+
This command adds the `owner` role to the newly created service account for the specified projects.
119+
This grants full access to all resources in the project, so use with caution.
120+
121+
Create a key for the service account:
122+
123+
```bash
124+
gcloud iam service-accounts keys create key.json --iam-account=my-service-account@${MY_GPROJECT}.iam.gserviceaccount.com
125+
```
126+
127+
This generates a new private key for the service account and saves it as `key.json`. This key file is used to authenticate as the service account.
128+
129+
Move the key file:
130+
131+
```bash
132+
mkdir ~/code/${GITHUB_USERNAME}/gcp
133+
mv key.json ~/code/${GITHUB_USERNAME}/gcp/
134+
```
135+
136+
This command moves the `key.json` file to a specific directory in your home folder.
137+
138+
Set the GOOGLE_APPLICATION_CREDENTIALS environment variable:
139+
140+
```bash
141+
echo "export GOOGLE_APPLICATION_CREDENTIALS='/~/code/${GITHUB_USERNAME}/gcp/key.json'" >> ~/.zshrc
142+
```
143+
This adds an export command to your `.zshrc` file, setting the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of your key file. This allows Google Cloud client libraries to automatically find and use the credentials for authentication.
144+
145+
146+
## Check
147+
148+
Reset the terminal:
149+
150+
```bash
151+
exec zsh
152+
```
153+
154+
Check your project is set up and has a billing account :
155+
156+
```bash
157+
bash <(curl -s https://raw.githubusercontent.com/lewagon/data-setup/refs/heads/nogcp/checks/gcp_check.sh)
158+
```
159+
160+
If at this point you have an error ❌, call a TA. 🙋‍♂️
161+
162+
Otherwise, congratulations! You're all set! 🎉🎉

GCP_alternative_teachers.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Alternative GCP Account Setup Guide (teachers)
2+
3+
In a number of countries, it is not possible to setup a GCP billing account as an individual.
4+
5+
The steps below will allow students to use GCP in those cases.
6+
7+
8+
# Process & Schedule
9+
10+
**Prerequisites for students**:
11+
12+
- Obtain a Gmail account
13+
- Communicate with the BM
14+
15+
## Week 1 - Day 1:
16+
17+
- Students do the regular setup skipping the GCP Setup by following a dedicated setup link: [Setup - No GCP](https://github.com/lewagon/data-setup/blob/nogcp/README.md)
18+
19+
## Week 2
20+
21+
- BM creates and send a Google Form to collect students' full name and Gmail addresses.
22+
- Students submit their Gmail account through the Google Form.
23+
24+
> Hello @channel
25+
>
26+
> We will prepare the Google Cloud Platform setup next week.
27+
>
28+
> Can you go to the form here and submit your Gmail account?
29+
30+
➡️ Ask the PM to prepare the repartition per account (prepared accounts with quotas already attributed by Google and billing already set up). Please reach out to your PM to ask for the accounts you can use and where to add your students.
31+
([Template sheet](https://docs.google.com/spreadsheets/d/1gWyCui6AtHaAe1yygVGOOV50C4Y969tXT08M4s8MK4A/edit?gid=1578747303#gid=1578747303))
32+
33+
## **Week 3**
34+
35+
👉 BM adds students' Gmail account as *Billing Account Administrator* with the instructions below:
36+
37+
<details>
38+
<summary>Instructions to add students to the billing account</summary>
39+
40+
### **Billing account Management**
41+
42+
From the hamburger menu, go to Billing section. Once you landed on the page, click on manage billing account.
43+
44+
![Billing account management](images/gcp_billingaccount.png)
45+
46+
### **Add student on the billing**
47+
48+
Once you have selected the billing account, add students and give them the role of billing account administrator (that will allow them to link their own project to this billing account).
49+
50+
The BM / PM should provide you a Google Sheet with students' name, email and the billing account ID to use.
51+
52+
👉 Go to the *Add principal* page:
53+
54+
![Billing account management](images/gcp_billing_account_add_principal.png)
55+
56+
👉 Add the student as a *Billing Account Administrator*:
57+
58+
![Roles setting](images/gcp_billing_account_add_student.png)
59+
60+
</details>
61+
62+
<br>
63+
64+
👉 Prepare the list of your students with their respective billing accounts to send it to them. ([Template sheet](https://docs.google.com/spreadsheets/d/1n8KJ0jKzDwiuaqMUBX_o6tROJ5Pqg6GcJlb6pt3uRQo/edit?usp=sharing))
65+
66+
67+
## **Week 4**
68+
69+
- BM communicates to students that they should do the GCP part of the setup. Send them this message:
70+
71+
72+
> Hello @channel,
73+
>
74+
> Next week we will start MLOps week on Google Cloud Platform also known as GCP :gcp:
75+
>
76+
> For you to be able to use GCP services, you need to follow the steps from this guide :point_down:
77+
>
78+
> Student guide: https://github.com/lewagon/data-setup/blob/nogcp/GCP_alternative_students.md
79+
>
80+
> To make it simple, you'll create a project through CLI command and link it to the billing account provided by Le Wagon.
81+
>
82+
> To know which billing account to use, please check the one allocated to you in this Google Sheet :google-sheets-intensifies:
83+
>
84+
> Let me know through tickets if you face any issue or need further explanations. :hand:
85+
86+
- Students do the GCP part of the setup:
87+
88+
[Students guide](https://github.com/lewagon/data-setup/blob/nogcp/GCP_alternative_students.md)
89+
90+
- Students confirm ✅ that they have finished the setup.
91+
- BM follows up everyone finished.

checks/gcp_check.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
# Use project ID from environment variable or argument
4+
MY_GPROJECT="${MY_GPROJECT:-$1}"
5+
6+
if [[ -z "$MY_GPROJECT" ]]; then
7+
echo "⚠️ No project ID provided."
8+
echo " Set it as an environment variable or pass it as an argument."
9+
echo " Example:"
10+
echo " export MY_GPROJECT=my-project-id"
11+
echo " ./gcp_check.sh"
12+
echo " OR"
13+
echo " ./gcp_check.sh my-project-id"
14+
exit 1
15+
fi
16+
17+
# Get current gcloud project
18+
current_project=$(gcloud config get-value project 2>/dev/null)
19+
20+
# Check if project is set
21+
if [[ "$current_project" == "(unset)" || -z "$current_project" ]]; then
22+
echo "⚠️ No Google Cloud project is currently set."
23+
exit 1
24+
fi
25+
26+
# Validate project match
27+
if [[ "$current_project" != "$MY_GPROJECT" ]]; then
28+
echo "⚠️ Project mismatch!"
29+
echo " Expected: $MY_GPROJECT"
30+
echo " Found: $current_project"
31+
exit 1
32+
fi
33+
34+
# Get billing info
35+
billing_info=$(gcloud beta billing projects describe "$current_project" --format=json 2>/dev/null)
36+
37+
if [[ -z "$billing_info" ]]; then
38+
echo "⚠️ Failed to get billing information for project $current_project"
39+
exit 1
40+
fi
41+
42+
# Parse JSON output (requires jq)
43+
billing_enabled=$(echo "$billing_info" | jq -r '.billingEnabled')
44+
billing_account=$(echo "$billing_info" | jq -r '.billingAccountName')
45+
46+
if [[ "$billing_enabled" == "true" && -n "$billing_account" && "$billing_account" != "null" ]]; then
47+
echo "✅ Billing is enabled on project $current_project"
48+
echo " Linked billing account: $billing_account"
49+
else
50+
echo "⚠️ Billing is NOT enabled on project $current_project"
51+
if [[ -z "$billing_account" || "$billing_account" == "null" ]]; then
52+
echo " No billing account linked"
53+
else
54+
echo " Billing account linked but billing disabled: $billing_account"
55+
fi
56+
fi

images/gcp-create-account.png

300 KB
Loading
62.3 KB
Loading
146 KB
Loading

images/gcp_billingaccount.png

433 KB
Loading

0 commit comments

Comments
 (0)