[{"id":"terraformintermediate-001","courseId":"terraform-intermediate","domain":"configuration-language","topic":"Dynamic blocks","prompt":"This dynamic block sets no iterator argument. Inside its content block, which name refers to the current element of var.settings?","hint":"The iterator's default name comes from the block itself, not from a fixed word.","explain":"A dynamic block generates one nested block per element of a collection. Inside its content block, a temporary iterator object gives access to the current element's value and its key or index.","source":"https://developer.hashicorp.com/terraform/language/expressions/dynamic-blocks","interaction":{"type":"single"},"options":[{"id":"a","text":"setting","why":"Without an iterator argument, the temporary variable takes the dynamic block's label as its name."},{"id":"b","text":"each","whyNot":"Nothing in a dynamic block creates a variable called each; the name comes from the block's label."},{"id":"c","text":"item","whyNot":"Terraform has no default name of item; the label is used when no iterator argument is given."},{"id":"d","text":"value","whyNot":"value is an attribute of the iterator, reached as setting.value, not a standalone variable."}],"answer":"a","explanation":"A dynamic block's iterator is named by its iterator argument; when that is omitted, the name defaults to the block's label.","concept":"A dynamic block's iterator is named by its iterator argument; when that is omitted, the name defaults to the block's label.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"dynamic \"setting\" {\n  for_each = var.settings\n  content {\n    name  = setting.value.name\n    value = setting.value.value\n  }\n}","takeaways":["Set an iterator argument when a nested block shares its type name with its parent, so references stay clear."]},{"id":"terraformintermediate-002","courseId":"terraform-intermediate","domain":"configuration-language","topic":"For expressions","prompt":"Which TWO of these for expressions produce an object value? var.list holds strings, and var.map has string values.","hint":"Look at the brackets around each expression and what they require inside.","explain":"A for expression transforms each element of a collection into a new value. The brackets around it decide what kind of result it builds.","source":"https://developer.hashicorp.com/terraform/language/expressions/for","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"{ for s in var.list : s => upper(s) }","why":"Braces make an object, and the => pair supplies the key and the value for each element."},{"id":"b","text":"{ for k, v in var.map : k => length(v) }","why":"Braces with a => pair produce an object, here keyed by each map key."},{"id":"c","text":"[ for s in var.list : upper(s) ]","whyNot":"Square brackets produce a tuple, not an object."},{"id":"d","text":"[ for k, v in var.map : length(k) + length(v) ]","whyNot":"Square brackets produce a tuple of the computed values, even when the inner expression is a sum."},{"id":"e","text":"{ for s in var.list : upper(s) }","whyNot":"An object result needs two result expressions joined by =>; without them this is not a valid object for expression."},{"id":"f","text":"[ for s in var.list : s => upper(s) ]","whyNot":"A => pair belongs to the brace form; with square brackets this is not an object expression."}],"answer":"ab","explanation":"Square brackets in a for expression produce a tuple; curly braces produce an object and require two result expressions separated by =>.","concept":"Square brackets in a for expression produce a tuple; curly braces produce an object and require two result expressions separated by =>.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Use { ... => ... } in a for expression when you need a map-like object result."]},{"id":"terraformintermediate-003","courseId":"terraform-intermediate","domain":"configuration-language","topic":"Splat expressions","prompt":"In Terraform, if var.website_setting is null, the expression var.website_setting[*] evaluates to an empty tuple instead of null.","hint":"Think about what [*] does to a value that is not a list.","explain":"The [*] operator normally walks a list and reads an attribute from each element. It has special handling for values that are not lists, so check its rules before assuming an error.","source":"https://developer.hashicorp.com/terraform/language/expressions/splat","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"The docs say a null value under [*] returns an empty tuple, not null."},{"id":"b","text":"False","whyNot":"Splat does not pass null through; the docs say a null value gives an empty tuple."}],"answer":"a","explanation":"Splat on a null value returns an empty tuple; on any other non-collection value, it returns a one-element tuple.","concept":"Splat on a null value returns an empty tuple; on any other non-collection value, it returns a one-element tuple.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Use [*] on optional object inputs in for_each to switch a dynamic block on or off."]},{"id":"terraformintermediate-004","courseId":"terraform-intermediate","domain":"configuration-language","topic":"Variable validation rules","prompt":"A module's environment variable accepts only dev, staging or prod. A teammate asks what the validation block inside that variable is for. What is its purpose?","hint":"Think about checks on input, not about where the value comes from.","explain":"A variable block defines an input a module accepts, and it can carry extra rules about the value. Those rules check the value a caller supplies, so the module can refuse bad input early.","source":"https://developer.hashicorp.com/terraform/language/values/variables","interaction":{"type":"single"},"options":[{"id":"a","text":"It ensures the value a consumer passes meets the module's requirements.","why":"The validation block checks the consumer's input against a condition the module defines."},{"id":"b","text":"It supplies a fallback value when the consumer passes none.","whyNot":"That job belongs to the default argument, not to a validation block."},{"id":"c","text":"It hides the value from CLI output and from state.","whyNot":"That is the job of the sensitive argument; validation does not change how a value is shown or stored."},{"id":"d","text":"It makes the variable required on the command line.","whyNot":"Terraform prompts for a value only when the variable has no default; validation does not decide where values come from."}],"answer":"a","explanation":"A variable's optional validation block checks that a supplied value meets the module's requirements.","concept":"A variable's optional validation block checks that a supplied value meets the module's requirements.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Add validation to inputs that accept only a fixed set of values, such as environment names."]},{"id":"terraformintermediate-005","courseId":"terraform-intermediate","domain":"configuration-language","topic":"The try function","prompt":"Which TWO statements about the try function are correct? Each argument is an expression that might produce an error.","hint":"Think about how errors from the arguments are handled, and what comes back when nothing works.","explain":"try is a special function that catches errors raised while its arguments are evaluated. It is useful when data has a shape you cannot be sure of when you write the configuration.","source":"https://developer.hashicorp.com/terraform/language/functions/try","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"It returns the result of the first argument that does not produce an error.","why":"try evaluates its arguments in turn and returns the first result that is free of errors."},{"id":"b","text":"If every argument fails, it returns an error that describes the problems.","why":"try gives up only after all arguments fail, and then reports every problem it found."},{"id":"c","text":"If every argument fails, it returns null.","whyNot":"try does not fall back to null; with no successful argument it returns an error."},{"id":"d","text":"It is meant for use throughout a module on any expression.","whyNot":"The docs advise using try only in locals that normalize data, so error handling stays in one place."},{"id":"e","text":"If every argument fails, it returns an empty string.","whyNot":"Failure produces an error, not an empty string."},{"id":"f","text":"It can only catch errors from data decoded from JSON or YAML.","whyNot":"Decoded data is where it is particularly useful, but it is not the only case it handles."}],"answer":"ab","explanation":"try returns the first argument that evaluates without error, and returns an error describing all failures if none succeed.","concept":"try returns the first argument that evaluates without error, and returns an error describing all failures if none succeed.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Confine try to normalizing locals so the rest of the module can use plain references."]}]