Skip to content

Intermediate · Google Cloud and comparing the clouds · topic 27 of 50 · 30 min

Google Cloud structure: projects, billing and IAM

Explanation

In Google Cloud every resource lives in a project, projects can be grouped into folders, and folders sit under one organisation. A billing account pays for projects, and budgets warn you before costs run away. IAM grants roles to principals (people, groups and service accounts), and a role granted higher up the tree is inherited by everything below it.

Why the structure matters

In Google Cloud, everything you create is a resource: a virtual machine, a storage bucket, a database, a Pub/Sub topic. Every resource belongs to exactly one project. Projects can be grouped into folders, and folders sit under one organisation. This tree is called the resource hierarchy.

The hierarchy decides two important things. First, who pays: billing is attached to projects. Second, who can do what: access rules attached to a level of the tree flow down to everything below it. If you design the tree well, managing hundreds of projects stays simple. If you design it badly, you spend your time fixing permissions one project at a time.

Think of it like this: Think of a large hospital group. The group itself is the organisation. Each hospital and department is a folder. Each ward is a project, with its own budget code. The beds, monitors and medicine cupboards are the resources. A rule made at group level ("auditors may look at every record") applies in every ward, without anyone repeating it.

The four levels

LevelWhat it isExample
OrganisationThe root of the tree, tied to your company domain through Google Workspace or Cloud Identityacme.in
FolderAn optional group of projects; folders can contain other foldersFinance, Engineering, Engineering/Production
ProjectThe basic container: it holds resources, enabled APIs, IAM settings and a billing linkpayroll-prod-4821
ResourceThe actual thing you use and pay forA Compute Engine VM, a Cloud Storage bucket

An organisation resource only exists when you sign up with Google Workspace or Cloud Identity for your domain. A student using a personal Gmail account can still create projects. They simply have no organisation above them, so folders and organisation-wide rules are not available.

Project ID, project name and project number

  • Project name: a friendly label such as "Payroll Production". It does not have to be unique and you can change it at any time.
  • Project ID: a globally unique identifier such as payroll-prod-4821. You choose it when you create the project (Google suggests one). It uses 6 to 30 lowercase letters, digits and hyphens and starts with a letter. It can never be changed, and commands and URLs use it.
  • Project number: a number Google assigns automatically. You see it in some service account names and in logs and API responses.

Billing accounts and budgets

A Cloud Billing account holds the payment method, such as a card or an invoiced company account. One billing account can pay for many projects, but each project is linked to at most one billing account at a time. If a project has no billing account linked, most paid services in it cannot run.

A budget is a spending target you set on a billing account, for all projects or a chosen few. You add alert thresholds, for example 50%, 90% and 100% of the amount, and Google emails the billing administrators when actual or forecast costs cross them.

Careful: A budget only sends alerts. It does not stop spending by itself. To cut costs automatically you must connect budget notifications to Pub/Sub and write your own automation. Most beginners discover this the hard way.

IAM: who can do what, where

Identity and Access Management (IAM) answers one question: who can do what on which resource. A principal (the "who") is granted a role (the "what") on a resource (the "where"). The grants are stored in an allow policy attached to the resource. A policy is a list of bindings, and each binding pairs one role with a list of principals.

  • A Google account, written user:asha@acme.in, is a person.
  • A Google group, written group:analysts@acme.in, lets you grant once to a whole team.
  • A service account, written serviceAccount:name@PROJECT_ID.iam.gserviceaccount.com, is an identity for a program.
  • A domain, written domain:acme.in, means every account in your Workspace or Cloud Identity domain.

A role is a set of permissions such as storage.objects.get or compute.instances.start. There are three kinds. Basic roles (Owner, Editor and Viewer) are very broad: Editor can change almost everything in a project. Avoid them in production. Predefined roles are made by Google for each service, for example roles/storage.objectViewer or roles/cloudsql.client. Custom roles let you pick exact permissions when no predefined role fits.

json
{
  "bindings": [
    { "role": "roles/storage.objectViewer", "members": ["group:analysts@acme.in"] },
    { "role": "roles/cloudsql.client", "members": [
        "user:asha@acme.in",
        "serviceAccount:payroll-app@payroll-prod-4821.iam.gserviceaccount.com" ] }
  ]
}
A simplified allow policy: two bindings, each pairing a role with its principals.

Inheritance: policies flow downwards

A policy set on the organisation applies to every folder, project and resource below it. A policy on a folder applies to every project in that folder. The access a principal really has on a resource is the union of the policy on that resource and the policies on all its ancestors. You cannot remove an inherited role by leaving it out lower down. (Google Cloud has separate deny policies for blocking, which are an advanced topic.)

Service accounts and keys

A service account is how a program proves who it is. The safest way is to attach the service account to the thing that runs your code, such as a VM or a Cloud Run service. Google client libraries then fetch short-lived tokens automatically. For code running outside Google Cloud, for example in GitHub Actions or on AWS, use workload identity federation: the outside system exchanges its own token for short-lived Google credentials.

You can also download a service account key as a JSON file. That file is a long-lived secret: anyone who finds it can act as the service account until someone deletes the key. Use keys only as a last resort. Many organisations block key creation completely with an organisation policy.

Regions and zones

A region is a geographic area, such as asia-south1 (Mumbai) or asia-south2 (Delhi). A zone is an isolated location inside a region, such as asia-south1-a. Some resources are zonal (a VM and its disk), some are regional (a subnet), and some are global (a VPC network). Indian companies often keep data in asia-south1 or asia-south2 for low latency and data-residency rules.

