Bird
Raised Fist0
GCPcloud~10 mins

Modules for reusability in GCP - Interactive Code Practice

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

Complete the code to declare a module source in Terraform.

GCP
module "network" {
  source = "[1]"
}
Drag options to blanks, or click blank then click option'
Anetwork-module
Bterraform-network
Cgcp-network
D./modules/network
Attempts:
3 left
💡 Hint
Common Mistakes
Using a module name instead of a path for source.
Omitting the source attribute.
2fill in blank
medium

Complete the code to pass a variable named 'region' to the module.

GCP
module "storage" {
  source = "./modules/storage"
  [1] = "us-central1"
}
Drag options to blanks, or click blank then click option'
Aregion
Blocation
Czone
Darea
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than defined in the module.
Forgetting to pass required variables.
3fill in blank
hard

Fix the error in the module call by completing the missing attribute.

GCP
module "compute" {
  source = "./modules/compute"
  machine_type = [1]
}
Drag options to blanks, or click blank then click option'
Amachine-type
Bn1-standard-1
C"n1-standard-1"
Dstandard-1
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around string values.
Using invalid variable names.
4fill in blank
hard

Fill both blanks to define a module output that returns the module's network name.

GCP
output "network_name" {
  value = module.[1].[2]
}
Drag options to blanks, or click blank then click option'
Anetwork
Bname
Cid
Dnet
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect module or output names.
Confusing output variable names with resource names.
5fill in blank
hard

Fill all three blanks to create a module call with source, region variable, and project variable.

GCP
module "storage_bucket" {
  source = "[1]"
  region = "[2]"
  project = "[3]"
}
Drag options to blanks, or click blank then click option'
A./modules/storage_bucket
Bus-east1
Cmy-gcp-project
Dstorage_bucket_module
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect source paths.
Passing variables without quotes.
Using wrong variable names.

Practice

(1/5)
1. What is the main benefit of using modules in GCP infrastructure setup?
easy
A. They let you reuse code to create cloud resources easily.
B. They automatically fix errors in your cloud setup.
C. They increase the cost of cloud resources.
D. They replace the need for any configuration files.

Solution

  1. Step 1: Understand what modules do

    Modules are reusable pieces of configuration that help you avoid repeating code.
  2. Step 2: Identify the benefit in context

    Using modules makes your cloud setup easier and faster by reusing code.
  3. Final Answer:

    They let you reuse code to create cloud resources easily. -> Option A
  4. Quick Check:

    Modules = Reuse code [OK]
Hint: Modules help reuse code to save time and effort [OK]
Common Mistakes:
  • Thinking modules fix errors automatically
  • Believing modules increase costs
  • Assuming modules remove all config files
2. Which of the following is the correct way to call a module in a Terraform configuration for GCP?
easy
A. module "storage" { source = "./modules/storage" }
B. call module storage from "./modules/storage"
C. use module storage located at ./modules/storage
D. import module storage from "./modules/storage"

Solution

  1. Step 1: Recall Terraform module syntax

    Terraform uses the keyword module followed by a name and a block with source to specify the module path.
  2. Step 2: Match the correct syntax

    module "storage" { source = "./modules/storage" } matches the correct syntax: module "name" { source = "path" }.
  3. Final Answer:

    module "storage" { source = "./modules/storage" } -> Option A
  4. Quick Check:

    Terraform module call = module "name" with source [OK]
Hint: Use 'module "name" { source = "path" }' to call modules [OK]
Common Mistakes:
  • Using keywords like call or import which are invalid
  • Missing quotes around module name
  • Not using a block structure for module
3. Given this Terraform module call:
module "network" {
  source = "./modules/network"
  region = "us-central1"
}

What will happen if the module network does not accept a region variable?
medium
A. Terraform will deploy but with a default region.
B. Terraform will ignore the extra variable and deploy successfully.
C. Terraform will throw an error about an unknown variable.
D. Terraform will deploy but skip the network module.

Solution

  1. Step 1: Understand variable passing in modules

    Terraform requires that variables passed to modules must be declared in the module's variables file.
  2. Step 2: Identify behavior when unknown variable is passed

    If a variable is passed but not declared, Terraform throws an error about unknown input variable.
  3. Final Answer:

    Terraform will throw an error about an unknown variable. -> Option C
  4. Quick Check:

    Unknown module variable = error [OK]
Hint: Modules must declare variables before use [OK]
Common Mistakes:
  • Assuming Terraform ignores unknown variables
  • Thinking Terraform uses defaults without declaration
  • Believing module is skipped silently
4. You have a module defined in ./modules/storage but when you run Terraform apply, it fails with:
Error: Module not found
What is the most likely cause?
medium
A. Terraform does not support modules in local folders.
B. The module code has syntax errors inside it.
C. You forgot to initialize the Terraform backend.
D. The source path in the module call is incorrect or misspelled.

Solution

  1. Step 1: Understand the error meaning

    The error 'Module not found' means Terraform cannot locate the module source path.
  2. Step 2: Check common causes

    The most common cause is a wrong or misspelled source path in the module call.
  3. Final Answer:

    The source path in the module call is incorrect or misspelled. -> Option D
  4. Quick Check:

    Module not found = wrong source path [OK]
Hint: Check module source path spelling if module not found error [OK]
Common Mistakes:
  • Assuming syntax errors cause 'Module not found'
  • Thinking Terraform disallows local modules
  • Confusing backend init with module loading
5. You want to create multiple GCP VM instances with similar settings using a module. Which approach best uses modules for reusability and scalability?
hard
A. Use a module only once and duplicate its code for other VMs.
B. Create a module for one VM and call it multiple times with different instance names.
C. Create separate modules for each VM with hardcoded settings.
D. Write all VM configurations directly in the main file without modules.

Solution

  1. Step 1: Understand module reusability

    Modules let you reuse the same configuration by calling them multiple times with different inputs.
  2. Step 2: Identify scalable approach

    Calling one VM module multiple times with different names is scalable and clean.
  3. Final Answer:

    Create a module for one VM and call it multiple times with different instance names. -> Option B
  4. Quick Check:

    Reuse module calls for multiple resources [OK]
Hint: Call one module multiple times with different inputs [OK]
Common Mistakes:
  • Duplicating module code instead of reusing
  • Hardcoding settings in separate modules
  • Avoiding modules and repeating code
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