Bird
Raised Fist0
GCPcloud~20 mins

Instance templates 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
🎖️
Instance Template Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose of Instance Templates in GCP

What is the primary purpose of using an instance template in Google Cloud Platform?

ATo store data persistently across VM instance restarts.
BTo monitor the health of VM instances automatically.
CTo define a reusable configuration for VM instances that can be used to create managed instance groups.
DTo provide a graphical interface for managing VM instances.
Attempts:
2 left
💡 Hint

Think about how you can create multiple VMs with the same settings easily.

Configuration
intermediate
2:00remaining
Instance Template Configuration Output

Given the following instance template configuration snippet, what will be the machine type of the VM instances created from it?

GCP
resource "google_compute_instance_template" "example" {
  name         = "example-template"
  machine_type = "e2-medium"
  disk {
    source_image = "debian-cloud/debian-11"
    auto_delete  = true
    boot         = true
  }
  network_interface {
    network = "default"
  }
}
Ae2-medium
Bn1-standard-1
Ccustom-2-4096
Df1-micro
Attempts:
2 left
💡 Hint

Look at the machine_type field in the configuration.

Architecture
advanced
2:00remaining
Scaling with Instance Templates and Managed Instance Groups

You want to automatically scale your web application based on CPU usage. Which architecture best uses instance templates to achieve this?

ADeploy a serverless function instead of using instance templates for scaling.
BCreate a managed instance group using an instance template and configure autoscaling based on CPU utilization.
CUse instance templates only to create a single VM instance and scale by adding more templates.
DManually create individual VM instances from the instance template and monitor CPU usage yourself.
Attempts:
2 left
💡 Hint

Think about how to automate scaling with instance templates.

security
advanced
2:00remaining
Security Best Practice with Instance Templates

Which practice improves security when using instance templates for VM creation?

AInclude a startup script that installs the latest security patches automatically on boot.
BStore sensitive credentials directly in the instance template metadata.
CUse the default service account with full project permissions for all instances.
DDisable firewall rules to allow all incoming traffic for easier access.
Attempts:
2 left
💡 Hint

Consider how to keep instances secure and updated automatically.

service_behavior
expert
2:00remaining
Effect of Changing an Instance Template on Existing Managed Instances

You update an instance template used by a managed instance group. What happens to the existing VM instances in the group?

AThe managed instance group deletes all instances and creates new ones instantly.
BAll existing instances automatically update immediately to the new template configuration.
CThe instance template update fails if instances already exist in the group.
DExisting instances remain unchanged until you manually trigger a rolling update or recreate them.
Attempts:
2 left
💡 Hint

Think about how managed instance groups handle updates to templates.

Practice

(1/5)
1. What is the main purpose of an instance template in Google Cloud Platform?
easy
A. To store data permanently for virtual machines
B. To manage user access to virtual machines
C. To monitor the performance of virtual machines
D. To save VM configuration settings for creating identical instances quickly

Solution

  1. Step 1: Understand what instance templates store

    Instance templates save the configuration details like machine type, disk image, and network settings.
  2. Step 2: Identify their main use

    They allow quick creation of many identical VM instances without repeating setup.
  3. Final Answer:

    To save VM configuration settings for creating identical instances quickly -> Option D
  4. Quick Check:

    Instance templates = VM settings saved [OK]
Hint: Instance templates store VM setup for easy reuse [OK]
Common Mistakes:
  • Confusing instance templates with storage or monitoring
  • Thinking instance templates manage user permissions
  • Assuming instance templates hold data permanently
2. Which of the following is the correct gcloud command to create an instance template named web-template with machine type e2-medium?
easy
A. gcloud compute instance-templates new web-template --type=e2-medium
B. gcloud compute instance-templates create web-template --machine-type=e2-medium
C. gcloud compute instances create web-template --machine-type=e2-medium
D. gcloud create instance-template web-template --machine e2-medium

Solution

  1. Step 1: Identify the correct gcloud command for instance templates

    The command to create instance templates starts with gcloud compute instance-templates create.
  2. Step 2: Check the machine type flag

    The correct flag is --machine-type= followed by the machine type.
  3. Final Answer:

    gcloud compute instance-templates create web-template --machine-type=e2-medium -> Option B
  4. Quick Check:

    Correct command syntax = gcloud compute instance-templates create web-template --machine-type=e2-medium [OK]
Hint: Use 'instance-templates create' with '--machine-type' flag [OK]
Common Mistakes:
  • Using 'instances create' instead of 'instance-templates create'
  • Wrong flag names like '--machine' or '--type'
  • Incorrect command order or missing 'compute'
3. Given this snippet:
gcloud compute instance-templates create my-template \
  --machine-type=n1-standard-1 \
  --image-family=debian-11 \
  --image-project=debian-cloud

What will be the machine type of instances created from my-template?
medium
A. debian-11
B. e2-medium
C. n1-standard-1
D. debian-cloud

Solution

  1. Step 1: Identify the machine type flag in the command

    The flag --machine-type=n1-standard-1 sets the machine type.
  2. Step 2: Understand other flags

    --image-family and --image-project specify the OS image, not machine type.
  3. Final Answer:

    n1-standard-1 -> Option C
  4. Quick Check:

    Machine type flag sets instance type [OK]
Hint: Look for '--machine-type' flag for VM size [OK]
Common Mistakes:
  • Confusing image family with machine type
  • Choosing project name as machine type
  • Ignoring the '--machine-type' flag
4. You tried to create an instance template with this command:
gcloud compute instance-templates create test-template --machine-type e2-small

But it failed. What is the likely error?
medium
A. Missing image or boot disk specification
B. Instance template name 'test-template' is invalid
C. Machine type 'e2-small' does not exist
D. Command should be 'gcloud create instance-template'

Solution

  1. Step 1: Check required arguments for instance-templates create

    Instance templates require a machine type AND a boot disk specification (e.g., --image-family and --image-project).
  2. Step 2: Validate other parts

    The instance template name and machine type are valid, and the command starts correctly with gcloud compute instance-templates create. Flag syntax with space is accepted.
  3. Final Answer:

    Missing image or boot disk specification -> Option A
  4. Quick Check:

    Instance templates need image spec [OK]
Hint: Include --image-family & --image-project flags [OK]
Common Mistakes:
  • Forgetting to specify image or boot disk flags
  • Wrong command order or missing 'compute'
  • Assuming machine type is invalid without checking
5. You want to create a managed instance group that automatically updates all VMs when the instance template changes. Which approach should you use?
hard
A. Create a managed instance group with the instance template and enable rolling updates
B. Manually delete and recreate each VM after changing the template
C. Use an unmanaged instance group with the new template
D. Create a new instance template but keep the old managed group unchanged

Solution

  1. Step 1: Understand managed instance groups and updates

    Managed instance groups can use instance templates and support rolling updates to replace VMs smoothly.
  2. Step 2: Identify the best method for automatic updates

    Enabling rolling updates on the managed group with the new template applies changes automatically.
  3. Final Answer:

    Create a managed instance group with the instance template and enable rolling updates -> Option A
  4. Quick Check:

    Managed groups + rolling updates = automatic VM updates [OK]
Hint: Use managed groups with rolling updates for auto changes [OK]
Common Mistakes:
  • Thinking unmanaged groups support automatic updates
  • Manually recreating VMs instead of using rolling updates
  • Ignoring instance template updates in managed groups