0
0
GCPcloud~30 mins

Instance states (running, stopped, terminated) in GCP - Mini Project: Build & Apply

Choose your learning style9 modes available
Instance states (running, stopped, terminated)
📖 Scenario: You are managing virtual machines (instances) in Google Cloud Platform (GCP). Each instance can be in one of three states: running, stopped, or terminated. You want to organize and track these instances by their states.
🎯 Goal: Create a data structure to hold instance names and their states, add a filter to select only running instances, then list those running instances, and finally configure a simple output format to display them.
📋 What You'll Learn
Create a dictionary called instances with exact instance names and states
Add a variable called desired_state set to the string 'running'
Use a list comprehension called running_instances to select instance names with state matching desired_state
Create a final dictionary called output with key 'running_instances' and value running_instances
💡 Why This Matters
🌍 Real World
Cloud administrators often need to track and manage virtual machine states to optimize costs and performance.
💼 Career
Understanding instance states and filtering them programmatically is essential for cloud operations and automation roles.
Progress0 / 4 steps
1
Create the initial instance states dictionary
Create a dictionary called instances with these exact entries: 'vm-1': 'running', 'vm-2': 'stopped', 'vm-3': 'terminated', 'vm-4': 'running'
GCP
Need a hint?

Use curly braces to create a dictionary with keys as instance names and values as their states.

2
Add the desired state variable
Add a variable called desired_state and set it to the string 'running'
GCP
Need a hint?

Assign the string 'running' to the variable desired_state.

3
Select running instances using list comprehension
Create a list comprehension called running_instances that includes instance names from instances where the state equals desired_state
GCP
Need a hint?

Use a list comprehension to filter keys where the value matches desired_state.

4
Create the final output dictionary
Create a dictionary called output with a key 'running_instances' and value running_instances
GCP
Need a hint?

Create a dictionary with the key exactly as 'running_instances' and assign the list running_instances as its value.