Bird
Raised Fist0
GCPcloud~20 mins

State management in GCP - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
State Management Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate
2:00remaining
How does Cloud Storage maintain state for object versions?

Google Cloud Storage can keep multiple versions of the same object. What happens when you enable versioning on a bucket and upload a new file with the same name?

AThe new upload creates a new version of the object, keeping the old version accessible.
BThe new upload overwrites the existing object and deletes the old version permanently.
CThe bucket rejects the upload because the object name already exists.
DThe new upload merges the content with the existing object automatically.
Attempts:
2 left
💡 Hint

Think about how versioning helps you recover old files.

❓ Architecture
intermediate
2:00remaining
Choosing state storage for a Cloud Run service

You have a Cloud Run service that processes user requests. It needs to keep user session data between requests. Which storage option is best to maintain state across multiple instances?

AUse Cloud SQL to store session data persistently.
BStore session data in Cloud Run instance memory (RAM).
CWrite session data to a local file on the Cloud Run container.
DUse environment variables to store session data.
Attempts:
2 left
💡 Hint

Remember that Cloud Run instances can scale and restart anytime.

❓ security
advanced
2:00remaining
Securing state data in Firestore

You store user preferences in Firestore. How can you ensure only the user can read and write their own preferences?

AEncrypt data on the client side and store encrypted blobs without rules.
BStore all preferences in a public collection with no security rules.
CUse IAM roles to grant all users read/write access to the Firestore database.
DUse Firestore security rules to allow read/write only if request.auth.uid matches the document ID.
Attempts:
2 left
💡 Hint

Think about how Firestore rules can restrict access based on user identity.

❓ Configuration
advanced
2:00remaining
Configuring Memorystore for Redis for session state

You want to use Memorystore for Redis to store session state for a GKE cluster. Which configuration is required to allow GKE nodes to connect securely to Memorystore?

ADeploy Memorystore in a different project without VPC peering.
BExpose Memorystore with a public IP and whitelist GKE node IPs.
CCreate Memorystore in the same VPC network as GKE and allow private IP access.
DUse Memorystore with no network configuration; it is accessible by default.
Attempts:
2 left
💡 Hint

Consider network security and private connectivity.

✅ Best Practice
expert
3:00remaining
Designing state management for a multi-region app

You design a multi-region web app on GCP that requires low-latency access to user state globally. Which approach best balances consistency and performance?

AUse a single regional Cloud Spanner instance and route all requests there.
BUse multi-region Cloud Spanner with strong consistency and automatic replication.
CStore state in local instance memory and sync periodically with a central database.
DUse Firestore in native mode with multi-region replication and eventual consistency.
Attempts:
2 left
💡 Hint

Think about global consistency and replication features.

Practice

(1/5)
1. What is the main purpose of state management in cloud infrastructure?
easy
A. To reduce the cost of cloud services
B. To increase the speed of cloud resource creation
C. To automatically fix errors in cloud resources
D. To keep track of the current setup of cloud resources

Solution

  1. Step 1: Understand what state management means

    State management records the current status and configuration of cloud resources.
  2. Step 2: Identify the main goal of state management

    Its main goal is to keep track of resources so changes can be managed safely and consistently.
  3. Final Answer:

    To keep track of the current setup of cloud resources -> Option D
  4. Quick Check:

    State management = tracking resource setup [OK]
Hint: State management means tracking resource setup [OK]
Common Mistakes:
  • Thinking it speeds up resource creation
  • Believing it fixes errors automatically
  • Assuming it reduces cloud costs directly
2. Which of the following is the correct way to configure a remote backend in Terraform using Google Cloud Storage?
easy
A. backend "gcs" { bucket = "my-bucket" path = "terraform/state" }
B. backend "gcp" { bucket = "my-bucket" path = "terraform/state" }
C. backend "gcs" { bucket = "my-bucket" prefix = "terraform/state" credentials = "path/to/key.json" }
D. backend "google" { bucket = "my-bucket" prefix = "terraform/state" }

