Create Basic Role, Predefined Role and Custom Role in Google Cloud IAM
Step-01: Introduction
We are going to use all three role types in this demo:
- Basic Roles
- Predefined Roles
- Custom Roles
Step-02: Create a VM Instance
bash
# Set Project
gcloud config set project PROJECT_ID
# (example) gcloud config set project gcpdemos
# Create VM Instance
gcloud compute instances create vm1 \
--zone=us-central1-a \
--machine-type=e2-micro \
--network-interface=subnet=default
Step-03: Pre-requisite: Create a test Gmail ID for this demo
gcpuser08@gmail.com
Step-04: Basic Role: Owner
Step-04-01: Add Principal with IAM Role: Owner and Verify
- Go to IAM & Admin → IAM → GRANT ACCESS in the Google Cloud Console.
- Add Principal:
gcpuser08@gmail.com
. - Select Role: Owner.
- Click SAVE.
An invitation will be sent to the new user.
Step-04-02: Login to Gmail and Accept Invitation
Login to Gmail and accept the invitation:
-
Username:
gcpuser08@gmail.com
-
Password:
XXXXXXXX
(test account password)
Step-04-03: Login to Google Cloud with the New User
- Open an Incognito / private browser window.
- Login to Google Cloud using
gcpuser08@gmail.com
. - Select the project (example:
gcplearn9
).
Observation: The user should have full access for all resources (Owner permission).
Step-05: Predefined Role: Compute Viewer
Step-05-01: Add Principal with IAM Role Compute Viewer
- Go to IAM & Admin → IAM → GRANT ACCESS.
- Add Principal:
gcpuser08@gmail.com
. - Select Role: Compute Viewer.
- Click SAVE.
Step-05-02: Login to Google Cloud with the New User
- Open an Incognito / private browser window.
- Login to Google Cloud with
gcpuser08@gmail.com
. - Select the project (example:
gcplearn9
).
Observation: The user should see read-only access to Compute Engine resources.
Step-06: Custom Role: Stop and Start VMs
Step-06-01: Create Custom Role
- Go to IAM → Roles → CREATE ROLE.
- Set:
- Title: Custom Role Start Stop VM
-
ID:
customRoleStartStopVM101
-
Add permissions:
compute.instances.start
,compute.instances.stop
. - Click CREATE.
-
Add permissions:
Note: The permission names are
compute.instances.start
andcompute.instances.stop
(use the exact permission strings when adding permissions).
Step-06-02: Add Principal with the Custom Role
- Go to IAM & Admin → IAM → GRANT ACCESS.
- Add Principal:
gcpuser08@gmail.com
. - Select Role: Compute Viewer.
- Select Role: Custom Role Start Stop VM (the custom role you created).
- Click SAVE.
Step-06-03: Login to Google Cloud with the New User
- Open an Incognito / private browser window.
- Login to Google Cloud with
gcpuser08@gmail.com
. - Select the project (example:
gcplearn9
).
Observations:
- Observation-1: The user should have only read-only access from the Compute Viewer role.
- Observation-2: The user should be able to stop and start the VM instance thanks to the custom role.
🌟 Thanks for reading! If this post added value, a like ❤️, follow, or share would encourage me to keep creating more content.
— Latchu | Senior DevOps & Cloud Engineer
☁️ AWS | GCP | ☸️ Kubernetes | 🔐 Security | ⚡ Automation
📌 Sharing hands-on guides, best practices & real-world cloud solutions
Top comments (0)