Bird
Raised Fist0
GCPcloud~20 mins

Cloud Shell and gcloud CLI in GCP - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Cloud Shell and gcloud CLI Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
1:30remaining
Understanding Cloud Shell Session Persistence

You start a Cloud Shell session and create a file named notes.txt in your home directory. After 12 hours, you reconnect to Cloud Shell. What will happen to the notes.txt file?

AThe file will be there only if you saved it to the /tmp directory.
BThe file will be gone because Cloud Shell resets the home directory every time you reconnect.
CThe file will still be there because Cloud Shell home directory is persistent across sessions.
DThe file will be deleted automatically after 1 hour of inactivity.
Attempts:
2 left
💡 Hint

Think about where Cloud Shell stores your home directory and how it manages user files.

Configuration
intermediate
1:00remaining
Setting the Default Project with gcloud CLI

You want to set your default project for gcloud commands to my-project-123. Which command will correctly set this default project?

Agcloud project set-default my-project-123
Bgcloud config set project my-project-123
Cgcloud config project set my-project-123
Dgcloud set project my-project-123
Attempts:
2 left
💡 Hint

Remember the syntax for setting configuration properties in gcloud CLI.

Architecture
advanced
2:00remaining
Choosing the Right Environment for Long-Running Scripts

You need to run a script that will take 10 hours to complete. You want to use Cloud Shell or gcloud CLI. Which is the best approach to ensure the script runs without interruption?

AUse Cloud Shell to start a Compute Engine VM and run the script there to avoid session timeouts.
BRun the script directly in Cloud Shell; it will keep running even if you close the browser.
CRun the script in Cloud Shell and keep the browser tab open to prevent disconnection.
DRun the script using gcloud CLI on your local machine only.
Attempts:
2 left
💡 Hint

Consider Cloud Shell session limits and how to run long tasks reliably.

security
advanced
2:00remaining
Managing Credentials in Cloud Shell

You want to run gcloud commands in Cloud Shell that access multiple projects with different permissions. What is the best way to manage credentials securely?

AUse <code>gcloud auth login</code> multiple times to switch between accounts as needed.
BUse service account keys stored in Cloud Shell home directory for each project.
CShare your Cloud Shell session with others to use their credentials when needed.
DUse <code>gcloud config configurations</code> to create separate configurations for each project and account.
Attempts:
2 left
💡 Hint

Think about how gcloud CLI supports multiple configurations for different accounts and projects.

🧠 Conceptual
expert
1:30remaining
Understanding Cloud Shell Resource Limits

Which of the following statements about Cloud Shell resource limits is TRUE?

ACloud Shell sessions have a fixed 5 GB persistent home disk and 1.7 GB RAM with limited CPU.
BCloud Shell automatically scales resources based on your script's demands.
CCloud Shell provides unlimited CPU and memory resources for any workload.
DCloud Shell allows running background processes indefinitely without session timeout.
Attempts:
2 left
💡 Hint

Recall the typical resource specifications and session behavior of Cloud Shell.

Practice

(1/5)
1. What is the primary purpose of Google Cloud Shell?
easy
A. To create graphical user interfaces for cloud services
B. To provide a browser-based command-line interface pre-configured for Google Cloud
C. To store large amounts of data in the cloud
D. To host virtual machines for running applications

Solution

  1. Step 1: Understand Cloud Shell functionality

    Cloud Shell is a tool that gives you a command-line environment in your browser, ready to use with Google Cloud tools.
  2. Step 2: Compare options with Cloud Shell purpose

    Options A, B, and C describe other cloud services, not Cloud Shell's main use.
  3. Final Answer:

    To provide a browser-based command-line interface pre-configured for Google Cloud -> Option B
  4. Quick Check:

    Cloud Shell = browser CLI [OK]
Hint: Cloud Shell is a browser terminal for Google Cloud commands [OK]
Common Mistakes:
  • Confusing Cloud Shell with VM hosting
  • Thinking Cloud Shell stores data
  • Assuming Cloud Shell creates GUIs
