GCP Essentials :: Resource Hierarchy
Tags: googlecloud, gcp, cloud
Published: 2020-12-06 13:11:07

Hello guys, in this post you will learn about how google manages your resources and their access to users.

So, Projects are the main way you **organize the resources** that you use in GCP. Use them to group together related resources, usually because **they have a common business objective**.

There are four ways to interact with GCP's management layer: through the **web-based console**, through **the SDK** and its **command-line tools**, through the **APIs, and** through **a mobile app**. In this, I will be using mostly web-based console for the demonstration, but developers like cli, so I will also tell you how you can do same thing via cli toolkit.

## Downloading the CLI
If you want to work with web-console, you can skip this part and move onto the next.

If you are docker user, you are lucky. Simply pull this docker image: https://hub.docker.com/r/google/cloud-sdk/, and spin up a container. 

Alternatively, you can install the cli tool by following these steps: https://cloud.google.com/sdk/docs/downloads-interactive

To check whether it's installed or not, run the following command
```sh
gcloud version 
```
```sh
# output
Google Cloud SDK 319.0.0
alpha 2020.11.13
beta 2020.11.13
bq 2.0.62
core 2020.11.13
gsutil 4.55
kubectl 1.16.13
```

Once it's installed you can the use init command to authenticate your cli using google account
```
gcloud init --skip-diagnostics
```

## Hierarchy of Resources in GCP

![](https://cloud.google.com/resource-manager/img/cloud-folders-hierarchy.png)

Projects may be organized into folders. Folders can contain other folders. All the folders and projects used by your organization can be brought together under an organization node.

Projects, folders, organization nodes and some resources (like google cloud storage) are all places where the **policies can be defined**. 

Projects can have **different owners and users**. Each GCP project has a name and a **project ID** (auto-generated, if not assigned) which is **unique across the GCP**.

To list all your projects, you can goto **IAM & Admin** &rArr; **Manage Resources**
<a href="https://ibb.co/JRQY8RS"><img src="https://i.ibb.co/bgJ4YgG/image.png" alt="image" border="0"></a>
 
or alternatively run the command
```
gcloud projects list 
```

To create a project you can click on `Create Project` 
<a href="https://ibb.co/bmbmg6W"><img src="https://i.ibb.co/Jt3tRcB/image.png" alt="image" border="0"></a>

or run the following command

```
gcloud projects create [unique-project-id] --name=ProjectName
```

Learn more about projects from here: https://cloud.google.com/resource-manager/docs/creating-managing-projects, faor `gcloud projects -h`

If you have same projects in multiple folders and they are meant to be inherit same permissions, setting policies in folder will be a better approach.
<a href="https://imgbb.com/"><img src="https://i.ibb.co/fM7vDRx/image.png" alt="image" border="0"></a>

The root of all this hierarchy is an organisation. It has a special policy that allow you to add the administrators who can change the policy, without sharing your root password.

**Note** If you are a gsuite user, your organisation will be created automatically and all the projects / folders you create will come under that. Otherwise you can sign up for a free [trial of workspace](https://support.google.com/a/answer/53926)

Read more about organisations from here: https://cloud.google.com/resource-manager/docs/creating-managing-organization

**Note** Resources inherit the policies of their parent resource. For instance, if you set a policy at the organization level, it is automatically inherited by all its children projects. And this inheritance is transitive, which means that all the resources in those projects inherit the policy too. 

## Resources
+ [GCP Resource Hierarchy Explained By Google](https://cloud.google.com/resource-manager/docs/cloud-platform-resource-hierarchy)
+ [How to Sign-Up for Trial Workspace Account](https://support.google.com/a/answer/53926)
+ [Creating and Managing Organisations for Non GSuite Accounts](https://cloud.google.com/resource-manager/docs/creating-managing-organization)
+ [Creating and Managing Projects](https://cloud.google.com/resource-manager/docs/creating-managing-projects)

If you have any questions regarding this series, you can either comment down your problems (recommended) or you can reach me out personally at following platforms

+ Email: tbhaxor@gmail.com
+ Twitter: [@tbhaxor](https://twitter.com/tbhaxor)
+ LinkedIn: [@gurkirat--singh](https://www.linkedin.com/in/gurkirat--singh)
+ Instagram: [@_tbhaxor_](https://instagram.com/_tbhaxor_)