gcloud basics

bash
gcloud init                                    # log in, choose a default project and region
gcloud projects list                           # projects you are allowed to see
gcloud config set project payroll-prod-4821    # default project for later commands
gcloud config set compute/region asia-south1   # default region
gcloud config list                             # show the current account, project and region
gcloud projects get-iam-policy payroll-prod-4821 --format=json   # who has which role
gcloud is the Google Cloud command-line tool. Comments after # are not run.

Common mistakes and how to fix them

  • Giving everyone the Editor role. Fix: grant predefined roles to groups, not basic roles to individuals.
  • Granting at the organisation level what one project needs. Fix: grant at the lowest level that does the job.
  • Downloading service account keys and committing them to Git. Fix: attach service accounts, or use workload identity federation.
  • Running a delete command against the wrong project. Fix: check gcloud config list first, or pass --project explicitly.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

Google Cloud structure: projects, billing and IAM · 1/8

Organisation Folders Projects Resources

In Google Cloud, every resource lives inside a project. Projects can sit in folders, and folders sit under one organisation.

Prefer a video by a teacher? Find free videos on “google cloud resource hierarchy projects folders IAM tutorial” on YouTube ↗

In real life: A payroll company in Pune organises its cloud

A payroll software company in Pune has 40 Google Cloud projects. They create folders for Production, Staging and Sandbox, and link the Sandbox projects to a separate billing account with a budget of ₹20,000 a month and alerts at 50%, 90% and 100%. The security team gets roles/viewer once, at the organisation level, so they can see everything without touching anything. Developers get roles/editor only on the Sandbox folder, and production changes are made by a deployment service account through CI with workload identity federation, so nobody keeps a JSON key on a laptop.

bash
gcloud resource-manager folders list --organization=123456789012
gcloud projects add-iam-policy-binding payroll-prod-4821 \
  --member="group:payroll-devs@acme.in" --role="roles/cloudsql.client"
List folders, then grant a predefined role to a group on one project.

Practice (0/3 done)

Task 1 · Question

You run: gcloud config set project payroll-dev-1102. What changes?

Task 2 · Code · Python

Write effective_roles(member, path, policies, groups=()) that returns the sorted list of roles a principal really has on a resource. path lists resource names from the organisation down to the resource, for example ["organizations/acme", "folders/finance", "projects/payroll-prod"]. policies maps a resource name to {role: [members]}. A binding counts if its members include the member itself or any of the groups the member belongs to. Policies on resources NOT in the path (for example a sibling folder) do not count. Return each role once, sorted.

Task 3 · Practice

Design a Google Cloud resource hierarchy for an engineering college that runs a student portal, an exam results system and a research computing lab. Write the tree (organisation, folders, projects), which billing account pays for what, the budgets you would set, and three IAM grants (who, which role, at which level).

Quick quiz

Question 1

1.Which project identifier can never be changed after the project is created?

Question 2

2.Ravi is granted roles/storage.objectViewer on the folder "Finance". Where does that role apply?

Question 3

3.What is the safest way for code on Cloud Run to read from a Cloud Storage bucket?

Question 4

4.Your budget of ₹10,000 reaches 100%. What happens by default?

Question 5

5.Which city is the Google Cloud region asia-south2 in?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

Which project identifier can never be changed after the project is created?

Answer: Project ID

The project ID is permanent and globally unique. The name and labels can change, and the billing link can be moved.

Ravi is granted roles/storage.objectViewer on the folder "Finance". Where does that role apply?

Answer: On every project and resource inside the Finance folder

IAM policies are inherited downwards, so a folder grant applies to everything inside the folder.

What is the safest way for code on Cloud Run to read from a Cloud Storage bucket?

Answer: Attach a service account to the Cloud Run service and grant it a storage role

An attached service account gets short-lived tokens automatically, so there is no long-lived secret to leak.

Your budget of ₹10,000 reaches 100%. What happens by default?

Answer: Alert notifications are sent, but spending is not stopped automatically

Budgets only alert. Capping spend needs your own automation through Pub/Sub notifications.

Which city is the Google Cloud region asia-south2 in?

Answer: Delhi

asia-south1 is Mumbai and asia-south2 is Delhi.

What does a cloud IAM policy define?Related

Answer: Which actions are allowed or denied on which resources

Policies are the permission rules.

From Cloud identity and access management

Which tool finds resources shared with outside accounts and unused permissions?Related

Answer: IAM Access Analyzer

IAM Access Analyzer reports external access, unused access and policy problems.

From IAM: users, groups, roles and least privilege

Which identity can IAM permission policies NOT restrict inside its own account?Related

Answer: The root user

The root user always has full access in its account; that is why it must be locked away.

From Creating and securing an AWS account

Developers may create their own IAM roles, but never more powerful than a set limit. What enforces that limit?Related

Answer: A permissions boundary

A permissions boundary caps the permissions of the users or roles it is set on.

From Identity is the new perimeter

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 3 more topics in “Google Cloud and comparing the clouds” before its exam: Core Google Cloud services, AWS vs Azure vs Google Cloud: the service map, The command line on all three clouds.
  2. Module 7 exam: Google Cloud and comparing the clouds · 12 questions · 20 min, without help. 4 topics of this module still to finish first.
  3. Then the next module, Containers in the cloud. 50 topics left in the course before the final exam.

← Previous: Azure networking, Functions, databases and monitoring