[{"id":"terraformadvanced-001","courseId":"terraform-advanced","domain":"configuration-language","topic":"Ephemeral values","prompt":"A team runs Terraform 1.9 and wants a variable's value to stay out of state and plan files. What must they do before they can add the ephemeral argument to that variable?","hint":"Compare the team's version with the first release that supports ephemeral variables.","explain":"Ephemeral values exist at runtime, but Terraform leaves them out of state and plan files entirely. Each ephemeral form needs a minimum Terraform release, and those minimums differ by form.","source":"https://developer.hashicorp.com/terraform/language/manage-sensitive-data","interaction":{"type":"single"},"options":[{"id":"a","text":"Upgrade to Terraform 1.10 or later","why":"The ephemeral argument on variables and child module outputs requires Terraform 1.10 or later."},{"id":"b","text":"Nothing; Terraform 0.15 or later supports it","whyNot":"0.15 is the minimum for the sensitive argument, not for the ephemeral argument."},{"id":"c","text":"Upgrade to Terraform 1.11 or later","whyNot":"1.11 is required for write-only arguments on managed resources; variables need 1.10."},{"id":"d","text":"Add sensitive = true; that also keeps the value out of state","whyNot":"sensitive only redacts values from CLI and UI output; it does not keep them out of state."}],"answer":"a","explanation":"The ephemeral argument on variables and child module outputs requires Terraform 1.10 or later; the sensitive argument only needs 0.15.","concept":"The ephemeral argument on variables and child module outputs requires Terraform 1.10 or later; the sensitive argument only needs 0.15.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Ephemeral and sensitive are separate: one keeps values out of state, the other only hides them from output."]},{"id":"terraformadvanced-002","courseId":"terraform-advanced","domain":"configuration-language","topic":"Optional object attributes","prompt":"A module declares port = optional(number, 8080) inside an object variable. A caller passes port = null explicitly. What value does the module see for port?","hint":"Consider what Terraform does with an optional attribute that is missing, and one that is set to null.","explain":"When a caller leaves out an optional object attribute, Terraform inserts a default instead of raising an error. Defaults are declared in the type constraint, so the module can rely on them.","source":"https://developer.hashicorp.com/terraform/language/expressions/type-constraints","interaction":{"type":"single"},"options":[{"id":"a","text":"The value 8080","why":"A non-null default replaces null too, so the module never sees null for this attribute."},{"id":"b","text":"null","whyNot":"Null is the fallback only when no non-null default is declared, and here one is declared."},{"id":"c","text":"An error, because the caller set port explicitly","whyNot":"Errors come from missing required attributes; an optional attribute gets its default instead."},{"id":"d","text":"0, the zero value for a number","whyNot":"Terraform never invents zero for numbers; the only fallback is the default you declare."}],"answer":"a","explanation":"An optional attribute with a non-null default is never null in the receiving module, whether the caller omitted it or set it to null.","concept":"An optional attribute with a non-null default is never null in the receiving module, whether the caller omitted it or set it to null.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"variable \"server\" {\n  type = object({\n    name = string\n    port = optional(number, 8080)\n  })\n}","takeaways":["Give an optional attribute a non-null default when the module must never handle null."]},{"id":"terraformadvanced-003","courseId":"terraform-advanced","domain":"configuration-language","topic":"path.module and path.root","prompt":"A shared module at modules/network reads helper files using path values. Which TWO statements about path.module, path.root and path.cwd are true?","hint":"Each path value names a different place: the expression's module, the root module, or the start directory.","explain":"Filesystem path values tell a configuration where its code lives or where the run started. A module can be reused from many places, so the value you pick affects portability.","source":"https://developer.hashicorp.com/terraform/language/expressions/references","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"path.root is the directory of the child module that calls the current module","whyNot":"path.root is the root module of the whole configuration, not the caller of a child module."},{"id":"b","text":"path.module is the directory of the module that contains the expression","why":"path.module is the path of the module where the expression is written, so it works inside shared modules."},{"id":"c","text":"path.cwd is the recommended value for finding files in a shared module","whyNot":"The docs steer away from path.cwd in favor of path.root or path.module."},{"id":"d","text":"path.cwd is the directory you ran Terraform from, before any -chdir is applied","why":"Terraform records the original working directory before -chdir, so path.cwd keeps that location."},{"id":"e","text":"Writing generated files into path.module is safe, since each call gets its own copy","whyNot":"Multiple calls of a local module share one source directory, so writes can race and overwrite each other."},{"id":"f","text":"path.cwd always points to the root module's directory","whyNot":"path.cwd is the original working directory, which is not necessarily the root module's directory."}],"answer":"bd","explanation":"path.module is the module holding the expression, path.root is the root module, and path.cwd is the original working directory before -chdir.","concept":"path.module is the module holding the expression, path.root is the root module, and path.cwd is the original working directory before -chdir.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["In shared modules, prefer path.module for files the module ships; avoid path.cwd."]},{"id":"terraformadvanced-004","courseId":"terraform-advanced","domain":"configuration-language","topic":"The can function","prompt":"A teammate writes can(local.nonexist) in a validation block, but no local named nonexist is declared anywhere. What does Terraform do?","hint":"Consider whether the expression is invalid for every input, or only fails for some runtime values.","explain":"can turns an error into a true or false result, but only for errors that appear once real values are known. Some mistakes are visible before any value is evaluated.","source":"https://developer.hashicorp.com/terraform/language/functions/can","interaction":{"type":"single"},"options":[{"id":"a","text":"It returns false, because the reference finds no value","whyNot":"can returns false only for runtime errors; an undeclared name fails before any value exists."},{"id":"b","text":"It returns true, because can skips undeclared references","whyNot":"can does not skip mistakes; it only converts errors from runtime data into a boolean."},{"id":"c","text":"Terraform reports an error; can cannot catch an undeclared name","why":"A reference to an undeclared top-level object is invalid for any input, so can does not catch it."},{"id":"d","text":"It returns null, which a condition treats as false","whyNot":"can always returns a boolean, never null."}],"answer":"c","explanation":"can catches only errors that appear at runtime; provably invalid expressions, like references to undeclared names, still raise errors.","concept":"can catches only errors that appear at runtime; provably invalid expressions, like references to undeclared names, still raise errors.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["can suits simple validation tests; prefer try for fallback values elsewhere."]},{"id":"terraformadvanced-005","courseId":"terraform-advanced","domain":"configuration-language","topic":"The templatefile function","prompt":"A configuration writes config.tftpl with local_file during apply, then calls templatefile on that path in the same run. Why does this not work?","hint":"Think about when functions are evaluated and whether they take part in dependency ordering.","explain":"Terraform orders work with a dependency graph built from references between blocks. Some functions read files directly, so check whether a file's contents exist before the run starts.","source":"https://developer.hashicorp.com/terraform/language/functions/templatefile","interaction":{"type":"single"},"options":[{"id":"a","text":"The file must exist at the start of the run, because functions are not part of the dependency graph","why":"templatefile reads files that already exist on disk at the beginning of a run; functions do not participate in the dependency graph."},{"id":"b","text":"templatefile accepts only files named *.tftpl","whyNot":"*.tftpl is recommended, not enforced; Terraform allows other file names."},{"id":"c","text":"templatefile requires its vars argument to be a list, not an object","whyNot":"The vars argument must be an object, so a list is the wrong shape for this call."},{"id":"d","text":"Templates cannot use for directives, so the file is rejected","whyNot":"Templates support directives such as %{ for } and %{ if }."}],"answer":"a","explanation":"templatefile reads files that already exist at the start of a run, because functions sit outside the dependency graph.","concept":"templatefile reads files that already exist at the start of a run, because functions sit outside the dependency graph.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Files written during an apply cannot be passed to templatefile in that same run."]}]