Solution

  1. Step 1: Identify the correct backend type for Google Cloud Storage

    The correct backend type is "gcs" for Google Cloud Storage in Terraform.
  2. Step 2: Check required configuration keys

    Bucket name and prefix are required; credentials path is optional but recommended for authentication.
  3. Final Answer:

    backend "gcs" { bucket = "my-bucket" prefix = "terraform/state" credentials = "path/to/key.json" } -> Option C
  4. Quick Check:

    Use "gcs" backend with bucket, prefix, and credentials [OK]
Hint: Use backend "gcs" with bucket and prefix keys [OK]
Common Mistakes:
  • Using wrong backend type like "gcp" or "google"
  • Missing credentials for authentication
  • Using incorrect keys like 'path' instead of 'prefix'
3. Given this Terraform snippet using a remote backend:
terraform {
  backend "gcs" {
    bucket = "team-state"
    prefix = "prod"
  }
}

resource "google_storage_bucket" "example" {
  name     = "example-bucket"
  location = "US"
}

What happens when two team members run terraform apply at the same time?
medium
A. Terraform will lock the state file to prevent simultaneous changes
B. Terraform will merge both changes automatically without conflicts
C. Terraform will overwrite the state file causing loss of data
D. Terraform will create duplicate resources in Google Cloud Storage

Solution

  1. Step 1: Understand remote backend behavior with GCS

    Terraform uses state locking with remote backends like GCS to prevent concurrent changes.
  2. Step 2: Identify what happens on simultaneous apply

    When two users run apply simultaneously, Terraform locks the state file so only one can proceed at a time.
  3. Final Answer:

    Terraform will lock the state file to prevent simultaneous changes -> Option A
  4. Quick Check:

    Remote backend locks state to avoid conflicts [OK]
Hint: Remote backends lock state to avoid conflicts [OK]
Common Mistakes:
  • Thinking Terraform merges changes automatically
  • Assuming state file is overwritten without warning
  • Believing duplicate resources are created automatically
4. You configured Terraform with a remote backend on GCS, but when running terraform apply, you get an error saying the state file is locked indefinitely. What is the best way to fix this?
medium
A. Delete the state file from the GCS bucket manually
B. Run terraform force-unlock with the lock ID
C. Change the backend configuration to local state
D. Restart your computer and try again

Solution

  1. Step 1: Understand the cause of indefinite lock

    State file locks can remain if a previous operation was interrupted or crashed.
  2. Step 2: Use Terraform's force-unlock command

    The correct fix is to run terraform force-unlock with the lock ID to safely remove the lock.
  3. Final Answer:

    Run terraform force-unlock with the lock ID -> Option B
  4. Quick Check:

    Use force-unlock to clear stuck state locks [OK]
Hint: Use terraform force-unlock to clear stuck locks [OK]
Common Mistakes:
  • Deleting state file manually causing data loss
  • Switching to local state without fixing lock
  • Restarting computer does not clear remote locks
5. Your team wants to manage multiple environments (dev, staging, prod) using Terraform with GCS backend. Which approach best ensures isolated state files and safe collaboration?
hard
A. Use one GCS bucket with different prefixes for each environment
B. Use separate GCS buckets for each environment with the same prefix
C. Use local state files stored on each developer's machine
D. Use one GCS bucket and store all environments in the same prefix

Solution

  1. Step 1: Understand environment isolation needs

    Each environment should have its own state to avoid conflicts and accidental changes.
  2. Step 2: Choose backend configuration for isolation and collaboration

    Using one bucket with different prefixes (folders) isolates states while keeping management simple and collaborative.
  3. Final Answer:

    Use one GCS bucket with different prefixes for each environment -> Option A
  4. Quick Check:

    Different prefixes isolate environments in one bucket [OK]
Hint: Use prefixes in one bucket to separate environments [OK]
Common Mistakes:
  • Using same prefix causes state conflicts
  • Using local state prevents team collaboration
  • Using multiple buckets complicates management unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard