Bird
Raised Fist0
GCPcloud~10 mins

Why IaC matters in GCP - Test Your Understanding

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define infrastructure as code using Terraform.

GCP
resource "google_compute_instance" "vm_instance" {
  name         = "example-instance"
  machine_type = "[1]"
  zone         = "us-central1-a"
}
Drag options to blanks, or click blank then click option'
An1-standard-1
Bstandard-1
Cmicro-1
Dsmall-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using an invalid machine type name causes deployment errors.
Leaving the machine_type blank will fail the resource creation.
2fill in blank
medium

Complete the code to specify the network interface for the VM instance.

GCP
resource "google_compute_instance" "vm_instance" {
  network_interface {
    network = "[1]"
  }
}
Drag options to blanks, or click blank then click option'
Adefault
Bprimary
Cmain-network
Ddefault-network
Attempts:
3 left
💡 Hint
Common Mistakes
Using a network name that does not exist causes deployment failure.
Adding spaces or hyphens incorrectly in the network name.
3fill in blank
hard

Fix the error in the Terraform code to correctly set the boot disk image.

GCP
boot_disk {
  initialize_params {
    image = "[1]"
  }
}
Drag options to blanks, or click blank then click option'
Aubuntu-20-04
Bubuntu-1804-lts
Cubuntu-latest
Dprojects/ubuntu-os-cloud/global/images/ubuntu-1804-bionic-v20210429
Attempts:
3 left
💡 Hint
Common Mistakes
Using short or incomplete image names causes Terraform to fail.
Misspelling the image path leads to errors.
4fill in blank
hard

Fill both blanks to create a firewall rule allowing HTTP traffic.

GCP
resource "google_compute_firewall" "http_firewall" {
  name    = "allow-http"
  network = "[1]"
  allow {
    protocol = "[2]"
    ports    = ["80"]
  }
}
Drag options to blanks, or click blank then click option'
Adefault
Bhttps
Ctcp
Dmain
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong network name causes the firewall to not apply.
Using 'https' instead of 'tcp' for the protocol is incorrect.
5fill in blank
hard

Fill all three blanks to output the VM instance's external IP address.

GCP
output "instance_ip" {
  value = google_compute_instance.[1].network_interface[[2]].access_config[[3]].nat_ip
}
Drag options to blanks, or click blank then click option'
Avm_instance
B0
Dinstance
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect resource names causes output errors.
Using wrong indexes leads to missing IP addresses.

Practice

(1/5)
1. Why is Infrastructure as Code (IaC) important when working with cloud environments like GCP?
easy
A. It requires manual configuration every time.
B. It makes cloud setup faster and repeatable.
C. It only works for small projects.
D. It replaces the need for cloud security.

Solution

  1. Step 1: Understand IaC benefits

    IaC automates cloud setup, making it faster and consistent each time.
  2. Step 2: Compare options

    Manual setup is slow and error-prone; IaC is designed for repeatability and speed.
  3. Final Answer:

    It makes cloud setup faster and repeatable. -> Option B
  4. Quick Check:

    IaC speeds up setup = A [OK]
Hint: IaC automates setup for speed and consistency [OK]
Common Mistakes:
  • Thinking IaC requires manual setup each time
  • Believing IaC only suits small projects
  • Confusing IaC with security tools
2. Which of the following is the correct way to define a simple Google Cloud Storage bucket using Terraform (an IaC tool)?
easy
A. resource "google_storage_bucket" "my_bucket" { name = "my-bucket" location = "US" }
B. resource google_storage_bucket my_bucket { name: "my-bucket" location: "US" }
C. resource "google_storage_bucket" my_bucket { name = "my-bucket" location = "US" }
D. resource "google_storage_bucket" "my_bucket" ( name = "my-bucket" location = "US" )

Solution

  1. Step 1: Check Terraform resource syntax

    Terraform uses resource "type" "name" { ... } with key = value pairs inside braces.
  2. Step 2: Identify correct syntax

    resource "google_storage_bucket" "my_bucket" { name = "my-bucket" location = "US" } matches this syntax exactly; others have wrong punctuation or missing quotes.
  3. Final Answer:

    resource "google_storage_bucket" "my_bucket" { name = "my-bucket" location = "US" } -> Option A
  4. Quick Check:

    Terraform resource syntax uses quotes and braces = B [OK]
Hint: Terraform resource blocks need quotes and braces [OK]
Common Mistakes:
  • Omitting quotes around resource type or name
  • Using colons instead of equals
  • Using parentheses instead of braces
3. Given this Terraform snippet for a Google Compute Engine instance:
resource "google_compute_instance" "vm_instance" {
  name         = "test-vm"
  machine_type = "e2-medium"
  zone         = "us-central1-a"
  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-11"
    }
  }
  network_interface {
    network = "default"
  }
}

What will happen when you run terraform apply with this configuration?
medium
A. The VM will be created but without a boot disk.
B. Terraform will throw a syntax error due to missing project ID.
C. Terraform will create a VM in the default zone instead of us-central1-a.
D. A new VM named 'test-vm' with e2-medium machine type will be created in us-central1-a.

Solution

  1. Step 1: Analyze the Terraform resource

    The resource defines a VM named 'test-vm' with machine type 'e2-medium' in zone 'us-central1-a' and a boot disk with Debian 11 image.
  2. Step 2: Understand Terraform behavior

    Terraform will create the VM as specified; project ID is optional if set in provider config, and boot disk is defined properly.
  3. Final Answer:

    A new VM named 'test-vm' with e2-medium machine type will be created in us-central1-a. -> Option D
  4. Quick Check:

    Defined VM config matches creation = C [OK]
Hint: Check resource fields and defaults carefully [OK]
Common Mistakes:
  • Assuming missing project ID causes error
  • Thinking boot disk is optional without explicit flag
  • Ignoring specified zone in config
4. You wrote this Terraform code to create a Google Cloud Storage bucket:
resource "google_storage_bucket" "bucket1" {
  name = "my-bucket"
  location = "us-central1"
  versioning {
    enabled = true
  }
  versioning = true
}

Why does Terraform fail to apply this configuration?
medium
A. The 'versioning' block and 'versioning' attribute conflict causing an error.
B. Bucket name 'my-bucket' is invalid in GCP.
C. Location 'us-central1' is not supported for buckets.
D. Terraform requires a 'storage_class' attribute which is missing.

Solution

  1. Step 1: Identify conflicting versioning definitions

    The code has both a 'versioning' block with 'enabled = true' and a 'versioning' attribute set to true, which conflicts.
  2. Step 2: Understand Terraform schema rules

    Terraform expects either a versioning block or attribute, not both; this causes a configuration error.
  3. Final Answer:

    The 'versioning' block and 'versioning' attribute conflict causing an error. -> Option A
  4. Quick Check:

    Conflicting versioning definitions cause error = D [OK]
Hint: Avoid duplicate keys or blocks in Terraform config [OK]
Common Mistakes:
  • Assuming bucket name is invalid without checking rules
  • Thinking location is unsupported without evidence
  • Believing missing storage_class always causes error
5. You want to ensure your GCP environment can be recreated exactly after a disaster. Which IaC practice best supports this goal?
hard
A. Use different tools each time to test flexibility.
B. Manually configure resources in the console and document steps in a text file.
C. Write and store Terraform code defining all resources, then use version control.
D. Create resources manually but take screenshots for reference.

Solution

  1. Step 1: Identify best disaster recovery IaC practice

    Using code (Terraform) to define resources ensures exact recreation and easy tracking.
  2. Step 2: Compare other options

    Manual steps or screenshots are error-prone and not repeatable; changing tools reduces consistency.
  3. Final Answer:

    Write and store Terraform code defining all resources, then use version control. -> Option C
  4. Quick Check:

    Code + version control = reliable recreation = A [OK]
Hint: Store IaC code in version control for exact rebuilds [OK]
Common Mistakes:
  • Relying on manual steps or screenshots
  • Changing tools frequently causing inconsistency
  • Ignoring version control benefits
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