Home › Certifications › Terraform Associate 004 › Reading, Generating and Modifying Configuration
55 multiple-choice questions and 39 flashcards on Reading, Generating and Modifying Configuration, about 22% of the Terraform Associate 004 bank. Every one carries a written rationale.
Reading, Generating and Modifying Configuration is one of 8 chapters in CoStudy's Terraform Associate (004) bank, and it holds 55 of the bank's 250 multiple-choice questions — roughly 22% of the total. That proportion is not arbitrary: chapters follow the certifying body's published exam outline, and the number of questions in each is set by that domain's published weight, so the share of your practice time this chapter takes matches the share of the real exam it accounts for.
Studying by chapter is worth doing once you have a diagnostic score. A single overall percentage tells you whether you are close; it does not tell you which domain is dragging. Working a weak chapter in isolation, and re-testing it in isolation, is the fastest way to move a score that has stalled — and it is why the mock exams in CoStudy report by domain rather than as one number.
10 questions drawn from this chapter, with the full rationale shown — the controlling principle behind the right answer, and why each wrong option tempts and fails.
Which statement about output values is correct?
Answer: C — An output exposes a module value to its caller, or prints it at the CLI in the root module
C is right: outputs are a module's return values. A caller reads them as module.<name>.<output>, and in the root module they are printed after apply and readable with terraform output. A reverses the direction — values flow into a module through variables and out through outputs. B is false; exposing resource attributes is their main use. D invents a requirement: outputs are optional, and you declare only what callers need.
When should you use 'for_each' instead of 'count'?
Answer: E — When iterating a map or set, so instances keep stable keys as members are removed
E is right: for_each keys each instance by a string, so removing one member leaves the others untouched, whereas count reindexes and forces needless replacements. A reverses current guidance. B describes the classic count = var.enabled ? 1 : 0 idiom. C is false - string keys are exactly the point. D is unrelated to either meta-argument.
Which lifecycle argument errors any plan that would destroy a resource?
Answer: A — prevent_destroy, which makes any plan proposing destruction fail with an error
A is right: with prevent_destroy set to true, a plan that would remove the resource fails outright rather than proceeding. B and C are invented names, and B additionally describes silent suppression, which would be far more dangerous than an error. D confuses a lifecycle guard with state locking. Note that deleting the resource block still produces an error rather than a quiet destroy, so you must remove the guard deliberately.
Which statement about count vs for_each is correct?
Answer: C — count requires an integer; for_each requires a map or set of strings.
Trick: A is the direction-reversal. count = N (number). for_each = map or set of strings. Their resource addresses differ: aws_instance.x[0] vs aws_instance.x["key"].
Terraform configuration files use which file extension?
Answer: C — .tf for native HCL, or .tf.json for the JSON variant; both load from the same directory
C is right: Terraform loads every .tf and .tf.json file in the working directory as one configuration; conventional names such as main.tf, variables.tf and outputs.tf are habit, not a requirement. A is a different ecosystem. B is false - HCL remains the native form. D and E describe CDKTF-style tooling, not core Terraform.
Which command-line flag passes a variables file at runtime?
Answer: A — -var-file=PATH
Trick: the flag is -var-file (singular hyphenated form). -var=name=value sets a single variable.
Which is correct HCL for joining a list of strings with commas?
Answer: A — join(",", var.names)
Trick: each of B, C, D is a different function. concat joins lists, merge joins maps, split is the inverse of join. join(SEP, LIST) → string.
Which pairing of custom condition and evaluation moment is INCORRECT?
Answer: B — variable validation — after all resources have been planned
A) Check assertions are evaluated during plan and apply and only produce warnings. B) Correct — this is the false pairing: variable validation runs when variable values are evaluated, well before resource planning. C) Preconditions do run before Terraform acts on the containing object. D) Postconditions do run after creation or refresh of the object.
A team wants Terraform to verify that a newly created object came out with the properties they expect, failing the run if not. The MOST appropriate placement is:
Answer: A — A postcondition in the lifecycle block
A) Correct — postconditions are evaluated after the object is created or refreshed and fail the run when the resulting attributes violate the assumption. B) Preconditions run before creation, when the resulting attributes are still unknown. C) Check blocks would only warn, not fail. D) Variable validation constrains only the input, not the object the provider actually produced.
A stateful database resource must never be destroyed by an accidental apply. Which approach gives the strongest configuration-level guardrail?
Answer: D — Set prevent_destroy = true in the resource lifecycle block
A) A separate workspace isolates state but a destroy in that workspace still succeeds. B) ignore_changes suppresses attribute drift but does nothing about a destroy. C) Sensitivity affects output display only and has no bearing on destruction. D) Correct — prevent_destroy makes Terraform error out at plan time if the plan would destroy that object, forcing a deliberate config change first.
4 cards from the 39 in this chapter.
Variable precedence (highest to lowest)?
-var/--var-file (CLI), terraform.tfvars + auto.tfvars, TF_VAR_* env, default in variable block.
Implicit dependencies?
Terraform infers from references. resource_a uses resource_b's attribute.
create_before_destroy?
Create new before destroying old. Useful for zero-downtime updates.
Variables?
variable "<name>" { type = ... default = ... }. Inputs to configuration.
These are a sample. The full Reading, Generating and Modifying Configuration chapter runs 94 items with per-chapter progress tracking, on the web and in the iOS app.
Open Terraform Associate 004 in CoStudy →