2. Which of the following is the correct command to list all active Google Cloud projects using gcloud CLI?
easy
A. gcloud list projects
B. gcloud projects show
C. gcloud projects list
D. gcloud list all-projects

Solution

  1. Step 1: Recall gcloud CLI syntax for listing projects

    The correct command to list projects is 'gcloud projects list'.
  2. Step 2: Verify other options

    Options A, C, and D do not follow the correct gcloud command structure and will cause errors.
  3. Final Answer:

    gcloud projects list -> Option C
  4. Quick Check:

    List projects command = gcloud projects list [OK]
Hint: Remember: gcloud <resource> list to show resources [OK]
Common Mistakes:
  • Swapping 'list' and 'projects' order
  • Using 'show' instead of 'list'
  • Adding extra words like 'all-projects'
3. What will be the output of the following command run in Cloud Shell?
gcloud config get-value project
medium
A. An error saying 'command not found'
B. A list of all available projects
C. The current user's email address
D. The currently set Google Cloud project ID

Solution

  1. Step 1: Understand the command purpose

    'gcloud config get-value project' retrieves the project ID currently set in gcloud configuration.
  2. Step 2: Analyze other options

    A list of all available projects lists projects, which requires 'projects list'. An error saying 'command not found' is incorrect because the command exists. The current user's email address returns user info, not project.
  3. Final Answer:

    The currently set Google Cloud project ID -> Option D
  4. Quick Check:

    Get project config = current project ID [OK]
Hint: get-value returns current config setting [OK]
Common Mistakes:
  • Expecting a list of projects instead of one project
  • Confusing project ID with user email
  • Assuming command is invalid
4. You run the command gcloud compute instances create my-vm --zone=us-central1-a but get an error saying the zone is invalid. What is the most likely fix?
medium
A. Change the zone to a valid one like us-central1-b
B. Remove the --zone flag completely
C. Use --region instead of --zone
D. Rename the instance to a different name

Solution

  1. Step 1: Understand zone error cause

    The error indicates the specified zone 'us-central1-a' is invalid or unavailable in your project or region.
  2. Step 2: Fix by choosing a valid zone

    Changing to a valid zone like 'us-central1-b' resolves the error. Removing the flag or using region instead won't fix zone-specific errors. Renaming instance is unrelated.
  3. Final Answer:

    Change the zone to a valid one like us-central1-b -> Option A
  4. Quick Check:

    Zone error = pick valid zone [OK]
Hint: Check available zones with 'gcloud compute zones list' [OK]
Common Mistakes:
  • Removing zone flag instead of correcting it
  • Using region flag where zone is required
  • Changing instance name instead of zone
5. You want to automate setting the default project in Cloud Shell for multiple users. Which gcloud CLI command sequence correctly sets the project and verifies it?
hard
A. gcloud config set project my-project-id && gcloud config get-value project
B. gcloud projects set my-project-id && gcloud projects get my-project-id
C. gcloud set project my-project-id && gcloud get project
D. gcloud config project set my-project-id && gcloud config project get

Solution

  1. Step 1: Identify correct command to set project

    The correct command to set the default project is 'gcloud config set project '.
  2. Step 2: Verify project setting

    To verify, use 'gcloud config get-value project' which returns the current project ID.
  3. Step 3: Check other options for correctness

    Options B, C, and D use invalid command syntax and will cause errors.
  4. Final Answer:

    gcloud config set project my-project-id && gcloud config get-value project -> Option A
  5. Quick Check:

    Set and get project config = gcloud config set project my-project-id && gcloud config get-value project [OK]
Hint: Use 'gcloud config set' and 'gcloud config get-value' for config changes [OK]
Common Mistakes:
  • Using incorrect command order or syntax
  • Confusing 'projects' commands with 'config' commands
  • Trying to set project with invalid commands