Bird
Raised Fist0
GCPcloud~5 mins

Instance states (running, stopped, terminated) in GCP - Commands & Configuration

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
Introduction
When you create a virtual machine in the cloud, it can be in different states like running, stopped, or terminated. These states tell you if the machine is working, paused, or deleted. Understanding these states helps you manage your cloud resources efficiently.
When you want to start a virtual machine to run your applications.
When you need to pause a virtual machine to save costs but keep its data.
When you want to permanently delete a virtual machine you no longer need.
When you want to check the current status of your virtual machines.
When you want to troubleshoot why a virtual machine is not responding.
Commands
This command creates a new virtual machine named 'example-instance' in the 'us-central1-a' zone. The instance will start in the running state automatically.
Terminal
gcloud compute instances create example-instance --zone=us-central1-a
Expected OutputExpected
Created [https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/instances/example-instance].
--zone - Specifies the zone where the instance will be created.
This command lists the instance named 'example-instance' and shows its current state, so you can verify it is running.
Terminal
gcloud compute instances list --filter="name=example-instance" --zones=us-central1-a
Expected OutputExpected
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS example-instance us-central1-a e2-medium 10.128.0.2 34.68.194.64 RUNNING
--filter - Filters the list to show only the instance with the specified name.
--zones - Limits the list to the specified zone.
This command stops the running instance named 'example-instance'. The instance state changes to stopped, which means it is not running but still exists with its data.
Terminal
gcloud compute instances stop example-instance --zone=us-central1-a
Expected OutputExpected
Stopped [https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/instances/example-instance].
--zone - Specifies the zone of the instance to stop.
Check the instance state again to confirm it is now stopped.
Terminal
gcloud compute instances list --filter="name=example-instance" --zones=us-central1-a
Expected OutputExpected
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS example-instance us-central1-a e2-medium 10.128.0.2 34.68.194.64 TERMINATED
--filter - Filters the list to show only the instance with the specified name.
--zones - Limits the list to the specified zone.
This command deletes the instance named 'example-instance' permanently. The instance is removed and cannot be started again.
Terminal
gcloud compute instances delete example-instance --zone=us-central1-a --quiet
Expected OutputExpected
Deleted [https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/instances/example-instance].
--zone - Specifies the zone of the instance to delete.
--quiet - Skips confirmation prompt to delete the instance immediately.
Key Concept

If you remember nothing else from this pattern, remember: running means the instance is active, stopped means it is paused but still exists, and terminated means it is deleted permanently.

Common Mistakes
Trying to start an instance that has been deleted (terminated).
A terminated instance no longer exists and cannot be started again.
Create a new instance instead of trying to start a deleted one.
Confusing 'stopped' with 'terminated' and deleting data unintentionally.
Stopping an instance keeps its data, but terminating deletes it permanently.
Use 'stop' to pause and keep data; use 'delete' only when you want to remove the instance completely.
Not specifying the correct zone when managing instances.
Commands fail or affect the wrong instance if the zone is incorrect or missing.
Always specify the correct zone with the --zone flag for instance commands.
Summary
Create an instance to start it in the running state.
Use the list command to check the instance's current state.
Stop the instance to pause it without deleting data.
Delete the instance to remove it permanently.

Practice

(1/5)
1. What does the RUNNING state of a Google Cloud VM instance indicate?
easy
A. The VM is paused and cannot be restarted
B. The VM is permanently deleted
C. The VM is active and ready to use
D. The VM is being created

Solution

  1. Step 1: Understand VM states

    The RUNNING state means the virtual machine is powered on and operational.
  2. Step 2: Compare with other states

    TERMINATED means stopped but restartable; DELETED means removed permanently.
  3. Final Answer:

    The VM is active and ready to use -> Option C
  4. Quick Check:

    RUNNING = active and ready [OK]
