0
0
GCPcloud~20 mins

Variables and outputs in GCP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Variables and Outputs Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Terraform variable default values
You have a Terraform variable defined as:
variable "region" {
type = string
default = "us-central1"
}

What will be the value of var.region if you do not provide any value during terraform apply?
AIt will be "us-central1".
BTerraform will throw an error for missing variable value.
CIt will be null.
DIt will be an empty string.
Attempts:
2 left
💡 Hint
Check the default attribute in the variable block.
Configuration
intermediate
2:00remaining
Outputting a resource attribute in Terraform
Given this Terraform resource:
resource "google_compute_instance" "vm" {
name = "my-vm"
machine_type = "e2-medium"
zone = "us-central1-a"
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}
network_interface {
network = "default"
}
}

Which output block correctly exports the VM's self_link attribute?
Aoutput "vm_self_link" { value = google_compute_instance.vm.zone }
Boutput "vm_self_link" { value = google_compute_instance.vm.self_link }
Coutput "vm_self_link" { value = google_compute_instance.vm.network }
Doutput "vm_self_link" { value = google_compute_instance.vm.name }
Attempts:
2 left
💡 Hint
Look for the attribute that uniquely identifies the resource URL.
Architecture
advanced
2:30remaining
Passing variables between Terraform modules
You have a root Terraform module that calls a child module. The child module expects a variable named project_id. Which root module code snippet correctly passes the root variable var.project to the child module?
Amodule "child" { source = "./child" project_id = var.project_id }
Bmodule "child" { source = "./child" project = var.project_id }
Cmodule "child" { source = "./child" project_id = var.project }
Dmodule "child" { source = "./child" project = var.project }
Attempts:
2 left
💡 Hint
Match the variable names expected by the child module with the root variables.
security
advanced
2:00remaining
Avoiding sensitive data exposure in Terraform outputs
You have a Terraform variable marked as sensitive:
variable "db_password" {
type = string
sensitive = true
}

Which output block will cause Terraform to hide the password value when you run terraform apply?
Aoutput "db_password" { value = var.db_password }
Boutput "db_password" { value = var.db_password redact = true }
Coutput "db_password" { value = var.db_password hidden = true }
Doutput "db_password" { value = var.db_password sensitive = true }
Attempts:
2 left
💡 Hint
Check the Terraform output block attribute to mark outputs as sensitive.
service_behavior
expert
3:00remaining
Effect of missing output declaration in Terraform module
You have a Terraform child module that creates a Google Cloud Storage bucket. The child module does NOT declare any outputs.

When you call this module from the root module and run terraform apply, what will be the state of the bucket's URL in the root module?
AThe bucket URL will NOT be available in the root module because no output is declared.
BThe bucket URL will be available as module.child.bucket_url automatically.
CTerraform will throw an error during apply due to missing output.
DThe bucket URL will be stored in a default output named bucket_url.
Attempts:
2 left
💡 Hint
Outputs must be explicitly declared to be accessible outside a module.