0
0
GCPcloud~20 mins

Modules for reusability in GCP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GCP Modules Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Architecture
intermediate
2:00remaining
Understanding Module Outputs in GCP Terraform

You have a Terraform module that creates a Google Cloud Storage bucket and outputs its name. What will be the value of module.bucket.bucket_name after applying the configuration?

GCP
module "bucket" {
  source = "./modules/gcs_bucket"
  bucket_name = "my-app-bucket"
}

output "bucket_name" {
  value = module.bucket.bucket_name
}
A"bucket_name"
BThrows an error because output is not defined
C"my-app-bucket"
Dnull
Attempts:
2 left
💡 Hint

Think about what the module outputs and how outputs are accessed.

Configuration
intermediate
2:00remaining
Module Variable Scope in GCP Terraform

Given a Terraform module that defines a variable region with a default value, what will be the region used if the module is called without specifying region?

GCP
variable "region" {
  type    = string
  default = "us-central1"
}

resource "google_compute_instance" "vm" {
  name         = "vm-instance"
  machine_type = "e2-medium"
  zone         = "${var.region}-a"
}
A"us-east1"
Bnull
CThrows an error because region is not passed
D"us-central1"
Attempts:
2 left
💡 Hint

Consider the default value behavior of variables in Terraform modules.

security
advanced
2:30remaining
Securing Module Inputs in GCP Terraform

You want to ensure that a sensitive variable like a service account key is not exposed in Terraform logs or state files when passed to a module. Which approach correctly secures this sensitive input?

ADeclare the variable with <code>type = string</code> and <code>sensitive = true</code> in the module and pass the key as input.
BEncrypt the key manually and pass the encrypted string as input without marking it sensitive.
CStore the key in a public GitHub repo and reference it in the module input.
DPass the key as a plain string variable without any special flags.
Attempts:
2 left
💡 Hint

Think about Terraform's built-in support for sensitive variables.

service_behavior
advanced
2:30remaining
Module Reuse Impact on Resource Naming in GCP Terraform

You reuse a module twice in your Terraform configuration to create two Google Cloud Storage buckets. Both module calls use the same bucket_name input. What will happen when you apply this configuration?

ATerraform will throw an error due to duplicate resource names.
BBoth buckets will be created with the same name successfully.
CTerraform will create only one bucket and ignore the second.
DTerraform will append a suffix to the second bucket name automatically.
Attempts:
2 left
💡 Hint

Consider how resource names must be unique in GCP and Terraform behavior on duplicates.

Best Practice
expert
3:00remaining
Designing Reusable Modules for Multi-Environment Deployments in GCP

You are designing a Terraform module to deploy a GCP Compute Engine instance. You want to reuse this module for multiple environments (dev, staging, prod) with different configurations. Which design approach best supports this reuse while following best practices?

ACreate separate modules for each environment with hardcoded values inside each module.
BUse input variables for all environment-specific settings and avoid hardcoding any values inside the module.
CUse environment variables outside Terraform to switch configurations and keep the module static.
DHardcode production values in the module and override them only for dev and staging.
Attempts:
2 left
💡 Hint

Think about how to keep modules flexible and maintainable across environments.