Intermediate · Google Cloud and comparing the clouds · topic 27 of 50 · 30 min
Google Cloud structure: projects, billing and IAM
Explanation
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.
The four levels
| Level | What it is | Example |
|---|---|---|
| Organisation | The root of the tree, tied to your company domain through Google Workspace or Cloud Identity | acme.in |
| Folder | An optional group of projects; folders can contain other folders | Finance, Engineering, Engineering/Production |
| Project | The basic container: it holds resources, enabled APIs, IAM settings and a billing link | payroll-prod-4821 |
| Resource | The actual thing you use and pay for | A 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.
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.
{
"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" ] }
]
}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
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 roleCommon 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
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.
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"Practice (0/3 done)
You run: gcloud config set project payroll-dev-1102. What changes?
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.
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
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Core Google Cloud servicesGoogle Cloud and comparing the clouds · same module
- AWS vs Azure vs Google Cloud: the service mapGoogle Cloud and comparing the clouds · same module
- The command line on all three cloudsGoogle Cloud and comparing the clouds · same module
- Cloud identity and access managementCyber Security: from zero to SOC analyst · Cloud security basics
- Identity is the new perimeterCloud security and compliance
- IAM policy JSON and how AWS decidesAWS account, IAM and billing
Questions people ask about this
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.
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.
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.
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.
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
- 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.
- Module 7 exam: Google Cloud and comparing the clouds · 12 questions · 20 min, without help. 4 topics of this module still to finish first.
- 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