In simple words
- Project: the basic container for GCP resources, settings and billing.
- Billing account: pays for one or more projects.
- IAM role: a set of permissions, such as Viewer or a narrow predefined role, given to someone on a resource.
- Service account: an identity for apps and pipelines, not people.
- API enablement: each service's API must be switched on in a project before you can use it.
Big picture
A project is a folder with a wall around it. Inside it you create resources, set permissions and get a bill. IAM (Identity and Access Management) decides who may do what inside. Think of an office building: each project is a locked floor, and IAM is the list of badges that open doors.
Projects
Every project has three names. Learn the difference once:
| Name | Can it change? | Example |
|---|---|---|
| Project name | Yes | Shop Dev |
| Project ID | No, unique worldwide | shop-dev-123 |
| Project number | No, made by Google | 482910334455 |
gcloud projects create shop-dev-123 --name="Shop Dev"gcloud config set project shop-dev-123gcloud projects listCreate in progress for [https://cloudresourcemanager.googleapis.com/v1/projects/shop-dev-123].Waiting for [operations/cp.8023] to finish...done.Updated property [core/project].PROJECT_ID NAME PROJECT_NUMBERshop-dev-123 Shop Dev 482910334455Most teams use one project per environment (dev, test, prod) and sometimes one per team or app. Deleting a project stops everything in it, and it can be restored for about 30 days.
Billing
A project can create paid resources only when it is linked to a billing account. The billing account holds the payment method. One billing account can pay for many projects.
gcloud billing accounts listgcloud billing projects link shop-dev-123 --billing-account=0123AB-4567CD-89EF01ACCOUNT_ID NAME OPEN MASTER_ACCOUNT_ID0123AB-4567CD-89EF01 Example Billing TruebillingAccountName: billingAccounts/0123AB-4567CD-89EF01billingEnabled: truename: projects/shop-dev-123/billingInfoprojectId: shop-dev-123APIs must be turned on
Each service has an API that is off by default in a new project. If you call a service that is off, you get an error.
gcloud services enable compute.googleapis.com run.googleapis.comgcloud services list --enabled --format="value(config.name)" | head -3Operation "operations/acat.p2-482910334455-5f0d" finished successfully.bigquery.googleapis.comcompute.googleapis.comrun.googleapis.comIAM: who, what, where
An IAM rule answers three questions:
| Part | Question | Example |
|---|---|---|
| Principal | Who? | user:ana@example.com, group:devs@example.com, a service account |
| Role | What can they do? | roles/storage.objectViewer |
| Resource | Where? | an organization, folder, project or a single bucket |
The rule is called a binding. A set of bindings on a resource is its IAM policy.
Three kinds of role
| Kind | What it is | Use it? |
|---|---|---|
| Basic | Owner, Editor, Viewer. Very wide | Avoid in real projects |
| Predefined | Made by Google for one service, such as roles/compute.instanceAdmin.v1 | Yes, first choice |
| Custom | You pick exact permissions | When no predefined role fits |
gcloud projects add-iam-policy-binding shop-dev-123 \ --member="group:devs@example.com" \ --role="roles/run.developer" gcloud projects get-iam-policy shop-dev-123 --format=json | head -12Updated IAM policy for project [shop-dev-123].bindings:- members: - group:devs@example.com role: roles/run.developer- members: - user:ana@example.com role: roles/owneretag: BwYhX2b9ZkU=version: 1Inheritance
Policies flow down. A role given on a folder applies to every project in it. You cannot take away at a lower level what was granted above (use deny policies for that). So grant roles as low as possible.
Service accounts
A service account is an identity for a program, not a person. Your VM or app uses it to call other services. Lesson 17 goes deep. For now remember: give each app its own service account with only the roles it needs.
gcloud iam service-accounts create shop-api --display-name="Shop API"Created service account [shop-api].Good habits
- Give roles to groups, not to single people.
- Use predefined roles, never Owner or Editor for daily work.
- Turn on 2-step verification for every human.
- Review who has access, now and then.
gcloud asset search-all-iam-policiescan help.
Common mistakes
- Giving
roles/editorbecause "it just works". It can change almost everything. - Mixing up project name and project ID in commands.
- Forgetting to enable the API, then reading a confusing "permission denied" or "API not enabled" error.
- Creating service account keys and emailing them. Lesson 17 shows better ways.
Summary
- A project holds resources, permissions and the bill.
- Billing is a separate account that you link to projects.
- APIs must be enabled per project.
- IAM = principal + role + resource. Policies are inherited from above.
- Prefer groups, predefined roles and service accounts per app.
CHECK YOUR UNDERSTANDING
3 quick questions
1. Which project name can never be changed after creation?
2. An IAM binding connects which three things?
3. You give a group a role on a folder. What happens to projects inside the folder?
You've finished the free preview of Google Cloud (GCP)
Upgrade to Pro to unlock the remaining 21 lessons, every practice lab and a certificate when you finish.
See plans