Quiz — Variables, Locals, Repetition, Outputs & Guards¶
Quiz results are saved to your browser's local storage and will persist between sessions.
Variable precedence, locals & volatile functions, validation, why sensitive = true is not encryption, count vs for_each vs dynamic, outputs (-raw vs -json), and downstream guard propagation. Reference: §5 Variables & Locals, §6 Expressions & Guards, §7 Repetition, and §8 Data, Outputs & Modules.
13 questions. Back to all topics
You edit a variable's default value in variables.tf, but terraform.tfvars already sets that same variable. Which value does Terraform actually use, and what is the true precedence order from lowest to highest?
A repo has local.static_envs = ["dev", "qa"] and separately a var.static_env boolean that controls review-environment behavior. Does Terraform automatically ensure these two stay consistent (e.g. that running on the 'dev' workspace automatically sets static_env = true)?
One local value is wrapped in try(..., "") with a null-check before use (feeding a graceful mock-data fallback). A different local value in the same repo calls jsondecode directly with no guard, and fails loudly if the upstream data is missing. Is the unguarded one necessarily worse code?
A local value filters out entries whose upstream dependency doesn't exist yet, e.g. { for k, v in x : k => v if condition }. Two other resources elsewhere in the same repo still do for_each = toset(local.full_unfiltered_list) and then index into the now-filtered map directly. What happens?
A resource has count = local.some_condition ? 1 : 0. When the condition is false, what actually happens to that resource, and how do you safely reference an attribute on it in an output?
A module block uses for_each over a map filtered down to only enabled entries: for_each = { for k, v in x : k => v if v.enabled }. If both entries in the map are disabled, what does for_each-over-modules actually do?
You mark variable "api_token" with sensitive = true and write it into local_file.config. You also reference var.api_token inside a normal output "token_out" block without sensitive = true. What happens?
A config defines locals { suffix = formatdate("YYYYMMDD-hhmmss", timestamp()) } and uses local.suffix inside a resource's content/labels. What happens when you run terraform plan immediately after a successful terraform apply?
You create 3 GCP service accounts (["dev", "qa", "prod"]) using count = length(var.envs) and var.envs[count.index]. Later, you remove "dev" (index 0) so the list is ["qa", "prod"]. What does terraform plan propose, and how would for_each = toset(var.envs) differ?
Why does for_each = toset([google_compute_instance.vm_a.network_interface[0].network_ip]) fail during terraform plan when vm_a has not been created yet?
You refactor a google_storage_bucket that had 3 hardcoded lifecycle_rule {} blocks into a single dynamic "lifecycle_rule" { for_each = local.lifecycle_rules ... } block with the exact same values. How does terraform state list change, and what does terraform plan show?
When is a validation {} block inside a variable declaration evaluated, and what is its main restriction?
You define a structured output output "app_sa_emails" { value = { for k, m in module.app_sa : k => m.email } } and run terraform output -raw app_sa_emails in a bash script. What happens?
Quiz Progress
0 / 0 questions answered (0%)
0 correct