kodekloud-gcp-training with your target project ID where needed.

- Create a service account.
- Grant the service account necessary IAM roles.
- Create a VPC, a subnet, and firewall rules.
- Launch a Compute Engine instance using the service account (no external IP).
- Verify resources and clean them up when finished.
You don’t need to memorize every gcloud flag. Learn the command structure and reference the gcloud CLI docs: https://cloud.google.com/sdk/gcloud/reference. Use this guide as a step-by-step reference for common infra tasks.
Prerequisites
Activate Cloud Shell and set the intended project (replace the project ID if different):Quick resource summary
1. Create a service account
Create a service account nameddemo-sa with a display name and description:
2. Grant IAM roles to the service account
Grant the permissions the VM needs to manage compute resources and access storage.- Grant Compute Instance Admin (VM lifecycle and instance operations):
- Grant Storage Object Viewer (read-only access to Cloud Storage objects):
2 for None unless you need a specific condition).
3. Create a VPC network
Create a custom-mode VPC nameddemo-vpc with regional BGP routing:
4. Create a subnet
Create a regional subnetdemo-subnet in us-central1 with CIDR 10.0.1.0/24 and attach it to demo-vpc:
5. Create firewall rules
Allow SSH (22), HTTP (80), and HTTPS (443) ingress from anywhere to instances ondemo-vpc. Create one rule per port for clarity and minimal privileges.
Allow SSH:
6. Create a Compute Engine instance
Create a VM nameddemo-vm in zone us-central1-a that uses the demo-sa service account and is attached to demo-subnet without an external IP (private-only instance):
us-central1-a):
Cleanup is important to avoid unexpected charges. Delete resources in reverse order of creation and confirm prompts. If you plan to keep resources, consider applying labels and budgets to manage costs.
7. Cleanup (delete resources)
When you’re finished, remove resources in reverse creation order. AnswerY to confirmation prompts.
Delete the VM:
Closing notes
This guide demonstrated how to provision a basic infrastructure stack using only gcloud CLI commands: creating a service account, assigning IAM roles, creating a custom VPC/subnet, adding firewall rules, and launching a private Compute Engine VM using the service account. For production environments, automate and parameterize these steps using scripts or infrastructure-as-code tools such as Terraform. Further reading and references:- gcloud CLI reference: https://cloud.google.com/sdk/gcloud/reference
- VPC networks overview: https://cloud.google.com/vpc/docs/vpc
- Compute Engine instances: https://cloud.google.com/compute/docs/instances