Hint: RUNNING means VM is active and ready [OK]
Common Mistakes:
  • Confusing TERMINATED with RUNNING
  • Thinking DELETED means stopped
  • Assuming RUNNING means VM is paused
2. Which command correctly stops a running Google Cloud VM instance named my-vm using gcloud CLI?
easy
A. gcloud compute instances stop my-vm
B. gcloud compute instances delete my-vm
C. gcloud compute instances terminate my-vm
D. gcloud compute instances suspend my-vm

Solution

  1. Step 1: Identify the correct stop command

    The command to stop a VM is gcloud compute instances stop.
  2. Step 2: Check other commands

    delete removes the VM, terminate is not a valid gcloud command, suspend preserves memory state but is different from stop.
  3. Final Answer:

    gcloud compute instances stop my-vm -> Option A
  4. Quick Check:

    Stop VM = gcloud compute instances stop [OK]
Hint: Use 'stop' to halt VM without deleting [OK]
Common Mistakes:
  • Using delete instead of stop
  • Typing terminate which is invalid
  • Confusing suspend with stop
3. Given this gcloud command output:
NAME    ZONE       STATUS
vm-1    us-central1-a  TERMINATED
vm-2    us-central1-a  RUNNING
vm-3    us-central1-a  TERMINATED

Which VM(s) can be restarted without creating a new instance?
medium
A. Only vm-2
B. vm-1 and vm-3
C. All vm-1, vm-2, and vm-3
D. None of them

Solution

  1. Step 1: Understand TERMINATED state

    TERMINATED means the VM is stopped but can be restarted later.
  2. Step 2: Identify which VMs are TERMINATED

    vm-1 and vm-3 are TERMINATED, so they can be restarted; vm-2 is already RUNNING.
  3. Final Answer:

    vm-1 and vm-3 -> Option B
  4. Quick Check:

    TERMINATED = restartable VMs [OK]
Hint: TERMINATED means stopped but restartable [OK]
Common Mistakes:
  • Thinking RUNNING VMs need restart
  • Assuming TERMINATED means deleted
  • Selecting all VMs regardless of state
4. You tried to restart a VM but got an error saying the instance does not exist. What is the most likely cause?
medium
A. The VM was DELETED and no longer exists
B. The VM is in SUSPENDED state
C. The VM is in TERMINATED state
D. The VM is in RUNNING state

Solution

  1. Step 1: Analyze error message

    Error 'instance does not exist' means the VM resource is gone.
  2. Step 2: Match with VM states

    Only DELETED means the VM is removed permanently; RUNNING, TERMINATED, SUSPENDED still exist.
  3. Final Answer:

    The VM was DELETED and no longer exists -> Option A
  4. Quick Check:

    Deleted VM = does not exist error [OK]
Hint: Deleted VM no longer exists, causing errors [OK]
Common Mistakes:
  • Confusing TERMINATED with DELETED
  • Assuming STOPPED means deleted
  • Ignoring error message meaning
5. You want to save costs by stopping a VM but keep its data and configuration intact for later use. Which state should you put the VM in, and why?
hard
A. RUNNING, because it keeps the VM active and ready
B. SUSPENDED, because it pauses the VM without data loss
C. DELETED, because it frees all resources immediately
D. TERMINATED, because it stops the VM but preserves data and allows restart

Solution

  1. Step 1: Understand cost-saving states

    Stopping a VM saves costs but keeps data if the VM is TERMINATED.
  2. Step 2: Evaluate options

    RUNNING uses full resources; DELETED removes VM and data; SUSPENDED preserves memory but standard stop uses TERMINATED.
  3. Final Answer:

    TERMINATED, because it stops the VM but preserves data and allows restart -> Option D
  4. Quick Check:

    Stop VM = TERMINATED state for cost saving [OK]
Hint: TERMINATED stops VM but keeps data for restart [OK]
Common Mistakes:
  • Choosing RUNNING to save costs
  • Deleting VM to save costs but losing data
  • Choosing SUSPENDED instead of TERMINATED