{"id":32637,"date":"2026-11-29T22:05:34","date_gmt":"2026-11-29T22:05:34","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=32637"},"modified":"2026-11-29T22:05:34","modified_gmt":"2026-11-29T22:05:34","slug":"google-cloud-platform-assignment-excercise","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/google-cloud-platform-assignment-excercise\/","title":{"rendered":"Google Cloud Platform Assignment &amp; Excercise"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This page is a Google Cloud Platform (GCP) assignment: hands-on exercises for creating a project, assigning IAM roles and launching a labelled Compute Engine VM, followed by review questions on regions, resource hierarchy, IAM, labels, networking, GKE and Anthos. Below the assignment you will find the full gcloud commands for each lab, how to check your results, fixes for answers that are wrong or out of date, and the current names of products that Google has renamed.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<script src=\"https:\/\/gist.github.com\/devops-school\/fda360159cbe8e7f0baf478c9b007888.js\"><\/script>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Before you start the exercises<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The exercise and solution links in the tables above are relative paths from a GitHub repository, so they do not work on this page. The labs below replace them. You can run everything in Cloud Shell, which already has <code>gcloud<\/code> installed and signed in, or on a local machine with the Google Cloud CLI installed.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A Google account and a Cloud Billing account. The free trial is enough, and an <code>e2-micro<\/code> VM costs very little.<\/li>\n\n\n<li>The Google Cloud CLI. Run <code>gcloud init<\/code> once to sign in and choose defaults.<\/li>\n\n\n<li>Permission to create projects. If your account belongs to an organization, you need the Project Creator role (<code>roles\/resourcemanager.projectCreator<\/code>).<\/li>\n<\/ul>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">gcloud version\ngcloud auth <span class=\"hljs-keyword\">list<\/span>\ngcloud config <span class=\"hljs-keyword\">list<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Lab 1: Create a project and link billing<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A project ID must be <strong>globally unique<\/strong>, 6 to 30 characters long, made of lowercase letters, digits and hyphens, and it must start with a letter. The display name (<code>--name<\/code>) does not need to be unique. Most APIs, including Compute Engine, will not work until the project is linked to a billing account.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">export PROJECT_ID=dso-gcp-lab-$RANDOM\n\ngcloud projects create $PROJECT_ID --name=<span class=\"hljs-string\">\"DevOpsSchool GCP Lab\"<\/span>\n\n<span class=\"hljs-comment\"># Find your billing account ID (format XXXXXX-XXXXXX-XXXXXX)<\/span>\ngcloud billing accounts <span class=\"hljs-keyword\">list<\/span>\ngcloud billing projects link $PROJECT_ID --billing-account=XXXXXX-XXXXXX-XXXXXX\n\n<span class=\"hljs-comment\"># Make it the default project and enable Compute Engine<\/span>\ngcloud config set project $PROJECT_ID\ngcloud services enable compute.googleapis.com\n\n<span class=\"hljs-comment\"># Verify<\/span>\ngcloud projects describe $PROJECT_ID --format=<span class=\"hljs-string\">\"value(projectId,name,lifecycleState)\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The last command should print your project ID, its name and <code>ACTIVE<\/code>. In older versions of the CLI, the billing commands lived under <code>gcloud beta billing<\/code>. If <code>gcloud billing<\/code> is not recognised, update the CLI.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Lab 2: Assign and verify IAM roles<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Roles are granted by adding a binding (a member plus a role) to a resource&#039;s allow policy. Where you can, grant a narrow predefined role instead of the basic Owner, Editor or Viewer roles.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># Grant read-only Compute Engine access to a user<\/span>\ngcloud projects add-iam-policy-binding $PROJECT_ID \\\n  --member=<span class=\"hljs-string\">\"user:alice@example.com\"<\/span> \\\n  --role=<span class=\"hljs-string\">\"roles\/compute.viewer\"<\/span>\n\n<span class=\"hljs-comment\"># Show which roles that user holds on the project<\/span>\ngcloud projects get-iam-policy $PROJECT_ID \\\n  --flatten=<span class=\"hljs-string\">\"bindings&#91;].members\"<\/span> \\\n  --filter=<span class=\"hljs-string\">\"bindings.members:user:alice@example.com\"<\/span> \\\n  --format=<span class=\"hljs-string\">\"table(bindings.role)\"<\/span>\n\n<span class=\"hljs-comment\"># Revoke the role<\/span>\ngcloud projects remove-iam-policy-binding $PROJECT_ID \\\n  --member=<span class=\"hljs-string\">\"user:alice@example.com\"<\/span> \\\n  --role=<span class=\"hljs-string\">\"roles\/compute.viewer\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Use the prefix that matches the kind of member: <code>user:<\/code>, <code>group:<\/code>, <code>serviceAccount:<\/code> or <code>domain:<\/code>. Granting a role to a group is easier to manage than granting it to many individual users.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Lab 3: Create a labelled instance with a startup script<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This lab extends the instance question above. It adds a zone, an image, a network tag and a startup script so that the VM serves a web page you can open to check the result.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">cat &gt; startup.sh &lt;&lt;<span class=\"hljs-string\">'EOF'<\/span>\n<span class=\"hljs-comment\">#!\/bin\/bash<\/span>\napt-get update\napt-get install -y nginx\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"Hello from $(hostname)\"<\/span> &gt; \/<span class=\"hljs-keyword\">var<\/span>\/www\/html\/index.html\nEOF\n\ngcloud compute instances create instance<span class=\"hljs-number\">-1<\/span> \\\n  --zone=us-central1-a \\\n  --machine-type=e2-micro \\\n  --image-family=debian<span class=\"hljs-number\">-12<\/span> --image-project=debian-cloud \\\n  --labels=app=web,env=dev \\\n  --tags=http-server \\\n  --metadata-from-file=startup-script=startup.sh\n\n<span class=\"hljs-comment\"># Firewall rule that applies only to VMs with the http-server tag<\/span>\ngcloud compute firewall-rules create allow-http \\\n  --network=<span class=\"hljs-keyword\">default<\/span> --allow=tcp:<span class=\"hljs-number\">80<\/span> \\\n  --target-tags=http-server --source-ranges=<span class=\"hljs-number\">0.0<\/span><span class=\"hljs-number\">.0<\/span><span class=\"hljs-number\">.0<\/span>\/<span class=\"hljs-number\">0<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Check labels, filter by label and test the web server:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">gcloud compute instances describe instance<span class=\"hljs-number\">-1<\/span> --zone=us-central1-a --format=<span class=\"hljs-string\">\"yaml(labels)\"<\/span>\ngcloud compute instances list --filter=<span class=\"hljs-string\">\"labels.env=dev\"<\/span>\ngcloud compute instances update instance<span class=\"hljs-number\">-1<\/span> --zone=us-central1-a --update-labels=app=db\ngcloud compute instances update instance<span class=\"hljs-number\">-1<\/span> --zone=us-central1-a --remove-labels=env\n\nIP=$(gcloud compute instances describe instance<span class=\"hljs-number\">-1<\/span> --zone=us-central1-a \\\n  --format=<span class=\"hljs-string\">\"value(networkInterfaces&#91;0].accessConfigs&#91;0].natIP)\"<\/span>)\ncurl http:<span class=\"hljs-comment\">\/\/$IP<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Give the startup script a minute or two to finish, then <code>curl<\/code> should return <code>Hello from instance-1<\/code>. This exercise shows the difference between the two kinds of metadata: <strong>labels<\/strong> (<code>app<\/code>, <code>env<\/code>) help you organise resources and report costs but change nothing about how the VM behaves, while the <strong>network tag<\/strong> <code>http-server<\/code> decides which firewall rule applies to it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> Commands that leave out <code>--zone<\/code> either use your <code>compute\/zone<\/code> default or ask you to pick a zone. Set a default with <code>gcloud config set compute\/zone us-central1-a<\/code> so you do not have to repeat the flag.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Corrections to the answers above<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Question<\/th><th>Original answer<\/th><th>Correct answer<\/th><\/tr><\/thead><tbody><tr><td>Project name has to be globally unique<\/td><td>True<\/td><td>False. The <strong>project ID<\/strong> must be globally unique and can never be reused, even after the project is deleted. The project name is only a label you choose.<\/td><\/tr><tr><td>Permissive parent policy overrules restrictive child policy<\/td><td>True<\/td><td>True for allow policies only: access is inherited and added together, so a child cannot take away a role granted higher up. However, IAM <strong>deny policies<\/strong> can block permissions that an allow policy grants.<\/td><\/tr><tr><td>A resource has to be associated with at least one project<\/td><td>True<\/td><td>A Compute Engine VM, bucket or similar resource belongs to <strong>exactly one<\/strong> project. Projects do not need an organization; one is only created when you use Google Workspace or Cloud Identity.<\/td><\/tr><tr><td>Network tags apply only to network resources<\/td><td>Network resources<\/td><td>Network tags are added to <strong>VM instances<\/strong> and instance templates. Firewall rules and routes then refer to those tags.<\/td><\/tr><tr><td>Metadata key to run code at startup<\/td><td><code>startap-script<\/code><\/td><td><code>startup-script<\/code> (or <code>startup-script-url<\/code> for a script stored in Cloud Storage). On Windows VMs, use keys such as <code>windows-startup-script-ps1<\/code>.<\/td><\/tr><tr><td>How do you list buckets?<\/td><td><code>gsutil ls<\/code>, <code>gcloud alpha storage ls<\/code><\/td><td><code>gcloud storage ls<\/code> is generally available and is the recommended command. <code>gsutil<\/code> is a legacy tool.<\/td><\/tr><tr><td>Enabling flow logs<\/td><td>Console steps only<\/td><td>Flow logs are enabled per subnet. With the CLI: <code>gcloud compute networks subnets update SUBNET --region=REGION --enable-flow-logs<\/code>.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Products renamed since this assignment was written<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Many of the Anthos and serverless questions use product names that Google has since changed. The ideas behind them still hold, but the documentation and the console use the current names.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Name used above<\/th><th>Current name or status<\/th><\/tr><\/thead><tbody><tr><td>Anthos<\/td><td>GKE Enterprise<\/td><\/tr><tr><td>Anthos on AWS<\/td><td>GKE on AWS (part of GKE Multi-Cloud)<\/td><\/tr><tr><td>Anthos Config Management<\/td><td>Config Sync and Policy Controller<\/td><\/tr><tr><td>Anthos Service Mesh, Traffic Director<\/td><td>Cloud Service Mesh<\/td><\/tr><tr><td>Ingress for Anthos<\/td><td>Multi Cluster Ingress<\/td><\/tr><tr><td>Cloud Run for Anthos<\/td><td>Knative serving<\/td><\/tr><tr><td>Cloud Functions<\/td><td>Cloud Run functions<\/td><\/tr><tr><td>Cloud Datastore<\/td><td>Firestore in Datastore mode<\/td><\/tr><tr><td>Stackdriver<\/td><td>Google Cloud Observability (Cloud Logging, Cloud Monitoring, Cloud Trace)<\/td><\/tr><tr><td>Deployment Manager<\/td><td>Deprecated. Google recommends Infrastructure Manager (Terraform-based) or Terraform.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Common errors and fixes<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>The project ID you specified is already in use<\/code><\/strong>: project IDs are global across all customers. Pick a different ID, for example by adding a random suffix.<\/li>\n\n\n<li><strong><code>Billing account for project is not found<\/code><\/strong> or <strong><code>billing must be enabled<\/code><\/strong>: link a billing account as shown in Lab 1.<\/li>\n\n\n<li><strong><code>Compute Engine API has not been used in project<\/code><\/strong>: run <code>gcloud services enable compute.googleapis.com<\/code> and wait a minute.<\/li>\n\n\n<li><strong><code>Required &#039;compute.instances.create&#039; permission<\/code><\/strong>: your account needs a role such as <code>roles\/compute.instanceAdmin.v1<\/code> on the project.<\/li>\n\n\n<li><strong><code>ZONE_RESOURCE_POOL_EXHAUSTED<\/code><\/strong>: the zone has no capacity for that machine type right now. Try another zone in the same region.<\/li>\n\n\n<li><strong><code>curl<\/code> times out<\/strong>: check that the VM has the <code>http-server<\/code> tag, that the firewall rule exists, and that the startup script has finished. Read the serial port output with <code>gcloud compute instances get-serial-port-output instance-1 --zone=us-central1-a<\/code>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Clean up<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Delete the lab resources so you are not billed after you finish. The quickest way is to delete the whole project. It stays in a pending-deletion state for about 30 days, during which you can restore it with <code>gcloud projects undelete<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">gcloud compute instances delete instance<span class=\"hljs-number\">-1<\/span> --zone=us-central1-a --quiet\ngcloud compute firewall-rules delete allow-http --quiet\n\n<span class=\"hljs-comment\"># Or remove everything at once<\/span>\ngcloud projects delete $PROJECT_ID<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">What is the difference between a GCP project name and a project ID?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The project ID is a permanent identifier that must be unique across all of Google Cloud and is used in commands and APIs. The project name is a display label that you can change and that other projects may share.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is the difference between labels and network tags in GCP?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Labels are key-value pairs for organising resources, filtering them and breaking down billing, and they do not change how a resource behaves. Network tags are strings attached to VMs that firewall rules and routes use to decide which instances they apply to.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I list all GCP regions and zones with gcloud?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run <code>gcloud compute regions list<\/code> for regions and <code>gcloud compute zones list<\/code> for zones. Add <code>--filter=&quot;region:us-central1&quot;<\/code> to the zones command to show only the zones in one region.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Is Anthos still available?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Its features now ship under the name GKE Enterprise, and individual components have new names, for example Cloud Service Mesh and Config Sync. The concepts in the Anthos questions above still apply.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Should I use gsutil or gcloud storage?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>gcloud storage<\/code> for new work. It is generally available and is the command Google recommends, while <code>gsutil<\/code> is a legacy tool.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related tutorials<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/google-cloud-professional-devops-engineer-skills-and-career-guide\/\">Google Cloud Professional DevOps Engineer: Skills and Career Guide<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/google-cloud-google-cloud-run-complete-tutorials\/\">Google Cloud: Google Cloud Run Complete Tutorials<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/what-is-google-cloud-storage-and-use-cases-of-google-cloud-storage\/\">What is Google Cloud Storage and use cases of Google Cloud Storage?<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/category\/cloud-computing\/google-cloud\/\">More Google Cloud tutorials<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This page is a Google Cloud Platform (GCP) assignment: hands-on exercises for creating a project, assigning IAM roles and launching a labelled Compute Engine VM, followed by&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[26149],"tags":[],"class_list":["post-32637","post","type-post","status-publish","format-standard","hentry","category-google-cloud"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/32637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=32637"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/32637\/revisions"}],"predecessor-version":[{"id":80415,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/32637\/revisions\/80415"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=32637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=32637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=32637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}